feat(envc): improve root help and add stdin hang repro script
Root usage documents commands; help/-h/--help and unknown-command paths print the same text. test_hang.sh reproduces blocking reads on stdin. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+25
-2
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -13,15 +14,36 @@ var (
|
||||
date = "unknown"
|
||||
)
|
||||
|
||||
// printUsage writes the root help text to w.
|
||||
func printUsage(w io.Writer) {
|
||||
_, _ = io.WriteString(w, `envc — convert, query, and merge configuration across env, YAML, JSON, and INI.
|
||||
|
||||
Usage:
|
||||
envc <command> [arguments]
|
||||
|
||||
Commands:
|
||||
convert Read one source, normalize keys, write another format (--from, --to)
|
||||
get Read one source and print the value at a dot path (--from, --path)
|
||||
merge Deep-merge multiple sources in order, then write one output (--from, --to)
|
||||
version Print version and build metadata (also -v, --version)
|
||||
|
||||
Each command accepts its own flags; run:
|
||||
envc <command> -h
|
||||
`)
|
||||
}
|
||||
|
||||
func main() {
|
||||
stdin, stdout, stderr := os.Stdin, os.Stdout, os.Stderr
|
||||
args := os.Args[1:]
|
||||
if len(args) < 1 {
|
||||
_, _ = fmt.Fprintln(stderr, "usage: envc <convert|get|merge|version> [flags]")
|
||||
printUsage(stderr)
|
||||
os.Exit(2)
|
||||
}
|
||||
var code int
|
||||
switch args[0] {
|
||||
case "help", "-h", "--help":
|
||||
printUsage(stdout)
|
||||
code = 0
|
||||
case "convert":
|
||||
code = RunConvert(args[1:], stdin, stdout, stderr)
|
||||
case "get":
|
||||
@@ -31,7 +53,8 @@ func main() {
|
||||
case "version", "--version", "-v":
|
||||
_, _ = fmt.Fprintf(stdout, "envc %s (commit %s, built %s)\n", version, commit, date)
|
||||
default:
|
||||
_, _ = fmt.Fprintf(stderr, "unknown command %q\n", args[0])
|
||||
_, _ = fmt.Fprintf(stderr, "unknown command %q\n\n", args[0])
|
||||
printUsage(stderr)
|
||||
code = 2
|
||||
}
|
||||
os.Exit(code)
|
||||
|
||||
Reference in New Issue
Block a user