From 916128184545e1308c6f276c0ad3b48e828ef083 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Aug 2013 10:54:11 +0800 Subject: [PATCH] Fixed conflicts --- cmd/cmd.go | 59 +++++++++++++++++++++++++++++++++++++++++++++ cmd/gen.go | 2 +- cmd/get.go | 10 ++++---- cmd/repos.go | 2 +- main.go => gopm.go | 60 ++++++---------------------------------------- 5 files changed, 73 insertions(+), 60 deletions(-) create mode 100644 cmd/cmd.go rename main.go => gopm.go (91%) diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 000000000..30fa463f3 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,59 @@ +package cmd + +import ( + "flag" + "fmt" + "os" + "strings" +) + +var ( + 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 ' output. + Long string + + // Flag is a set of flags specific to this command. + Flag flag.FlagSet + + // CustomFlags indicates that the command will do its own + // flag parsing. + CustomFlags 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 +} diff --git a/cmd/gen.go b/cmd/gen.go index d830434fc..013af44ea 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -1,4 +1,4 @@ -package main +package cmd // scan a directory and gen a gopm file func gen(dir string) { diff --git a/cmd/get.go b/cmd/get.go index f7f535afa..162507280 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -1,4 +1,4 @@ -package main +package cmd import ( "fmt" @@ -11,7 +11,7 @@ import ( "strings" ) -var cmdGet = &Command{ +var CmdGet = &Command{ UsageLine: "get [-u] [packages]", Short: "download and install packages and dependencies", Long: ` @@ -46,11 +46,11 @@ See also: go build, go install, go clean. `, } -var getD = cmdGet.Flag.Bool("f", false, "") -var getU = cmdGet.Flag.Bool("u", false, "") +var getD = CmdGet.Flag.Bool("f", false, "") +var getU = CmdGet.Flag.Bool("u", false, "") func init() { - cmdGet.Run = runGet + CmdGet.Run = runGet } func runGet(cmd *Command, args []string) { diff --git a/cmd/repos.go b/cmd/repos.go index badaa1a52..0ec557b27 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -1,4 +1,4 @@ -package main +package cmd type Repos interface { Url(pkgName string, ver string) string diff --git a/main.go b/gopm.go similarity index 91% rename from main.go rename to gopm.go index 7db3f2ffc..d8966d61b 100644 --- a/main.go +++ b/gopm.go @@ -22,70 +22,24 @@ import ( "text/template" "unicode" "unicode/utf8" + + "github.com/gpmgo/gopm/cmd" ) var ( - config map[string]interface{} - reposDir string = "~/.gopm/repos" + config map[string]interface{} ) -// 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 ' output. - Long string - - // Flag is a set of flags specific to this command. - Flag flag.FlagSet - - // CustomFlags indicates that the command will do its own - // flag parsing. - CustomFlags 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 -} - // Commands lists the available commands and help topics. // The order here is the order in which they are printed by 'go help'. -var commands = []*Command{ +var commands = []*cmd.Command{ /*cmdBuild, cmdClean, cmdDoc, cmdEnv, cmdFix, cmdFmt,*/ - cmdGet, + cmd.CmdGet, /*cmdInstall, cmdList, cmdRun, @@ -267,8 +221,8 @@ func help(args []string) { if arg == "documentation" { buf := new(bytes.Buffer) printUsage(buf) - usage := &Command{Long: buf.String()} - tmpl(os.Stdout, documentationTemplate, append([]*Command{usage}, commands...)) + usage := &cmd.Command{Long: buf.String()} + tmpl(os.Stdout, documentationTemplate, append([]*cmd.Command{usage}, commands...)) return }