Merge pull request #382 from franciscocpg/feat/info
diff --git a/action/project_info.go b/action/project_info.go
new file mode 100644
index 0000000..5e0995e
--- /dev/null
+++ b/action/project_info.go
@@ -0,0 +1,39 @@
+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)
+ 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/glide.go b/glide.go
index c69952b..2981837 100644
--- a/glide.go
+++ b/glide.go
@@ -596,6 +596,48 @@
},
},
{
+ Name: "info",
+ Usage: "Info prints information about this project",
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "format, f",
+ Usage: `Format of the information wanted (required).`,
+ },
+ },
+ Description: `A format containing the text with replacement variables
+ has to be passed in. Those variables are:
+
+ %n - name
+ %d - description
+ %h - homepage
+ %l - license
+
+ For example, given a project with the following glide.yaml:
+
+ package: foo
+ homepage: https://example.com
+ license: MIT
+ description: Some example description
+
+ Then running the following commands:
+
+ glide info -f %n
+ prints 'foo'
+
+ glide info -f "License: %l"
+ prints 'License: MIT'
+
+ glide info -f "%n - %d - %h - %l"
+ prints 'foo - Some example description - https://example.com - MIT'`,
+ Action: func(c *cli.Context) {
+ if c.IsSet("format") {
+ action.Info(c.String("format"))
+ } else {
+ cli.ShowCommandHelp(c, c.Command.Name)
+ }
+ },
+ },
+ {
Name: "about",
Usage: "Learn about Glide",
Action: func(c *cli.Context) {