Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ func NewRootCmd() *cobra.Command {
}
return fmt.Errorf("base_url (%s): %w\nFix with: basecamp config unset base_url", source, err)
}
if profileName != "" {
// Re-validate: profile may have changed base_url
if err := hostutil.RequireSecureURL(cfg.BaseURL); err != nil {
return fmt.Errorf("base_url (from profile %q): %w\nFix with: basecamp config unset base_url", profileName, err)
}
}
}

// Resolve behavior preferences: explicit flag > config > version.IsDev()
Expand Down Expand Up @@ -377,8 +371,6 @@ func promptForProfile(cfg *config.Config) (string, error) {
return selected.ID, nil
}

// transformCobraError transforms Cobra's default error messages to match the
// Bash CLI format for consistency with existing tests and user expectations.
// isConfigCmd returns true if cmd is "config" or any of its subcommands.
// Used to skip HTTPS enforcement so users can repair a bad base_url.
func isConfigCmd(cmd *cobra.Command) bool {
Expand All @@ -390,6 +382,8 @@ func isConfigCmd(cmd *cobra.Command) bool {
return false
}

// transformCobraError transforms Cobra's default error messages to match the
// Bash CLI format for consistency with existing tests and user expectations.
func transformCobraError(err error) error {
msg := err.Error()

Expand Down
20 changes: 18 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,15 @@ func repoConfigPath() string {
// Walk up to find .git directory, then look for .basecamp/config.json.
// Bounded by $HOME: only search within the home directory tree.
// If CWD is outside $HOME (e.g., /tmp), no repo config is trusted.
dir, _ := os.Getwd()
dir, err := os.Getwd()
if err != nil {
return "" // fail closed: can't determine CWD
}
resolved, err := filepath.EvalSymlinks(dir)
if err != nil {
return "" // fail closed: can't resolve symlinks for trust boundary
}
dir = resolved
home, _ := os.UserHomeDir()
if resolved, err := filepath.EvalSymlinks(home); err == nil {
home = resolved
Expand Down Expand Up @@ -466,7 +474,15 @@ func isInsideDir(child, parent string) bool {
// - Inside a git repo: only paths at or below the repo root
// - Outside a git repo: only the current working directory (no parent traversal)
func localConfigPaths(repoConfigPath string) []string {
dir, _ := os.Getwd()
dir, err := os.Getwd()
if err != nil {
return nil // fail closed: can't determine CWD
}
resolved, err := filepath.EvalSymlinks(dir)
if err != nil {
return nil // fail closed: can't resolve symlinks for trust boundary
}
dir = resolved
var paths []string

// Determine trust boundary (resolve symlinks for reliable comparison
Expand Down
Loading