fix(cli): rename root command mol→molecule, register initCmd, fix config scaffold path

- Change rootCmd Use/Short/Long from 'mol' to 'molecule'
- Register initCmd in root so 'molecule init' works
- Update viper config name lookup from 'mol' to 'molecule'
- Fix config init/set to write molecule.yaml instead of mol.yaml
- Update all user-facing strings mol→molecule

Fixes TestCLI_Version, TestCLI_Init, TestCLI_ConfigInit, TestCLI_Completion_GeneratesScript
This commit is contained in:
Molecule AI · sdk-lead 2026-04-23 19:24:12 +00:00
parent 230934561c
commit bf29d8b00a
2 changed files with 26 additions and 25 deletions

View File

@ -19,11 +19,11 @@ import (
var configCmd = &cobra.Command{
Use: "config",
Short: "View and manage CLI and workspace configuration",
Long: `mol config list list all config keys (from file + env)
mol config get <key> print a single config value
mol config set <key> <value> write a key to the config file
mol config init scaffold a default mol.yaml in the current directory
mol config view print the current config file with sources annotated`,
Long: `molecule config list list all config keys (from file + env)
molecule config get <key> print a single config value
molecule config set <key> <value> write a key to the config file
molecule config init scaffold a default molecule.yaml in the current directory
molecule config view print the current config file with sources annotated`,
}
func init() {
@ -44,7 +44,7 @@ var configListCmd = &cobra.Command{
func runConfigList(cmd *cobra.Command, _ []string) error {
settings := viper.AllSettings()
if len(settings) == 0 {
fmt.Println("No config keys set. Use `mol config set <key> <value>` or set env vars.")
fmt.Println("No config keys set. Use `molecule config set <key> <value>` or set env vars.")
return nil
}
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
@ -85,7 +85,7 @@ func runConfigGet(cmd *cobra.Command, args []string) error {
// ===========================================================================
var configSetCmd = &cobra.Command{
Use: "set <key> <value>",
Short: "Write a config key to the config file (~/.config/mol.yaml)",
Short: "Write a config key to the config file (~/.config/molecule.yaml)",
Args: cobra.ExactArgs(2),
RunE: runConfigSet,
}
@ -96,7 +96,7 @@ func runConfigSet(cmd *cobra.Command, args []string) error {
if err != nil {
configDir = "."
}
configFile := filepath.Join(configDir, "mol.yaml")
configFile := filepath.Join(configDir, "molecule.yaml")
v := viper.New()
v.SetConfigFile(configFile)
@ -116,12 +116,12 @@ func runConfigSet(cmd *cobra.Command, args []string) error {
// ===========================================================================
var configInitCmd = &cobra.Command{
Use: "init",
Short: "Scaffold a default mol.yaml in the current directory",
Short: "Scaffold a default molecule.yaml in the current directory",
RunE: runConfigInit,
}
func runConfigInit(cmd *cobra.Command, _ []string) error {
const defaultConfig = `# mol CLI config https://github.com/Molecule-AI/molecule-cli
const defaultConfig = `# molecule CLI config https://github.com/Molecule-AI/molecule-cli
#
# All values can be overridden by environment variables:
# MOLECULE_API_URL, MOLECULE_RUNTIME_URL, MOL_OUTPUT, MOL_VERBOSE, etc.
@ -135,13 +135,13 @@ func runConfigInit(cmd *cobra.Command, _ []string) error {
# Verbose logging: true | false (env: MOL_VERBOSE)
# verbose: false
`
if _, err := os.Stat("mol.yaml"); err == nil {
return fmt.Errorf("config init: mol.yaml already exists (not overwriting)")
if _, err := os.Stat("molecule.yaml"); err == nil {
return fmt.Errorf("config init: molecule.yaml already exists (not overwriting)")
}
if err := os.WriteFile("mol.yaml", []byte(defaultConfig), 0o644); err != nil {
return fmt.Errorf("config init: write mol.yaml: %w", err)
if err := os.WriteFile("molecule.yaml", []byte(defaultConfig), 0o644); err != nil {
return fmt.Errorf("config init: write molecule.yaml: %w", err)
}
fmt.Println("Scaffolded mol.yaml — edit it and run mol --config mol.yaml, or move it to ~/.config/mol.yaml")
fmt.Println("Scaffolded molecule.yaml — edit it and run molecule --config molecule.yaml, or move it to ~/.config/molecule.yaml")
return nil
}
@ -156,7 +156,7 @@ var configViewCmd = &cobra.Command{
func runConfigView(cmd *cobra.Command, _ []string) error {
if viper.ConfigFileUsed() == "" {
fmt.Println("No config file in use. Set one with --config or mol config init.")
fmt.Println("No config file in use. Set one with --config or molecule config init.")
fmt.Println("\nActive env vars starting with MOLECULE_ or MOL_:")
for _, env := range os.Environ() {
if strings.HasPrefix(env, "MOLECULE_") || strings.HasPrefix(env, "MOL_") {

View File

@ -25,18 +25,18 @@ var (
// rootCmd is the top-level molecule command.
var rootCmd = &cobra.Command{
Use: "mol",
Use: "molecule",
Version: Version,
Short: "mol — Molecule AI platform CLI",
Long: `mol is the CLI for the Molecule AI agent platform.
Short: "molecule — Molecule AI platform CLI",
Long: `molecule is the CLI for the Molecule AI agent platform.
Manage workspaces, inspect agents, audit the platform, and configure
agent behaviour from the terminal.
Quick start:
mol workspace list
mol agent list
mol platform health`,
molecule workspace list
molecule agent list
molecule platform health`,
SilenceUsage: true,
SilenceErrors: true,
}
@ -50,7 +50,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "table",
"Output format: table | json | yaml")
rootCmd.PersistentFlags().StringVar(&configPath, "config", "",
"Path to config file (default ~/.config/mol.yaml or ./mol.yaml)")
"Path to config file (default ~/.config/molecule.yaml or ./molecule.yaml)")
rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
return &exitError{code: 2, msg: err.Error()}
})
@ -63,7 +63,7 @@ func Execute() error {
if configPath != "" {
viper.SetConfigFile(configPath)
} else {
viper.SetConfigName("mol")
viper.SetConfigName("molecule")
viper.AddConfigPath("$HOME/.config")
viper.AddConfigPath(".")
}
@ -87,6 +87,7 @@ func init() {
rootCmd.AddCommand(agentCmd)
rootCmd.AddCommand(platformCmd)
rootCmd.AddCommand(configCmd)
rootCmd.AddCommand(initCmd)
}
// exitError wraps a user-facing error with a specific exit code.
@ -122,5 +123,5 @@ func kv(w *tabwriter.Writer, k, v string) {
}
func versionInfo() string {
return fmt.Sprintf("mol %s (go %s)", Version, runtime.Version())
return fmt.Sprintf("molecule %s (go %s)", Version, runtime.Version())
}