fix(cli): complete "mol" → "molecule" rename across all cmd packages

Rename all user-facing "mol" references to "molecule" to match the
published binary name (binary: molecule in .goreleaser.yaml):
- root.go: Use string, versionInfo, viper config name, flag descriptions
- init.go: section comment, Short, Long, cfgPath, scaffolded message
- config.go: Long description, Shorts, configFile, WriteFile, Stat check
- molecule_test.go: binary name, version output check, mol.yaml → molecule.yaml

Also fix test helper to use runtime.GOEXE instead of hardcoded /tmp/go/bin/go.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · sdk-dev 2026-04-22 06:36:42 +00:00
parent f654a2dff9
commit ea69db8bfc
4 changed files with 40 additions and 40 deletions

View File

@ -202,7 +202,7 @@ func repoRoot() string {
// mol returns the path to the CLI binary, building it if needed.
func mol(t *testing.T) string {
root := repoRoot()
exe := filepath.Join(t.TempDir(), "mol")
exe := filepath.Join(t.TempDir(), "molecule")
goBin := runtime.GOEXE // e.g. "/usr/bin/go" — respects PATH
cmd := exec.Command(goBin, "build", "-o", exe, "./cmd/molecule")
cmd.Dir = root
@ -269,8 +269,8 @@ func TestCLI_Version(t *testing.T) {
t.Fatalf("mol --version: %v", err)
}
out := stdout.String()
if !strings.Contains(out, "mol") {
t.Errorf("expected 'mol' in version output, got: %s", out)
if !strings.Contains(out, "molecule") {
t.Errorf("expected 'molecule' in version output, got: %s", out)
}
}
@ -722,9 +722,9 @@ func TestCLI_ConfigInit(t *testing.T) {
if err != nil {
t.Fatalf("mol config init: %v\nstderr: %s", err, stderr.String())
}
f := filepath.Join(dir, "mol.yaml")
f := filepath.Join(dir, "molecule.yaml")
if _, err := os.Stat(f); err != nil {
t.Errorf("mol.yaml not scaffolded at %s", f)
t.Errorf("molecule.yaml not scaffolded at %s", f)
}
}
@ -762,12 +762,12 @@ func TestCLI_Init(t *testing.T) {
if err != nil {
t.Fatalf("mol init: %v\nstderr: %s", err, stderr.String())
}
f := filepath.Join(dir, "mol.yaml")
f := filepath.Join(dir, "molecule.yaml")
if _, err := os.Stat(f); err != nil {
t.Errorf("mol.yaml not scaffolded at %s", f)
t.Errorf("molecule.yaml not scaffolded at %s", f)
}
out := stdout.String()
if !strings.Contains(out, "Scaffolded") && !strings.Contains(out, "mol.yaml") {
if !strings.Contains(out, "Scaffolded") && !strings.Contains(out, "molecule.yaml") {
t.Errorf("expected scaffolded confirmation in output, got:\n%s", out)
}
}
@ -775,21 +775,21 @@ func TestCLI_Init(t *testing.T) {
func TestCLI_Init_AlreadyExists(t *testing.T) {
exe := mol(t)
dir := t.TempDir()
// pre-create mol.yaml
os.WriteFile(filepath.Join(dir, "mol.yaml"), []byte("x"), 0o644)
// pre-create molecule.yaml
os.WriteFile(filepath.Join(dir, "molecule.yaml"), []byte("x"), 0o644)
cmd := exec.Command(exe, "init")
cmd.Dir = dir
var stderr bytes.Buffer
cmd.Stderr = &stderr
err := cmd.Run()
if err == nil {
t.Fatalf("expected error when mol.yaml exists, got none")
t.Fatalf("expected error when molecule.yaml exists, got none")
}
exitErr, ok := err.(*exec.ExitError)
if !ok {
t.Fatalf("expected *exec.ExitError, got %T", err)
}
if exitErr.ExitCode() == 0 {
t.Errorf("expected non-zero exit code when mol.yaml exists, got 0")
t.Errorf("expected non-zero exit code when molecule.yaml exists, got 0")
}
}

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

@ -9,13 +9,13 @@ import (
)
// ---------------------------------------------------------------------------
// mol init — bootstrap workspace setup
// molecule init — bootstrap workspace setup
// ---------------------------------------------------------------------------
var initCmd = &cobra.Command{
Use: "init",
Short: "Bootstrap workspace and scaffold a mol.yaml config file",
Long: `Scaffold a default mol.yaml in the current directory.
Short: "Bootstrap workspace and scaffold a molecule.yaml config file",
Long: `Scaffold a default molecule.yaml in the current directory.
This is the primary entry point for new users. Run once in a project
to create a configuration file that can be checked into version control.
@ -23,18 +23,18 @@ to create a configuration file that can be checked into version control.
All values can be overridden by environment variables
(MOLECULE_API_URL, MOLECULE_RUNTIME_URL, etc.).
After init, run 'mol --config mol.yaml workspace list' to verify your setup.`,
After init, run 'molecule --config molecule.yaml workspace list' to verify your setup.`,
RunE: runInit,
}
func runInit(cmd *cobra.Command, _ []string) error {
cfgPath := "mol.yaml"
cfgPath := "molecule.yaml"
if _, err := os.Stat(cfgPath); err == nil {
return fmt.Errorf("init: %s already exists — not overwriting (use --force to replace)", cfgPath)
}
content := `# mol CLI configuration https://github.com/Molecule-AI/molecule-cli
content := `# molecule CLI configuration 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.
@ -61,8 +61,8 @@ func runInit(cmd *cobra.Command, _ []string) error {
fmt.Printf("Scaffolded %s\n", absPath)
fmt.Println()
fmt.Println("Next steps:")
fmt.Println(" 1. Edit mol.yaml with your platform URL")
fmt.Println(" 2. Run mol --config mol.yaml workspace list")
fmt.Println(" 3. For full reference: mol --help")
fmt.Println(" 1. Edit molecule.yaml with your platform URL")
fmt.Println(" 2. Run molecule --config molecule.yaml workspace list")
fmt.Println(" 3. For full reference: molecule --help")
return nil
}

View File

@ -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(".")
}
@ -123,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())
}