From c0c8d2ae14587dcf549e802598c4223e4fe58f08 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Aug 2013 10:35:08 +0800 Subject: [PATCH 1/4] Update dir strcut --- .DS_Store | Bin 0 -> 6148 bytes gen.go => cmd/gen.go | 0 get.go => cmd/get.go | 0 repos.go => cmd/repos.go | 0 arch.png => docs/arch.png | Bin features_CN.md => docs/features_CN.md | 0 usage.md => docs/usage.md | 0 7 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store rename gen.go => cmd/gen.go (100%) rename get.go => cmd/get.go (100%) rename repos.go => cmd/repos.go (100%) rename arch.png => docs/arch.png (100%) rename features_CN.md => docs/features_CN.md (100%) rename usage.md => docs/usage.md (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f3dddc3b41eaf33f033e2a6f8d28381616a7bd45 GIT binary patch literal 6148 zcmeH~&r8EF6vvZoYKjWI2s;MPLpH6Cl-Z^uiu}wY?)OA@;_jIE}J}m(9~CzxF5D!jGeeFqqva zy9kPT?gcaDxeAI2c$7WNvIOk0i5|sKF}bzd%cXO2){)0ur|igOzjxY^j?*toOIVh@ z5(kGz=a<9arF>mgnj#0tD(xGsDqMM?yS01+SpL_iTR2ZY!q z9z=i$5P@$5aDR}HQC*{zR<(6Nf!AmBw@@*Gjc*B5Y1B1ZX$21?uDgQjuG~B^xb6<^ z(!{w&E3LXa<7#FY$IM(mUbvba+NBC-+|^1Y5g-EV1e&^PiHpQH6ghyVZp literal 0 HcmV?d00001 diff --git a/gen.go b/cmd/gen.go similarity index 100% rename from gen.go rename to cmd/gen.go diff --git a/get.go b/cmd/get.go similarity index 100% rename from get.go rename to cmd/get.go diff --git a/repos.go b/cmd/repos.go similarity index 100% rename from repos.go rename to cmd/repos.go diff --git a/arch.png b/docs/arch.png similarity index 100% rename from arch.png rename to docs/arch.png diff --git a/features_CN.md b/docs/features_CN.md similarity index 100% rename from features_CN.md rename to docs/features_CN.md diff --git a/usage.md b/docs/usage.md similarity index 100% rename from usage.md rename to docs/usage.md From d3d8cab2b96c897789c389e34185c7eabaa43800 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Aug 2013 10:35:32 +0800 Subject: [PATCH 2/4] Update --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index f3dddc3b41eaf33f033e2a6f8d28381616a7bd45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~&r8EF6vvZoYKjWI2s;MPLpH6Cl-Z^uiu}wY?)OA@;_jIE}J}m(9~CzxF5D!jGeeFqqva zy9kPT?gcaDxeAI2c$7WNvIOk0i5|sKF}bzd%cXO2){)0ur|igOzjxY^j?*toOIVh@ z5(kGz=a<9arF>mgnj#0tD(xGsDqMM?yS01+SpL_iTR2ZY!q z9z=i$5P@$5aDR}HQC*{zR<(6Nf!AmBw@@*Gjc*B5Y1B1ZX$21?uDgQjuG~B^xb6<^ z(!{w&E3LXa<7#FY$IM(mUbvba+NBC-+|^1Y5g-EV1e&^PiHpQH6ghyVZp From 9fc6c217ca7a6ecf2aa69b357e21ec45474ba62a Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Aug 2013 10:36:17 +0800 Subject: [PATCH 3/4] .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f78fbe263 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +gopm +*.exe +*.exe~ From 916128184545e1308c6f276c0ad3b48e828ef083 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 13 Aug 2013 10:54:11 +0800 Subject: [PATCH 4/4] 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 }