Skip to content

Refactor CLI to use urfave/cli v2#212

Merged
amitsaha merged 1 commit intoamitsaha:masterfrom
rdowavic:feat/urfave-cli-refactor
Feb 27, 2026
Merged

Refactor CLI to use urfave/cli v2#212
amitsaha merged 1 commit intoamitsaha:masterfrom
rdowavic:feat/urfave-cli-refactor

Conversation

@rdowavic
Copy link
Contributor

@rdowavic rdowavic commented Feb 27, 2026

Summary

  • Replace flag.NewFlagSet + manual os.Args[1] dispatch with a urfave/cli/v2 cli.App definition
  • Proper subcommand routing for init and validate with structured help output
  • Config file precedence preserved using cCtx.IsSet() as a direct replacement for fs.Visit()
  • Business logic files untouched — only the CLI layer changes

Test plan

  • go test ./... passes
  • ./gitbackup -h shows structured help with COMMANDS and GLOBAL OPTIONS sections
  • ./gitbackup init --help and ./gitbackup validate --help show subcommand help
  • Backup with config file works: ./gitbackup -config gitbackup.yml -backupdir /tmp/test
  • CLI flag override works: ./gitbackup -config gitbackup.yml -service github -backupdir /tmp/test
  • Single-dash flags still accepted (urfave/cli accepts both -flag and --flag)

Replace flag.NewFlagSet + manual os.Args dispatch with a cli.App
definition. This gives proper subcommand routing for init/validate,
structured help output, and a clean foundation for future CLI expansion.

- options.go: replace initConfig() with appFlags() + buildConfig(cCtx),
  using cCtx.IsSet() for config-file-then-CLI-flag precedence
- main.go: define cli.App with Commands for init/validate and Action
  for the backup flow
- config_file_test.go: add buildTestConfig() helper using urfave/cli
- cli_test.go: read help from stdout (urfave/cli writes help to stdout)
- Regenerate golden files for new help format
@amitsaha amitsaha merged commit feee6b7 into amitsaha:master Feb 27, 2026
6 checks passed
@amitsaha
Copy link
Owner

🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants