feat: implement core CLI packages and Phase 3 commands

- config: resolve binary dir, load/save .hf-config.json
- mode: detect padded-cell vs manual mode via pass_mgr
- client: HTTP client wrapper with auth header support
- passmgr: pass_mgr integration (get-secret, set, generate)
- output: human-readable + JSON output formatting with tables
- help: help and help-brief renderer for groups/commands
- commands: version, health, config (--url, --acc-mgr-token, show)
- auth: token resolution helper (padded-cell auto / manual explicit)
- main: command dispatcher with --json global flag support
- README: updated with current package layout and status
This commit is contained in:
zhi
2026-03-21 13:50:29 +00:00
parent cb0b7669b3
commit 7d3cff7d95
24 changed files with 810 additions and 52 deletions

View File

@@ -3,22 +3,107 @@ package main
import (
"fmt"
"os"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/commands"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/help"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/mode"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output"
)
func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "--help", "-h":
fmt.Println("hf - HarborForge CLI")
fmt.Println()
fmt.Println("This is the initial Go scaffold for the HarborForge CLI.")
fmt.Println("More command groups will be added in follow-up tasks.")
return
case "version":
fmt.Println("hf dev")
return
}
args := os.Args[1:]
// Parse global flags first
args = parseGlobalFlags(args)
if len(args) == 0 {
fmt.Print(help.RenderTopHelp(commands.Version, topGroups()))
return
}
fmt.Println("hf - HarborForge CLI scaffold")
switch args[0] {
case "--help", "-h":
fmt.Print(help.RenderTopHelp(commands.Version, topGroups()))
case "--help-brief":
fmt.Print(help.RenderTopHelpBrief(commands.Version, topGroups()))
case "version":
commands.RunVersion()
case "health":
commands.RunHealth()
case "config":
runConfig(args[1:])
default:
fmt.Fprintf(os.Stderr, "unknown command: %s\n", args[0])
fmt.Fprintf(os.Stderr, "Run 'hf --help' for usage.\n")
os.Exit(1)
}
}
// parseGlobalFlags extracts --json from anywhere in the args and returns remaining args.
func parseGlobalFlags(args []string) []string {
var remaining []string
for _, a := range args {
switch a {
case "--json":
output.JSONMode = true
default:
remaining = append(remaining, a)
}
}
return remaining
}
func runConfig(args []string) {
if len(args) == 0 {
commands.RunConfigShow()
return
}
for i := 0; i < len(args); i++ {
switch args[i] {
case "--url":
if i+1 >= len(args) {
output.Error("usage: hf config --url <hf-url>")
}
commands.RunConfigURL(args[i+1])
return
case "--acc-mgr-token":
if i+1 >= len(args) {
output.Error("usage: hf config --acc-mgr-token <token>")
}
commands.RunConfigAccMgrToken(args[i+1])
return
case "--help", "-h":
fmt.Println("hf config - View and manage CLI configuration")
fmt.Println()
fmt.Println("Usage:")
fmt.Println(" hf config Show current config")
fmt.Println(" hf config --url <hf-url> Set HarborForge API URL")
if !mode.IsPaddedCell() {
fmt.Println(" hf config --acc-mgr-token <token> Set account-manager token")
}
return
default:
output.Errorf("unknown config flag: %s", args[i])
}
}
}
// topGroups returns the full command tree for help rendering.
// TODO: permission awareness will be added when auth introspection is available.
func topGroups() []help.Group {
return []help.Group{
{Name: "version", Description: "Show CLI version", Permitted: true},
{Name: "health", Description: "Check API health", Permitted: true},
{Name: "config", Description: "View and manage CLI configuration", Permitted: true},
{Name: "user", Description: "Manage users", Permitted: true},
{Name: "role", Description: "Manage roles and permissions", Permitted: true},
{Name: "permission", Description: "List permissions", Permitted: true},
{Name: "project", Description: "Manage projects", Permitted: true},
{Name: "milestone", Description: "Manage milestones", Permitted: true},
{Name: "task", Description: "Manage tasks", Permitted: true},
{Name: "meeting", Description: "Manage meetings", Permitted: true},
{Name: "support", Description: "Manage support tickets", Permitted: true},
{Name: "propose", Description: "Manage proposals", Permitted: true},
{Name: "monitor", Description: "Monitor servers and API keys", Permitted: true},
}
}