mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.1 KiB
88 lines
2.1 KiB
// Copyright 2013 gopm authors. |
|
// |
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may |
|
// not use this file except in compliance with the License. You may obtain |
|
// a copy of the License at |
|
// |
|
// http://www.apache.org/licenses/LICENSE-2.0 |
|
// |
|
// Unless required by applicable law or agreed to in writing, software |
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
// License for the specific language governing permissions and limitations |
|
// under the License. |
|
|
|
package cmd |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"strings" |
|
) |
|
|
|
const APP_VER = "0.5.1.1107" |
|
|
|
var ( |
|
AppPath string |
|
reposDir string = "~/.gopm/repos" |
|
) |
|
|
|
// A Command is an implementation of a go command |
|
// like go build or go fix. |
|
type Command struct { |
|
// Run runs the command. |
|
// The args are the arguments after the command name. |
|
Run func(cmd *Command, args []string) |
|
|
|
// UsageLine is the one-line usage message. |
|
// The first word in the line is taken to be the command name. |
|
UsageLine string |
|
|
|
// Short is the short description shown in the 'go help' output. |
|
Short string |
|
|
|
// Long is the long message shown in the 'go help <this-command>' output. |
|
Long string |
|
|
|
// Flag is a set of flags specific to this command. |
|
Flags map[string]bool |
|
} |
|
|
|
// Name returns the command's name: the first word in the usage line. |
|
func (c *Command) Name() string { |
|
name := c.UsageLine |
|
i := strings.Index(name, " ") |
|
if i >= 0 { |
|
name = name[:i] |
|
} |
|
return name |
|
} |
|
|
|
func (c *Command) Usage() { |
|
fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine) |
|
fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long)) |
|
os.Exit(2) |
|
} |
|
|
|
// Runnable reports whether the command can be run; otherwise |
|
// it is a documentation pseudo-command such as importpath. |
|
func (c *Command) Runnable() bool { |
|
return c.Run != nil |
|
} |
|
|
|
var CmdVersion = &Command{ |
|
UsageLine: "version", |
|
Short: "show version", |
|
Long: ` |
|
show version |
|
`, |
|
} |
|
|
|
func runVersion(cmd *Command, args []string) { |
|
fmt.Println(APP_VER) |
|
} |
|
|
|
func init() { |
|
CmdVersion.Run = runVersion |
|
CmdVersion.Flags = map[string]bool{} |
|
}
|
|
|