From 26bd1dd11010b4d86cebe2510ad7085a6b316334 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 28 Jun 2020 18:26:29 +0200 Subject: commands: refactor to avoid globals --- commands/commands.go | 69 ++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'commands/commands.go') diff --git a/commands/commands.go b/commands/commands.go index bd8cb14d..103d5412 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -1,27 +1,42 @@ package commands import ( - "fmt" "sort" "github.com/spf13/cobra" ) -var ( - commandsDesc bool -) +type commandOptions struct { + desc bool +} -type commandSorterByName []*cobra.Command +func newCommandsCommand() *cobra.Command { + env := newEnv() + options := commandOptions{} -func (c commandSorterByName) Len() int { return len(c) } -func (c commandSorterByName) Swap(i, j int) { c[i], c[j] = c[j], c[i] } -func (c commandSorterByName) Less(i, j int) bool { return c[i].CommandPath() < c[j].CommandPath() } + cmd := &cobra.Command{ + Use: "commands [