Files
oh-my-posh/src/cli/auth.go
T
ClaudeandJan De Dobbeleer 2a59ed1e50 refactor(cli): replace cobra and pflag with minimal internal packages
The CLI framework was the largest remaining third-party chunk (545 kB)
and most of its surface went unused - completions are explicitly
disabled, templates and command groups never used. Replace both with
internal packages mirroring the exact API subset in use: a command tree
with persistent flags and nearest-hook semantics, POSIX flag parsing
(--flag=value, --flag value, shorthands and grouping, the -- terminator,
interspersed positionals, unknown-flag allowlisting for the argocd
segment), positional validators, the implicit help command, and the
Windows Explorer double-click guard.

Help, usage and error output were verified byte-identical against the
previous binary across a 47-case golden battery: every command and
subcommand help screen, error formats and exit codes, flag styles
including flags before the subcommand, and init/print rendering.

Shrinks the stripped linux/amd64 binary by 586 kB (13.50 MB -> 12.91 MB;
23.7% below the original 16.93 MB).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qiyvpiy5jR2tyzwZ3zUki5
2026-07-31 07:40:24 +02:00

69 lines
1.3 KiB
Go

package cli
import (
"os"
"github.com/jandedobbeleer/oh-my-posh/src/cache"
"github.com/jandedobbeleer/oh-my-posh/src/cli/auth/tui"
"github.com/jandedobbeleer/oh-my-posh/src/log"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/cmdtree"
)
var authCmd = &cmdtree.Command{
Use: "auth [service]",
Short: "Authenticate against a service",
Long: `Authenticate against a service.
Available services:
- copilot: GitHub Copilot API
- ytmda: YouTube Music Desktop App (YTMDA) API`,
ValidArgs: []string{
copilotServiceName,
"ytmda",
},
Args: NoArgsOrOneValidArg,
Run: func(cmd *cmdtree.Command, args []string) {
if len(args) == 0 {
_ = cmd.Help()
return
}
flags := &runtime.Flags{
Shell: os.Getenv("POSH_SHELL"),
}
env := &runtime.Terminal{}
env.Init(flags)
cache.Init(env.Shell(), cache.Persist)
defer func() {
cache.Close()
}()
switch args[0] {
case copilotServiceName:
authenticator := tui.NewCopilot(env)
if err := tui.Run(authenticator); err != nil {
log.Error(err)
exitcode = 70
}
case "ytmda":
authenticator := tui.NewYtmda(env)
if err := tui.Run(authenticator); err != nil {
log.Error(err)
exitcode = 70
}
default:
_ = cmd.Help()
}
},
}
func init() {
RootCmd.AddCommand(authCmd)
}