Skip to content

Commit

Permalink
✨ feat: add config command to CLI (#108)
Browse files Browse the repository at this point in the history
* 🚨 Fix: changed Println to Printf in jobListCmd

Eliminate simple linter warning about returning value using `Println` function.

* ✨ Feat: add new `config` command to CLI

Added a new `config` command to CLI - with following sub-commands: `config show` , `config clean` . It is the basis for a user to look at and alter settings of their configuration from the command line without having to navigate the OS.

* ✨ Feat: add new functionality to `config clean` CLI cmd

This commit adds multiple quality of life enhancements for manuscript removal from the config.ini.  the clean command can now specify specific manuscripts, bypass interactive mode, remove all manuscripts from a config file, etc.

* ✨ Feat: add `--summary` flag to CLI `config show` cmd

This additional flag prints out a beautified summary of the config file which shares where manuscripts are located - what they're configrued to/some basic information output.  Implemented as a useful debugging tool.

* 🎨 Chore: clean up commander.go

This commit adds additional structure to commander.go to keep it clean as the number of commands increases. In particular, it adds comments and breaks things into helper functions that clarify things throughout.

* 🎨 [chore] Add comments and fix nomenclature

This commit renames ShowConfigSummary to ConfigShowSummary for consistency of the config_manuscript.go file. IT also adds notations and comments throughout so that the logic being used is more apparent to first time readers.
  • Loading branch information
KagemniKarimu authored Dec 23, 2024
1 parent 1d606e1 commit 59cf42d
Show file tree
Hide file tree
Showing 3 changed files with 524 additions and 7 deletions.
127 changes: 121 additions & 6 deletions cli/commands/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
version = "1.1.1"
)

// Execute runs the CLI commands
func Execute(args []string) error {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand All @@ -21,6 +22,8 @@ func Execute(args []string) error {
return nil
}

// *** MAIN COMMANDS *** //
// `init` command to initialize a new manuscript project
var initCmd = &cobra.Command{
Use: "init",
Aliases: []string{"ini", "in", "i"},
Expand All @@ -47,6 +50,88 @@ You'll be prompted to select:
},
}

// `config` command to manage manuscript configuration
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage manuscript configuration",
Long: `🔧 Manage Manuscript Configuration
Actions:
📁 View config file location
📋 Show current configuration
🧹 Clean configuration file
Usage:
- Run without arguments to see config location
- Use 'show' to view full configuration
- Use 'clean' to remove all configurations`,
Example: `>> manuscript-cli config
>> manuscript-cli config show
>> manuscript-cli config clean`,
Run: func(cmd *cobra.Command, args []string) {
ConfigLocation()
},
}

// SUB-COMMANDS for `config` command //
// `config show` command to display manuscript configuration
var configShowCmd = &cobra.Command{
Use: "show",
Short: "Show manuscript configuration",
Long: `📋 Show Manuscript Configuration
Options:
--summary Show condensed overview of configuration
Display includes:
• Config file location
• Base directory
• Manuscript counts
• Port assignments
• Disk vs config differences`,
Example: `>> manuscript-cli config show
>> manuscript-cli config show --summary`,
Run: func(cmd *cobra.Command, args []string) {
summary, _ := cmd.Flags().GetBool("summary")
if summary {
ConfigShowSummary()
} else {
ConfigShow()
}
},
}

// `config clean` command to remove manuscript configurations from config file
var configCleanCmd = &cobra.Command{
Use: "clean [manuscript-names...]",
Short: "Clean manuscript configuration file",
Long: `🧹 Clean Manuscript Configuration
Options:
--all Remove all manuscripts
--force Skip confirmation for removal
Examples:
• Clean specific manuscripts with confirmation:
manuscript-cli config clean manuscript1 manuscript2
• Clean specific manuscripts without confirmation:
manuscript-cli config clean manuscript1 manuscript2 --force
• Clean all manuscripts with confirmation:
manuscript-cli config clean --all
• Clean all manuscripts without confirmation:
manuscript-cli config clean --all --force`,
Run: func(cmd *cobra.Command, args []string) {
all, _ := cmd.Flags().GetBool("all")
force, _ := cmd.Flags().GetBool("force")
ConfigClean(all, force, args)
},
}

// *** JOB COMMANDS *** //
// `list` command to show all manuscript jobs
var jobListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Expand Down Expand Up @@ -74,12 +159,13 @@ Usage:
Run: func(cmd *cobra.Command, args []string) {
config, err := pkg.LoadConfig(manuscriptConfig)
if err != nil {
fmt.Println("Error: Failed to load manuscript config: %v", err)
fmt.Printf("Error: Failed to load manuscript config: %v", err)
}
ListJobs(config)
},
}

// `stop` command to stop a manuscript job
var jobStopCmd = &cobra.Command{
Use: "stop <job_name>",
Short: "Stop a manuscript job",
Expand All @@ -99,6 +185,7 @@ Note: Restart jobs using 'deploy' command`,
},
}

// `logs` command to view logs of a manuscript job
var jobLogsCmd = &cobra.Command{
Use: "logs <job_name>",
Short: "View logs of a manuscript job",
Expand All @@ -116,6 +203,8 @@ Shows:
JobLogs(args[0])
},
}

// `chat` command to chat with the dataset AI for Text-2-SQL queries
var chatCmd = &cobra.Command{
Use: "chat <job_name>",
Aliases: []string{"c"},
Expand Down Expand Up @@ -146,6 +235,7 @@ Required Env Vars:
},
}

// `deploy` command to deploy a manuscript.yaml file
var deployManuscript = &cobra.Command{
Use: "deploy <manuscript-file>",
Aliases: []string{"d"},
Expand Down Expand Up @@ -183,6 +273,8 @@ Requirements:
},
}

// *** UTILITY COMMANDS *** //
// `version` command to show the version of manuscript-cli
var versionCmd = &cobra.Command{
Use: "version",
Short: "Show the version of manuscript-cli",
Expand All @@ -201,17 +293,33 @@ Shows:
}

func init() {
// Configure help from help_template.go
// Set help from help_template.go for root command
configureHelp(rootCmd)

// Ensure commands show up as added instead of alphabetically
cobra.EnableCommandSorting = false

// Add CLI commands in logical groups
// Add commands to root
addCLICommands()

// Add flags to each command and subcommand
configureFlags()

// Disable the default completion command
rootCmd.CompletionOptions.HiddenDefaultCmd = true
}

// Add CLI commands in logical groups
func addCLICommands() {
// Manuscript creation & deployment commands
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(deployManuscript)

// Add config commands
configCmd.AddCommand(configShowCmd)
configCmd.AddCommand(configCleanCmd)
rootCmd.AddCommand(configCmd)

// Job management commands
rootCmd.AddCommand(jobListCmd)
rootCmd.AddCommand(jobStopCmd)
Expand All @@ -223,17 +331,24 @@ func init() {
// Utility commands
rootCmd.AddCommand(versionCmd)

}

// Configure flags for each command
func configureFlags() {
// Add flags to config subcommands
configCleanCmd.Flags().Bool("all", false, "Remove all manuscripts")
configCleanCmd.Flags().Bool("force", false, "Skip confirmation for removal")
configShowCmd.Flags().BoolP("summary", "s", false, "Show condensed overview of configuration")

// Configure deployment flags
deployManuscript.Flags().StringVar(&env, "env", "", "Specify the environment to deploy (local or chainbase)")
deployManuscript.MarkFlagRequired("env")

// Configure version command flags
versionCmd.Flags().BoolP("verbose", "v", false, "Display detailed version information")

// Disable the default completion command
rootCmd.CompletionOptions.HiddenDefaultCmd = true
}

// Default Command for CLI
var rootCmd = &cobra.Command{
Use: "manuscript-cli [command]",
}
Loading

0 comments on commit 59cf42d

Please sign in to comment.