Info feature
diff --git a/action/project_info.go b/action/project_info.go new file mode 100644 index 0000000..807a53d --- /dev/null +++ b/action/project_info.go
@@ -0,0 +1,41 @@ +package action + +import ( + "bytes" + + "github.com/Masterminds/glide/msg" +) + +func Info(format string) { + conf := EnsureConfig() + var buffer bytes.Buffer + varInit := false + for _, var_format := range format { + if varInit { + switch var_format { + case 'n': + buffer.WriteString(conf.Name) + case 'd': + buffer.WriteString(conf.Description) + case 'h': + buffer.WriteString(conf.Home) + case 'l': + buffer.WriteString(conf.License) + case 'v': + buffer.WriteString(conf.Version) + default: + msg.Die("Invalid format %s", string(var_format)) + } + } else { + switch var_format { + case '%': + varInit = true + continue + default: + buffer.WriteString(string(var_format)) + } + } + varInit = false + } + msg.Puts(buffer.String()) +}
diff --git a/action/version.go b/action/version.go deleted file mode 100644 index a26d747..0000000 --- a/action/version.go +++ /dev/null
@@ -1,10 +0,0 @@ -package action - -import ( - "github.com/Masterminds/glide/msg" -) - -func Version() { - conf := EnsureConfig() - msg.Puts(conf.Version) -}
diff --git a/glide.go b/glide.go index 1233e97..9a745fe 100644 --- a/glide.go +++ b/glide.go
@@ -596,24 +596,38 @@ }, }, { - Name: "project", - ShortName: "prj", - Usage: "Project prints some information about this project based on glide.yaml", + Name: "info", + Usage: "Info prints some information about this project based on glide.yaml", Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "version, v", - Usage: "Get the project version.", - }, - cli.BoolFlag{ - Name: "name", - Usage: "Get the project name.", + cli.StringFlag{ + Name: "format, f", + Usage: `Format of the information wanted. Variables: + %n - name + %d - description + %h - homepage + %l - license + %v - version + + Examples: + Given the project with the following glide.yaml: + package: foo + version: 1.0 + homepage: https://foo.io + license: MIT + description: Some foo description + + Then: + glide info -f %n + prints 'foo' + glide info -f "Version: %v" + prints 'Version: 1.0' + glide info -f "%n - %v - %d - %h - %l" + prints 'foo - 1.0 - Some foo description - https://foo.io - MIT'`, }, }, Action: func(c *cli.Context) { - if c.IsSet("version") { - action.Version() - } else if c.IsSet("name") { - action.Name() + if c.IsSet("format") { + action.Info(c.String("format")) } else { cli.ShowCommandHelp(c, c.Command.Name) }
diff --git a/glide.yaml b/glide.yaml index f0108f1..a55094c 100644 --- a/glide.yaml +++ b/glide.yaml
@@ -2,6 +2,7 @@ version: 1.0 homepage: https://glide.sh license: MIT +description: A dependency manager owners: - name: Matt Butcher email: technosophos@gmail.com