-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mathieu Frenette <[email protected]>
- Loading branch information
Showing
3 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package vars | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/Samasource/jen/src/cmd/internal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// New creates a cobra command | ||
func New(options *internal.Options) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "vars", | ||
Aliases: []string{"var"}, | ||
Short: "Lists variables defined in current project and their current values", | ||
Args: cobra.NoArgs, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
return run(options, args) | ||
}, | ||
} | ||
} | ||
|
||
func run(options *internal.Options, args []string) error { | ||
execContext, err := options.NewContext() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vars := execContext.GetVars() | ||
|
||
// Sort names | ||
names := make([]string, 0, len(vars)) | ||
for name := range vars { | ||
names = append(names, name) | ||
} | ||
sort.Strings(names) | ||
|
||
// Print names and values | ||
for _, name := range names { | ||
value := vars[name] | ||
fmt.Printf("%s: %v\n", name, value) | ||
} | ||
return nil | ||
} |