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:
parent
f654a2dff9
commit
ea69db8bfc
@ -202,7 +202,7 @@ func repoRoot() string {
|
|||||||
// mol returns the path to the CLI binary, building it if needed.
|
// mol returns the path to the CLI binary, building it if needed.
|
||||||
func mol(t *testing.T) string {
|
func mol(t *testing.T) string {
|
||||||
root := repoRoot()
|
root := repoRoot()
|
||||||
exe := filepath.Join(t.TempDir(), "mol")
|
exe := filepath.Join(t.TempDir(), "molecule")
|
||||||
goBin := runtime.GOEXE // e.g. "/usr/bin/go" — respects PATH
|
goBin := runtime.GOEXE // e.g. "/usr/bin/go" — respects PATH
|
||||||
cmd := exec.Command(goBin, "build", "-o", exe, "./cmd/molecule")
|
cmd := exec.Command(goBin, "build", "-o", exe, "./cmd/molecule")
|
||||||
cmd.Dir = root
|
cmd.Dir = root
|
||||||
@ -269,8 +269,8 @@ func TestCLI_Version(t *testing.T) {
|
|||||||
t.Fatalf("mol --version: %v", err)
|
t.Fatalf("mol --version: %v", err)
|
||||||
}
|
}
|
||||||
out := stdout.String()
|
out := stdout.String()
|
||||||
if !strings.Contains(out, "mol") {
|
if !strings.Contains(out, "molecule") {
|
||||||
t.Errorf("expected 'mol' in version output, got: %s", out)
|
t.Errorf("expected 'molecule' in version output, got: %s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,9 +722,9 @@ func TestCLI_ConfigInit(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mol config init: %v\nstderr: %s", err, stderr.String())
|
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 {
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("mol init: %v\nstderr: %s", err, stderr.String())
|
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 {
|
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()
|
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)
|
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) {
|
func TestCLI_Init_AlreadyExists(t *testing.T) {
|
||||||
exe := mol(t)
|
exe := mol(t)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
// pre-create mol.yaml
|
// pre-create molecule.yaml
|
||||||
os.WriteFile(filepath.Join(dir, "mol.yaml"), []byte("x"), 0o644)
|
os.WriteFile(filepath.Join(dir, "molecule.yaml"), []byte("x"), 0o644)
|
||||||
cmd := exec.Command(exe, "init")
|
cmd := exec.Command(exe, "init")
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err == nil {
|
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)
|
exitErr, ok := err.(*exec.ExitError)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected *exec.ExitError, got %T", err)
|
t.Fatalf("expected *exec.ExitError, got %T", err)
|
||||||
}
|
}
|
||||||
if exitErr.ExitCode() == 0 {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,11 +19,11 @@ import (
|
|||||||
var configCmd = &cobra.Command{
|
var configCmd = &cobra.Command{
|
||||||
Use: "config",
|
Use: "config",
|
||||||
Short: "View and manage CLI and workspace configuration",
|
Short: "View and manage CLI and workspace configuration",
|
||||||
Long: `mol config list — list all config keys (from file + env)
|
Long: `molecule config list — list all config keys (from file + env)
|
||||||
mol config get <key> — print a single config value
|
molecule config get <key> — print a single config value
|
||||||
mol config set <key> <value> — write a key to the config file
|
molecule config set <key> <value> — write a key to the config file
|
||||||
mol config init — scaffold a default mol.yaml in the current directory
|
molecule config init — scaffold a default molecule.yaml in the current directory
|
||||||
mol config view — print the current config file with sources annotated`,
|
molecule config view — print the current config file with sources annotated`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -44,7 +44,7 @@ var configListCmd = &cobra.Command{
|
|||||||
func runConfigList(cmd *cobra.Command, _ []string) error {
|
func runConfigList(cmd *cobra.Command, _ []string) error {
|
||||||
settings := viper.AllSettings()
|
settings := viper.AllSettings()
|
||||||
if len(settings) == 0 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
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{
|
var configSetCmd = &cobra.Command{
|
||||||
Use: "set <key> <value>",
|
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),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: runConfigSet,
|
RunE: runConfigSet,
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func runConfigSet(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
configDir = "."
|
configDir = "."
|
||||||
}
|
}
|
||||||
configFile := filepath.Join(configDir, "mol.yaml")
|
configFile := filepath.Join(configDir, "molecule.yaml")
|
||||||
|
|
||||||
v := viper.New()
|
v := viper.New()
|
||||||
v.SetConfigFile(configFile)
|
v.SetConfigFile(configFile)
|
||||||
@ -116,12 +116,12 @@ func runConfigSet(cmd *cobra.Command, args []string) error {
|
|||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
var configInitCmd = &cobra.Command{
|
var configInitCmd = &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Scaffold a default mol.yaml in the current directory",
|
Short: "Scaffold a default molecule.yaml in the current directory",
|
||||||
RunE: runConfigInit,
|
RunE: runConfigInit,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConfigInit(cmd *cobra.Command, _ []string) error {
|
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:
|
# All values can be overridden by environment variables:
|
||||||
# MOLECULE_API_URL, MOLECULE_RUNTIME_URL, MOL_OUTPUT, MOL_VERBOSE, etc.
|
# 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 logging: true | false (env: MOL_VERBOSE)
|
||||||
# verbose: false
|
# verbose: false
|
||||||
`
|
`
|
||||||
if _, err := os.Stat("mol.yaml"); err == nil {
|
if _, err := os.Stat("molecule.yaml"); err == nil {
|
||||||
return fmt.Errorf("config init: mol.yaml already exists (not overwriting)")
|
return fmt.Errorf("config init: molecule.yaml already exists (not overwriting)")
|
||||||
}
|
}
|
||||||
if err := os.WriteFile("mol.yaml", []byte(defaultConfig), 0o644); err != nil {
|
if err := os.WriteFile("molecule.yaml", []byte(defaultConfig), 0o644); err != nil {
|
||||||
return fmt.Errorf("config init: write mol.yaml: %w", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ var configViewCmd = &cobra.Command{
|
|||||||
|
|
||||||
func runConfigView(cmd *cobra.Command, _ []string) error {
|
func runConfigView(cmd *cobra.Command, _ []string) error {
|
||||||
if viper.ConfigFileUsed() == "" {
|
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_:")
|
fmt.Println("\nActive env vars starting with MOLECULE_ or MOL_:")
|
||||||
for _, env := range os.Environ() {
|
for _, env := range os.Environ() {
|
||||||
if strings.HasPrefix(env, "MOLECULE_") || strings.HasPrefix(env, "MOL_") {
|
if strings.HasPrefix(env, "MOLECULE_") || strings.HasPrefix(env, "MOL_") {
|
||||||
|
|||||||
@ -9,13 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// mol init — bootstrap workspace setup
|
// molecule init — bootstrap workspace setup
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
var initCmd = &cobra.Command{
|
var initCmd = &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Bootstrap workspace and scaffold a mol.yaml config file",
|
Short: "Bootstrap workspace and scaffold a molecule.yaml config file",
|
||||||
Long: `Scaffold a default mol.yaml in the current directory.
|
Long: `Scaffold a default molecule.yaml in the current directory.
|
||||||
|
|
||||||
This is the primary entry point for new users. Run once in a project
|
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.
|
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
|
All values can be overridden by environment variables
|
||||||
(MOLECULE_API_URL, MOLECULE_RUNTIME_URL, etc.).
|
(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,
|
RunE: runInit,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInit(cmd *cobra.Command, _ []string) error {
|
func runInit(cmd *cobra.Command, _ []string) error {
|
||||||
cfgPath := "mol.yaml"
|
cfgPath := "molecule.yaml"
|
||||||
|
|
||||||
if _, err := os.Stat(cfgPath); err == nil {
|
if _, err := os.Stat(cfgPath); err == nil {
|
||||||
return fmt.Errorf("init: %s already exists — not overwriting (use --force to replace)", cfgPath)
|
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:
|
# All values can be overridden by environment variables:
|
||||||
# MOLECULE_API_URL, MOLECULE_RUNTIME_URL, MOL_OUTPUT, MOL_VERBOSE, etc.
|
# 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.Printf("Scaffolded %s\n", absPath)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Next steps:")
|
fmt.Println("Next steps:")
|
||||||
fmt.Println(" 1. Edit mol.yaml with your platform URL")
|
fmt.Println(" 1. Edit molecule.yaml with your platform URL")
|
||||||
fmt.Println(" 2. Run mol --config mol.yaml workspace list")
|
fmt.Println(" 2. Run molecule --config molecule.yaml workspace list")
|
||||||
fmt.Println(" 3. For full reference: mol --help")
|
fmt.Println(" 3. For full reference: molecule --help")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "table",
|
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "table",
|
||||||
"Output format: table | json | yaml")
|
"Output format: table | json | yaml")
|
||||||
rootCmd.PersistentFlags().StringVar(&configPath, "config", "",
|
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 {
|
rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||||
return &exitError{code: 2, msg: err.Error()}
|
return &exitError{code: 2, msg: err.Error()}
|
||||||
})
|
})
|
||||||
@ -63,7 +63,7 @@ func Execute() error {
|
|||||||
if configPath != "" {
|
if configPath != "" {
|
||||||
viper.SetConfigFile(configPath)
|
viper.SetConfigFile(configPath)
|
||||||
} else {
|
} else {
|
||||||
viper.SetConfigName("mol")
|
viper.SetConfigName("molecule")
|
||||||
viper.AddConfigPath("$HOME/.config")
|
viper.AddConfigPath("$HOME/.config")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
}
|
}
|
||||||
@ -123,5 +123,5 @@ func kv(w *tabwriter.Writer, k, v string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func versionInfo() string {
|
func versionInfo() string {
|
||||||
return fmt.Sprintf("mol %s (go %s)", Version, runtime.Version())
|
return fmt.Sprintf("molecule %s (go %s)", Version, runtime.Version())
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user