fix(publisher): add --help support for subcommands (#867)
## Summary - Added `printCommandHelp()` function to display help for each subcommand - `mcp-publisher init --help` now shows init command help instead of running init - `mcp-publisher login --help` now shows login methods instead of error - `mcp-publisher publish --help` now shows publish usage instead of attempting publish Fixes #735 Signed-off-by: majiayu000 <1835304752@qq.com> Co-authored-by: Radoslav Dimitrov <radoslav@stacklok.com>
This commit is contained in:
parent
ab6a5a6b6d
commit
61fdf17b21
1 changed files with 62 additions and 0 deletions
|
|
@ -27,6 +27,12 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for help flag for subcommands
|
||||||
|
if len(os.Args) >= 3 && (os.Args[2] == "--help" || os.Args[2] == "-h") {
|
||||||
|
printCommandHelp(os.Args[1])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "init":
|
case "init":
|
||||||
|
|
@ -68,3 +74,59 @@ func printUsage() {
|
||||||
_, _ = fmt.Fprintln(os.Stdout)
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
_, _ = fmt.Fprintln(os.Stdout, "Use 'mcp-publisher <command> --help' for more information about a command.")
|
_, _ = fmt.Fprintln(os.Stdout, "Use 'mcp-publisher <command> --help' for more information about a command.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printCommandHelp(command string) {
|
||||||
|
switch command {
|
||||||
|
case "init":
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Create a server.json file template")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Usage:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher init")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "This command creates a server.json file in the current directory with")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "auto-detected values from your project (package.json, git remote, etc.).")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "After running init, edit the generated server.json to customize your")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "server's metadata before publishing.")
|
||||||
|
|
||||||
|
case "login":
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Authenticate with the registry")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Usage:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher login <method> [options]")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Methods:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " github Interactive GitHub authentication")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " github-oidc GitHub Actions OIDC authentication")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " dns DNS-based authentication (requires --domain)")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " http HTTP-based authentication (requires --domain)")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " none Anonymous authentication (for testing)")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Examples:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher login github")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher login dns --domain example.com --private-key <key>")
|
||||||
|
|
||||||
|
case "logout":
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Clear saved authentication")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Usage:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher logout")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "This command removes the saved authentication token from your system.")
|
||||||
|
|
||||||
|
case "publish":
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Publish server.json to the registry")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Usage:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " mcp-publisher publish [server.json]")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "Arguments:")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, " server.json Path to the server.json file (default: ./server.json)")
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout)
|
||||||
|
_, _ = fmt.Fprintln(os.Stdout, "You must be logged in before publishing. Run 'mcp-publisher login' first.")
|
||||||
|
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", command)
|
||||||
|
printUsage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue