diff --git a/internal/commands/configcmd/cat.go b/internal/commands/configcmd/cat.go index e2493ef..1567924 100644 --- a/internal/commands/configcmd/cat.go +++ b/internal/commands/configcmd/cat.go @@ -12,8 +12,9 @@ import ( var catCmd = &cobra.Command{ Use: "cat", Short: "Print config.json of Dockma.", - Long: `-`, + Long: "Print config.json of Dockma.", Example: "dockma config cat", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { filepath := config.GetDockmaFilepath(("config.json")) diff --git a/internal/commands/configcmd/home.go b/internal/commands/configcmd/home.go index 8e4a6f0..d5ec1a3 100644 --- a/internal/commands/configcmd/home.go +++ b/internal/commands/configcmd/home.go @@ -11,8 +11,9 @@ import ( var homeCmd = &cobra.Command{ Use: "home", Short: "Print home dir of Dockma config.", - Long: `-`, + Long: "Print home dir of Dockma config.", Example: "dockma config home", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { fmt.Printf("Dockma config home dir: %s%s%s\n", chalk.Cyan, viper.GetString("home"), chalk.ResetColor) }, diff --git a/internal/commands/configcmd/root.go b/internal/commands/configcmd/root.go index 7376db2..2f5efb7 100644 --- a/internal/commands/configcmd/root.go +++ b/internal/commands/configcmd/root.go @@ -4,9 +4,10 @@ import ( "github.com/spf13/cobra" ) -// ConfigCommand is the top level config command +// ConfigCommand implements the top level config command var ConfigCommand = &cobra.Command{ - Use: "config", - Short: "Dockma configuration details.", - Long: "-", + Use: "config", + Short: "Dockma configuration details.", + Long: "Dockma configuration details.", + Aliases: []string{"cfg"}, } diff --git a/internal/commands/configcmd/set.go b/internal/commands/configcmd/set.go index 32e896d..075ce3c 100644 --- a/internal/commands/configcmd/set.go +++ b/internal/commands/configcmd/set.go @@ -13,9 +13,10 @@ import ( var setCmd = &cobra.Command{ Use: "set", - Short: "Set dockma config vars in an interactive walkthrough.", - Long: `-`, + Short: "Set Dockma config vars in an interactive walkthrough.", + Long: "Set Dockma config vars in an interactive walkthrough.", Example: "dockma config set", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { options := []string{ fmt.Sprintf("hidesubcommandoutput: %t", viper.GetBool("hidesubcommandoutput")), diff --git a/internal/commands/downcmd/root.go b/internal/commands/downcmd/root.go index 6051432..e66b1f9 100644 --- a/internal/commands/downcmd/root.go +++ b/internal/commands/downcmd/root.go @@ -13,10 +13,13 @@ import ( "github.com/ttacon/chalk" ) +// DownCommand implements the top level down command var DownCommand = &cobra.Command{ - Use: "down", - Short: "Stops active environment.", - Long: "-", + Use: "down", + Short: "Stops active environment.", + Long: "Stops active environment.", + Example: "dockma down", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { filepath := config.GetLogfile() diff --git a/internal/commands/envscmd/init.go b/internal/commands/envscmd/init.go index 96a4f6a..c1dd357 100644 --- a/internal/commands/envscmd/init.go +++ b/internal/commands/envscmd/init.go @@ -15,16 +15,9 @@ import ( var initCmd = &cobra.Command{ Use: "init [path-to-environment]", Short: "Initialize new environment.", - Long: `-`, + Long: "Initialize new environment.", + Args: cobra.RangeArgs(0, 1), Example: "dockma envs init path/to/env", - // TODO add flag to prevent setting active - Args: func(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Too many arguments") - } - - return nil - }, Run: func(cmd *cobra.Command, args []string) { var env string @@ -33,7 +26,7 @@ var initCmd = &cobra.Command{ path = args[0] if err := os.Chdir(path); err != nil { - fmt.Printf("%sError. Could not change directory to: %s%s\n", chalk.Red, path, chalk.ResetColor) + fmt.Printf("%sError: Could not find directory: %s%s\n", chalk.Red, path, chalk.ResetColor) os.Exit(0) } diff --git a/internal/commands/envscmd/list.go b/internal/commands/envscmd/list.go index 606ab9e..479fd87 100644 --- a/internal/commands/envscmd/list.go +++ b/internal/commands/envscmd/list.go @@ -13,7 +13,8 @@ import ( var listCmd = &cobra.Command{ Use: "list", Short: "List all configured environments.", - Long: `-`, + Long: "List all configured environments.", + Args: cobra.NoArgs, Example: "dockma envs list", Run: func(cmd *cobra.Command, args []string) { envs := config.GetEnvs() diff --git a/internal/commands/envscmd/remove.go b/internal/commands/envscmd/remove.go index 8aa84e0..19bb18f 100644 --- a/internal/commands/envscmd/remove.go +++ b/internal/commands/envscmd/remove.go @@ -1,7 +1,6 @@ package envscmd import ( - "errors" "fmt" "github.com/martinnirtl/dockma/internal/survey" @@ -15,15 +14,9 @@ var removeCmd = &cobra.Command{ Use: "remove [environment]", Aliases: []string{"rm"}, Short: "Remove environment.", - Long: `-`, + Long: "Remove environment.", + Args: cobra.RangeArgs(0, 1), Example: "dockma envs remove my-env", - Args: func(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Too many arguments") - } - - return nil - }, Run: func(cmd *cobra.Command, args []string) { env := "" if len(args) == 0 { diff --git a/internal/commands/envscmd/root.go b/internal/commands/envscmd/root.go index 77d7555..f56a706 100644 --- a/internal/commands/envscmd/root.go +++ b/internal/commands/envscmd/root.go @@ -4,9 +4,10 @@ import ( "github.com/spf13/cobra" ) -// EnvsCommand is the top level Envs command +// EnvsCommand implements the top level envs command var EnvsCommand = &cobra.Command{ - Use: "envs", - Short: "Environments reflect docker-compose based projects.", - Long: "-", + Use: "env", + Aliases: []string{"environment"}, + Short: "Environments reflect docker-compose based projects.", + Long: "Environments reflect docker-compose based projects.", } diff --git a/internal/commands/envscmd/set.go b/internal/commands/envscmd/set.go index f620b0f..40a274f 100644 --- a/internal/commands/envscmd/set.go +++ b/internal/commands/envscmd/set.go @@ -1,7 +1,6 @@ package envscmd import ( - "errors" "fmt" "github.com/martinnirtl/dockma/internal/utils" @@ -13,15 +12,9 @@ import ( var setCmd = &cobra.Command{ Use: "set [environment]", Short: "Set active environment.", - Long: `-`, + Long: "Set active environment.", + Args: cobra.RangeArgs(0, 1), Example: "dockma envs set", - Args: func(cmd *cobra.Command, args []string) error { - if len(args) > 1 { - return errors.New("Too many arguments") - } - - return nil - }, Run: func(cmd *cobra.Command, args []string) { env := "" if len(args) == 0 { diff --git a/internal/commands/initcmd/root.go b/internal/commands/initcmd/root.go index 88a4092..73910fc 100644 --- a/internal/commands/initcmd/root.go +++ b/internal/commands/initcmd/root.go @@ -15,10 +15,12 @@ import ( "github.com/ttacon/chalk" ) +// InitCommand implements the top level init command var InitCommand = &cobra.Command{ Use: "init", Short: "Initialize the Dockma CLI.", - Long: "-", + Long: "Initialize the Dockma CLI.", + Args: cobra.NoArgs, PersistentPreRun: initPreRunHook, // used to override root PreRun func Run: initCommandHandler, } diff --git a/internal/commands/inspectcmd/root.go b/internal/commands/inspectcmd/root.go index 5a16e15..873366e 100644 --- a/internal/commands/inspectcmd/root.go +++ b/internal/commands/inspectcmd/root.go @@ -12,10 +12,12 @@ import ( "github.com/ttacon/chalk" ) +// InspectCommand implements the top level inspect command var InspectCommand = &cobra.Command{ Use: "inspect", Short: "Print detailed output of previously executed command [up|down|pull].", - Long: "-", + Long: "Print detailed output of previously executed command [up|down|pull].", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { filepath := config.GetLogfile() diff --git a/internal/commands/installcmd/root.go b/internal/commands/installcmd/root.go index f0c6d8f..ba8b3f0 100644 --- a/internal/commands/installcmd/root.go +++ b/internal/commands/installcmd/root.go @@ -1 +1,13 @@ package installcmd + +import ( + "github.com/spf13/cobra" +) + +// InstallCommand implements the top level install command +var InstallCommand = &cobra.Command{ + Use: "install", + Short: "-", + Long: "-", + Run: func(cmd *cobra.Command, args []string) {}, +} diff --git a/internal/commands/logscmd/root.go b/internal/commands/logscmd/root.go index 653e015..93eeb28 100644 --- a/internal/commands/logscmd/root.go +++ b/internal/commands/logscmd/root.go @@ -5,7 +5,9 @@ import ( "os" "sort" + "github.com/martinnirtl/dockma/internal/config" "github.com/martinnirtl/dockma/internal/utils" + "github.com/martinnirtl/dockma/pkg/dockercompose" "github.com/martinnirtl/dockma/pkg/externalcommand" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -15,10 +17,13 @@ var followFlag bool var timestampsFlag bool var tailFlag int +// LogsCommand implements the top level logs command var LogsCommand = &cobra.Command{ - Use: "logs [service...]", - Short: "Logs output of all or only selected services.", - Long: "-", + Use: "logs [service...]", + Short: "Logs output of all or only selected services.", + Long: "Logs output of all or only selected services.", + Args: cobra.OnlyValidArgs, + ValidArgs: getValidArgs(), Run: func(cmd *cobra.Command, args []string) { activeEnv := viper.GetString("active") @@ -67,3 +72,18 @@ func addFlagsToArgs(args []string) []string { return args } + +func getValidArgs() []string { + activeEnv := config.GetActiveEnv() + + if activeEnv == "-" { + utils.NoEnvs() + } + + envHomeDir := config.GetEnvHomeDir(activeEnv) + + services, err := dockercompose.GetServices(envHomeDir) + utils.Error(err) + + return services.All +} diff --git a/internal/commands/profilecmd/create.go b/internal/commands/profilecmd/create.go index 65c4a30..169be35 100644 --- a/internal/commands/profilecmd/create.go +++ b/internal/commands/profilecmd/create.go @@ -16,7 +16,8 @@ import ( var createCmd = &cobra.Command{ Use: "create", Short: "Create named service selection.", - Long: `-`, + Long: "Create named service selection.", + Args: cobra.NoArgs, Example: "dockma profile create", Run: func(cmd *cobra.Command, args []string) { activeEnv := config.GetActiveEnv() diff --git a/internal/commands/profilecmd/delete.go b/internal/commands/profilecmd/delete.go index 17494f9..55a20bc 100644 --- a/internal/commands/profilecmd/delete.go +++ b/internal/commands/profilecmd/delete.go @@ -15,7 +15,8 @@ import ( var deleteCmd = &cobra.Command{ Use: "delete", Short: "Delete a profile of active environment.", - Long: `-`, + Long: "Delete a profile of active environment.", + Args: cobra.NoArgs, Aliases: []string{"del"}, Example: "dockma profile delete", Run: func(cmd *cobra.Command, args []string) { diff --git a/internal/commands/profilecmd/list.go b/internal/commands/profilecmd/list.go index 9fb097b..64fe290 100644 --- a/internal/commands/profilecmd/list.go +++ b/internal/commands/profilecmd/list.go @@ -14,7 +14,8 @@ var servicesFlag bool var listCmd = &cobra.Command{ Use: "list", Short: "List profiles of active environment.", - Long: `-`, + Long: "List profiles of active environment.", + Args: cobra.NoArgs, Example: "dockma profile list", Run: func(cmd *cobra.Command, args []string) { activeEnv := config.GetActiveEnv() diff --git a/internal/commands/profilecmd/rename.go b/internal/commands/profilecmd/rename.go index 28d3695..f76d66e 100644 --- a/internal/commands/profilecmd/rename.go +++ b/internal/commands/profilecmd/rename.go @@ -16,7 +16,8 @@ import ( var renameCmd = &cobra.Command{ Use: "rename", Short: "Rename profile.", - Long: `-`, + Long: "Rename profile.", + Args: cobra.NoArgs, Example: "dockma profile rename", Run: func(cmd *cobra.Command, args []string) { activeEnv := config.GetActiveEnv() diff --git a/internal/commands/profilecmd/root.go b/internal/commands/profilecmd/root.go index 0981fb9..2c377e4 100644 --- a/internal/commands/profilecmd/root.go +++ b/internal/commands/profilecmd/root.go @@ -2,9 +2,9 @@ package profilecmd import "github.com/spf13/cobra" -// ProfileCommand is the top level config command +// ProfileCommand implements the top level profile command var ProfileCommand = &cobra.Command{ Use: "profile", Short: "Manage profiles (predefined service selections).", - Long: "-", + Long: "Manage profiles (predefined service selections).", } diff --git a/internal/commands/profilecmd/update.go b/internal/commands/profilecmd/update.go index 4e844da..74acf63 100644 --- a/internal/commands/profilecmd/update.go +++ b/internal/commands/profilecmd/update.go @@ -16,7 +16,9 @@ import ( var updateCmd = &cobra.Command{ Use: "update", Short: "Update profile's service selection.", - Long: `-`, + Long: "Update profile's service selection.", + Aliases: []string{"upd"}, + Args: cobra.NoArgs, Example: "dockma profile update", Run: func(cmd *cobra.Command, args []string) { activeEnv := config.GetActiveEnv() diff --git a/internal/commands/pscmd/root.go b/internal/commands/pscmd/root.go index fa10486..cc7943d 100644 --- a/internal/commands/pscmd/root.go +++ b/internal/commands/pscmd/root.go @@ -10,10 +10,12 @@ import ( "github.com/spf13/viper" ) +// PSCommand implements the top level ps command var PSCommand = &cobra.Command{ Use: "ps", Short: "List running services of active environment.", - Long: "-", + Long: "List running services of active environment.", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { activeEnv := viper.GetString("active") diff --git a/internal/commands/pullcmd/root.go b/internal/commands/pullcmd/root.go index 7cdd158..3d84f2b 100644 --- a/internal/commands/pullcmd/root.go +++ b/internal/commands/pullcmd/root.go @@ -41,11 +41,12 @@ func Pull(path string, log bool) error { return nil } -// PullCommand is a top level dockma command +// PullCommand implements the top level pull command var PullCommand = &cobra.Command{ Use: "pull", Short: "Run 'git pull' in active environment home dir.", - Long: "-", + Long: "Run 'git pull' in active environment home dir.", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { activeEnv := config.GetActiveEnv() diff --git a/internal/commands/upcmd/root.go b/internal/commands/upcmd/root.go index cc82c72..770904e 100644 --- a/internal/commands/upcmd/root.go +++ b/internal/commands/upcmd/root.go @@ -18,11 +18,12 @@ import ( "github.com/ttacon/chalk" ) -// UpCommand implements the top level dockma command up +// UpCommand implements the top level up command var UpCommand = &cobra.Command{ Use: "up", Short: "Runs active environment with service selection.", - Long: "-", + Long: "Runs active environment with service selection.", + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { filepath := config.GetLogfile() diff --git a/internal/commands/versioncmd/root.go b/internal/commands/versioncmd/root.go index 223ca3d..2472b6e 100644 --- a/internal/commands/versioncmd/root.go +++ b/internal/commands/versioncmd/root.go @@ -6,11 +6,13 @@ import ( "github.com/spf13/cobra" ) -// VersionCommand is the top level version command +// VersionCommand implements the top level version command var VersionCommand = &cobra.Command{ Use: "version", Short: "Print the version number of dockma.", - Long: "-", + Long: "Print the version number of dockma.", + Args: cobra.NoArgs, + Hidden: true, PersistentPreRun: func(cmd *cobra.Command, args []string) {}, Run: func(cmd *cobra.Command, args []string) { fmt.Println("🐳 Dockma v0.0.0")