package cmd import ( "os" "path/filepath" ) // invocationNameOverride lets tests fix the binary name surfaced in // user-facing hint and refusal messages. Production code leaves it empty // so the live os.Args[0] basename is used. // // Tests that assert on specific hint substrings (e.g. "ctask attach // ") must set this to "ctask" via t.Cleanup; otherwise the test // binary's name (e.g. "cmd.test") will surface in the hint and the // substring will not match. Do not run such tests in t.Parallel — this // is a package global. var invocationNameOverride string // invocationName returns the binary name to render in user-facing // command suggestions (" new --direct", // " attach ", etc.). It returns the basename of os.Args[0] // so the hint reads cleanly regardless of invocation form: `./ctask`, // `.\ctask.exe`, `/usr/local/bin/ctask`, and an installed `ctask` on // PATH all surface as `ctask` (or `ctask.exe` on Windows). The slight // loss of paste-ability for explicit-path invocations (the user has to // re-prepend their `./` or `.\`) is the trade for a clean, predictable // hint that matches the canonical install case. // // Falls back to "ctask" when argv is empty (a degenerate state — should // not happen in normal execution, but defensive against odd embeddings). func invocationName() string { if invocationNameOverride != "" { return invocationNameOverride } if len(os.Args) == 0 || os.Args[0] == "" { return "ctask" } return filepath.Base(os.Args[0]) }