From b852beb2ac3a6bfe1cc42ad576668d7bfc8e9050 Mon Sep 17 00:00:00 2001 From: J23 Date: Thu, 26 Dec 2024 19:50:50 +0800 Subject: [PATCH] cmd: merge kong-upstream and improve short-only --- cmd/zeta-mc/migrate.go | 2 +- command_test.go | 131 ++++++++++++++++++++++++++++ modules/strengthen/os_windows.go | 2 +- pkg/command/command.go | 4 +- pkg/command/command_branch.go | 8 +- pkg/command/command_cat.go | 22 ++--- pkg/command/command_check_ignore.go | 2 +- pkg/command/command_checkout.go | 48 +++++----- pkg/command/command_clean.go | 4 +- pkg/command/command_commit.go | 4 +- pkg/command/command_config.go | 4 +- pkg/command/command_diff.go | 6 +- pkg/command/command_for_each_ref.go | 2 +- pkg/command/command_hash_object.go | 4 +- pkg/command/command_init.go | 4 +- pkg/command/command_ls_files.go | 2 +- pkg/command/command_ls_tree.go | 10 +-- pkg/command/command_merge.go | 16 ++-- pkg/command/command_merge_base.go | 14 +-- pkg/command/command_merge_file.go | 4 +- pkg/command/command_merge_tree.go | 4 +- pkg/command/command_push.go | 2 +- pkg/command/command_rebase.go | 2 +- pkg/command/command_restore.go | 2 +- pkg/command/command_rm.go | 2 +- pkg/command/command_show.go | 2 +- pkg/command/command_status.go | 2 +- pkg/command/command_switch.go | 16 ++-- pkg/command/command_tag.go | 6 +- pkg/kong/build.go | 36 +++++--- pkg/kong/callbacks.go | 63 ++++++------- pkg/kong/context.go | 84 ++++++++++++------ pkg/kong/global.go | 10 +++ pkg/kong/guesswidth.go | 2 +- pkg/kong/guesswidth_unix.go | 4 +- pkg/kong/help.go | 70 ++++++--------- pkg/kong/hook.go | 11 --- pkg/kong/hooks.go | 18 ++++ pkg/kong/kong.go | 51 +++++++++-- pkg/kong/mapper.go | 39 +++++---- pkg/kong/model.go | 52 +++++------ pkg/kong/negatable.go | 19 ++++ pkg/kong/options.go | 10 ++- pkg/kong/resolver.go | 4 +- pkg/kong/scanner.go | 2 +- pkg/kong/tag.go | 101 +++++++++++++-------- pkg/kong/util.go | 2 +- pkg/serve/encrypt.go | 2 +- pkg/tr/languages/zh-CN.toml | 1 + 49 files changed, 582 insertions(+), 330 deletions(-) create mode 100644 command_test.go delete mode 100644 pkg/kong/hook.go create mode 100644 pkg/kong/negatable.go diff --git a/cmd/zeta-mc/migrate.go b/cmd/zeta-mc/migrate.go index 6aa4ac0..57ced0d 100644 --- a/cmd/zeta-mc/migrate.go +++ b/cmd/zeta-mc/migrate.go @@ -22,7 +22,7 @@ type App struct { Globals From string `arg:"" name:"from" help:"Original repository remote URL (or filesystem path)" type:"string"` Destination string `arg:"" optional:"" name:"destination" help:"Destination where the repository is migrated" type:"path"` - Values []string `short:"X" name:":config" help:"Override default configuration, format: ="` + Values []string `short:"X" shortonly:"" help:"Override default configuration, format: ="` Squeeze bool `name:"squeeze" short:"s" help:"Squeeze mode, compressed metadata"` LFS bool `name:"lfs" help:"Migrate all LFS objects to zeta"` Quiet bool `name:"quiet" help:"Operate quietly. Progress is not reported to the standard error stream"` diff --git a/command_test.go b/command_test.go new file mode 100644 index 0000000..5965645 --- /dev/null +++ b/command_test.go @@ -0,0 +1,131 @@ +package cli + +import ( + "fmt" + "os" + "testing" + + "github.com/antgroup/hugescm/pkg/kong" + "github.com/antgroup/hugescm/pkg/tr" + "github.com/antgroup/hugescm/pkg/version" +) + +type Checkout struct { + UnresolvedArgs []string `arg:"" optional:""` + Branch string `name:"branch" short:"b" help:"Direct the new HEAD to the branch after checkout"` + TagName string `name:"tag" short:"t" help:"Direct the new HEAD to the tag's commit after checkout"` + Commit string `name:"commit" help:"Direct the new HEAD to the branch after checkout"` + Sparse []string `name:"sparse" short:"s" help:"A subset of repository files, all files are checked out by default" type:"string"` + Limit int64 `name:"limit" short:"L" help:"Omits blobs larger than n bytes or units. n may be zero. supported units: KB,MB,GB,K,M,G" default:"-1" type:"size"` + Batch bool `name:"batch" help:"Get and checkout files for each provided on stdin"` + Snapshot bool `name:"snapshot" help:"Checkout a non-editable snapshot"` + Depth int `name:"depth" help:"Create a shallow clone with a history truncated to the specified number of commits" default:"1"` + One bool `name:"one" help:"Checkout large files one after another"` + Quiet bool `name:"quiet" help:"Operate quietly. Progress is not reported to the standard error stream"` + passthroughArgs []string `kong:"-"` +} + +func (c *Checkout) Passthrough(paths []string) { + c.passthroughArgs = append(c.passthroughArgs, paths...) +} + +func (c *Checkout) Run() error { + fmt.Fprintf(os.Stderr, "unresolvedArgs: %v passthroughArgs: %v\n", c.UnresolvedArgs, c.passthroughArgs) + return nil +} + +type Diff struct { + NoIndex bool `name:"no-index" help:"Compares two given paths on the filesystem"` + NameOnly bool `name:"name-only" help:"Show only names of changed files"` + NameStatus bool `name:"name-status" help:"Show names and status of changed files"` + Numstat bool `name:"numstat" help:"Show numeric diffstat instead of patch"` + Stat bool `name:"stat" help:"Show diffstat instead of patch"` + Shortstat bool `name:"shortstat" help:"Output only the last line of --stat format"` + Z bool `short:"z" shortonly:"" help:"Output diff-raw with lines terminated with NUL"` + Staged bool `name:"staged" help:"Compare the differences between the staging area and "` + Cached bool `name:"cached" help:"Compare the differences between the staging area and "` + Textconv bool `name:"textconv" help:"Converting text to Unicode"` + MergeBase string `name:"merge-base" help:"If --merge-base is given, use the common ancestor of and HEAD instead"` + Histogram bool `name:"histogram" help:"Generate a diff using the \"Histogram diff\" algorithm"` + ONP bool `name:"onp" help:"Generate a diff using the \"O(NP) diff\" algorithm"` + Myers bool `name:"myers" help:"Generate a diff using the \"Myers diff\" algorithm"` + Patience bool `name:"patience" help:"Generate a diff using the \"Patience diff\" algorithm"` + Minimal bool `name:"minimal" help:"Spend extra time to make sure the smallest possible diff is produced"` + DiffAlgorithm string `name:"diff-algorithm" help:"Choose a diff algorithm, supported: histogram|onp|myers|patience|minimal" placeholder:""` + Output string `name:"output" help:"Output to a specific file instead of stdout" placeholder:""` + From string `arg:"" optional:"" name:"from" help:""` + To string `arg:"" optional:"" name:"to" help:""` + passthroughArgs []string `kong:"-"` +} + +func (c *Diff) Passthrough(paths []string) { + c.passthroughArgs = append(c.passthroughArgs, paths...) +} + +func (c *Diff) Run() error { + fmt.Fprintf(os.Stderr, "from %s to %s args: %v\n", c.From, c.To, c.passthroughArgs) + return nil +} + +type App struct { + Checkout Checkout `cmd:"" name:"co" help:"checkout"` + Diff Diff `cmd:"" name:"diff" help:"diff"` +} + +func TestCheckout(t *testing.T) { + parseArgs := func(args []string) { + var app App + ctx := kong.ParseArgs(&app, args, + kong.Name("zeta"), + kong.Description(tr.W("HugeSCM - A next generation cloud-based version control system")), + kong.UsageOnError(), + kong.ConfigureHelp(kong.HelpOptions{ + Compact: true, + NoExpandSubcommands: true, + }), + kong.Vars{ + "version": version.GetVersionString(), + }, + ) + if err := ctx.Run(); err != nil { + return + } + } + argss := [][]string{ + {"co", "--", "a.txt", "b.txt"}, + {"co", "master", "--", "a.txt", "b.txt"}, + {"co", ".", "--", "a.txt", "b.txt"}, + {"co", ".", "--", "a.txt", "b.txt", "--"}, + } + for _, args := range argss { + parseArgs(args) + } +} + +func TestDiff(t *testing.T) { + parseArgs := func(args []string) { + var app App + ctx := kong.ParseArgs(&app, args, + kong.Name("zeta"), + kong.Description(tr.W("HugeSCM - A next generation cloud-based version control system")), + kong.UsageOnError(), + kong.ConfigureHelp(kong.HelpOptions{ + Compact: true, + NoExpandSubcommands: true, + }), + kong.Vars{ + "version": version.GetVersionString(), + }, + ) + if err := ctx.Run(); err != nil { + return + } + } + argss := [][]string{ + {"diff", "--", "a.txt", "b.txt"}, + {"diff", "master", "--", "a.txt", "b.txt"}, + } + for _, args := range argss { + parseArgs(args) + } +} diff --git a/modules/strengthen/os_windows.go b/modules/strengthen/os_windows.go index 9e15caa..79d8157 100644 --- a/modules/strengthen/os_windows.go +++ b/modules/strengthen/os_windows.go @@ -71,7 +71,7 @@ const ( ) var pool = sync.Pool{ - New: func() interface{} { + New: func() any { // Size of buffer chosen somewhat arbitrarily to accommodate a large number of path strings. // MAX_PATH (260) + size of volume GUID prefix (49) + null terminator = 310. b := make([]uint16, 310) diff --git a/pkg/command/command.go b/pkg/command/command.go index 3cb67cb..46bffde 100644 --- a/pkg/command/command.go +++ b/pkg/command/command.go @@ -17,8 +17,8 @@ import ( type Globals struct { Verbose bool `short:"V" name:"verbose" help:"Make the operation more talkative"` Version VersionFlag `short:"v" name:"version" help:"Show version number and quit"` - Values []string `short:"X" name:":config" help:"Override default configuration, format: ="` - CWD string `name:"cwd" help:"Set the path to the repository worktree"` + Values []string `short:"X" shortonly:"" help:"Override default configuration, format: ="` + CWD string `name:"cwd" help:"Set the path to the repository worktree" placeholder:""` } func (g *Globals) DbgPrint(format string, args ...any) { diff --git a/pkg/command/command_branch.go b/pkg/command/command_branch.go index ddbe80a..01b351b 100644 --- a/pkg/command/command_branch.go +++ b/pkg/command/command_branch.go @@ -15,13 +15,13 @@ type Branch struct { ShowCurrent bool `name:"show-current" help:"Show current branch name"` List bool `name:"list" short:"l" help:"List branches. With optional ..."` Copy bool `name:"copy" short:"c" help:"Copy a branch and its reflog"` - ForceCopy bool `name:":force-copy" short:"C" help:"Copy a branch, even if target exists"` + ForceCopy bool `short:"C" shortonly:"" help:"Copy a branch, even if target exists"` Delete bool `name:"delete" short:"d" help:"Delete fully merged branch"` - ForceDelete bool `name:":force-delete" short:"D" help:"Delete branch (even if not merged)"` + ForceDelete bool `short:"D" shortonly:"" help:"Delete branch (even if not merged)"` Move bool `name:"move" short:"m" help:"Move/rename a branch and its reflog"` - ForceMove bool `name:":force-move" short:"M" help:"Move/rename a branch, even if target exists"` + ForceMove bool `short:"M" shortonly:"" help:"Move/rename a branch, even if target exists"` Force bool `name:"force" short:"f" help:"Force creation, move/rename, deletion"` - Args []string `arg:"" optional:"" name:"args" help:"Branch args: , , "` + Args []string `arg:"" optional:"" name:"args" help:""` } const ( diff --git a/pkg/command/command_cat.go b/pkg/command/command_cat.go index 7aef2d5..453df1d 100644 --- a/pkg/command/command_cat.go +++ b/pkg/command/command_cat.go @@ -10,15 +10,15 @@ import ( ) type Cat struct { - Object string `arg:"" name:"object" help:"The name of the object to show"` - T bool `name:"type" short:"t" help:"Show object type"` - DisplaySize bool `name:":" short:"s" help:"Show object size"` - JSON bool `name:"json" short:"j" help:"Returns data as JSON; limited to commits, trees, fragments, and tags"` - Textconv bool `name:"textconv" help:"Converting text to Unicode"` - Direct bool `name:"direct" help:"View files directly"` - Verify bool `name:"verify" help:"Verify object hash"` - Limit int64 `name:"limit" short:"L" help:"Omits blobs larger than n bytes or units. n may be zero. supported units: KB,MB,GB,K,M,G" default:"-1" type:"size"` - Output string `name:"output" help:"Output to a specific file instead of stdout" placeholder:""` + Object string `arg:"" name:"object" help:"The name of the object to show"` + Type bool `name:"type" short:"t" help:"Show object type"` + Size bool `name:"size" short:"s" help:"Show object size"` + Verify bool `name:"verify" help:"Verify object hash"` + Textconv bool `name:"textconv" help:"Converting text to Unicode"` + JSON bool `name:"json" short:"j" help:"Returns data as JSON; limited to commits, trees, fragments, and tags"` + Direct bool `name:"direct" help:"View files directly"` + Limit int64 `name:"limit" short:"L" help:"Omits blobs larger than n bytes or units. n may be zero. supported units: KB,MB,GB,K,M,G" default:"-1" type:"size"` + Output string `name:"output" help:"Output to a specific file instead of stdout" placeholder:""` } func (c *Cat) Run(g *Globals) error { @@ -34,8 +34,8 @@ func (c *Cat) Run(g *Globals) error { return r.Cat(context.Background(), &zeta.CatOptions{ Object: c.Object, Limit: c.Limit, - Type: c.T, - PrintSize: c.DisplaySize, + Type: c.Type, + PrintSize: c.Size, Textconv: c.Textconv, Direct: c.Direct, PrintJSON: c.JSON, diff --git a/pkg/command/command_check_ignore.go b/pkg/command/command_check_ignore.go index 3272985..6682222 100644 --- a/pkg/command/command_check_ignore.go +++ b/pkg/command/command_check_ignore.go @@ -15,7 +15,7 @@ import ( type CheckIgnore struct { Stdin bool `name:"stdin" help:"Read file names from stdin"` - Z bool `name:":z" short:"z" help:"Terminate input and output records by a NUL character"` + Z bool `short:"z" shortonly:"" help:"Terminate input and output records by a NUL character"` JSON bool `name:"json" short:"j" help:"Data will be returned in JSON format"` Paths []string `arg:"" name:"pathname" optional:"" help:"Pathname given via the command-line"` } diff --git a/pkg/command/command_checkout.go b/pkg/command/command_checkout.go index 002b026..9c88d07 100644 --- a/pkg/command/command_checkout.go +++ b/pkg/command/command_checkout.go @@ -13,20 +13,12 @@ import ( "github.com/antgroup/hugescm/pkg/zeta" ) -const ( - coSummaryFormat = `%szeta checkout (co) [--branch|--tag] [--commit] [--sparse] [--limit] [] -%szeta checkout (co) -%szeta checkout (co) [] -- ... -%szeta checkout (co) --batch [] -%szeta checkout (co) []` -) - type Checkout struct { - UnresolvedArgs []string `arg:"" optional:"" hidden:""` - Branch string `name:"branch" short:"b" help:"Direct the new HEAD to the branch after checkout"` - TagName string `name:"tag" short:"t" help:"Direct the new HEAD to the tag's commit after checkout"` - Commit string `name:"commit" help:"Direct the new HEAD to the branch after checkout"` - Sparse []string `name:"sparse" short:"s" help:"A subset of repository files, all files are checked out by default" type:"string"` + Args []string `arg:"" optional:""` + Branch string `name:"branch" short:"b" help:"Direct the new HEAD to the branch after checkout" placeholder:""` + TagName string `name:"tag" short:"t" help:"Direct the new HEAD to the tag's commit after checkout" placeholder:""` + Commit string `name:"commit" help:"Direct the new HEAD to the branch after checkout" placeholder:""` + Sparse []string `name:"sparse" short:"s" help:"A subset of repository files, all files are checked out by default" placeholder:""` Limit int64 `name:"limit" short:"L" help:"Omits blobs larger than n bytes or units. n may be zero. supported units: KB,MB,GB,K,M,G" default:"-1" type:"size"` Batch bool `name:"batch" help:"Get and checkout files for each provided on stdin"` Snapshot bool `name:"snapshot" help:"Checkout a non-editable snapshot"` @@ -36,6 +28,14 @@ type Checkout struct { passthroughArgs []string `kong:"-"` } +const ( + coSummaryFormat = `%szeta checkout (co) [--branch|--tag] [--commit] [--sparse] [--limit] [] +%szeta checkout (co) +%szeta checkout (co) [] -- ... +%szeta checkout (co) --batch [] +%szeta checkout (co) []` +) + func (c *Checkout) Summary() string { or := W(" or: ") return fmt.Sprintf(coSummaryFormat, W("Usage: "), or, or, or, or) @@ -82,15 +82,15 @@ func (c *Checkout) doRemote(g *Globals, remote, destination string) error { } func (c *Checkout) destination() string { - if len(c.UnresolvedArgs) >= 2 { - return c.UnresolvedArgs[1] + if len(c.Args) >= 2 { + return c.Args[1] } return "" } func (c *Checkout) revision() string { - if len(c.UnresolvedArgs) != 0 { - return c.UnresolvedArgs[0] + if len(c.Args) != 0 { + return c.Args[0] } return "HEAD" } @@ -127,9 +127,9 @@ func (c *Checkout) runCompatibleCheckout0(g *Globals, r *zeta.Repository, worktr } func (c *Checkout) runCompatibleCheckout(g *Globals, r *zeta.Repository) error { - pathSpec := make([]string, 0, len(c.UnresolvedArgs)) + pathSpec := make([]string, 0, len(c.Args)) // zeta checkout [] - if len(c.UnresolvedArgs) == 0 { + if len(c.Args) == 0 { pathSpec = append(pathSpec, c.passthroughArgs...) head, err := r.Current() if err != nil { @@ -138,9 +138,9 @@ func (c *Checkout) runCompatibleCheckout(g *Globals, r *zeta.Repository) error { } return c.runCompatibleCheckout0(g, r, true, head.Name(), head.Hash(), pathSpec) } - rev, refname, err := r.RevisionEx(context.Background(), c.UnresolvedArgs[0]) + rev, refname, err := r.RevisionEx(context.Background(), c.Args[0]) if zeta.IsErrUnknownRevision(err) { - pathSpec = append(pathSpec, c.UnresolvedArgs...) + pathSpec = append(pathSpec, c.Args...) pathSpec = append(pathSpec, c.passthroughArgs...) head, err := r.Current() if err != nil { @@ -155,7 +155,7 @@ func (c *Checkout) runCompatibleCheckout(g *Globals, r *zeta.Repository) error { } // zeta checkout [] g.DbgPrint("resolve revision: %s", rev) - pathSpec = append(pathSpec, c.UnresolvedArgs[1:]...) + pathSpec = append(pathSpec, c.Args[1:]...) pathSpec = append(pathSpec, c.passthroughArgs...) var worktreeOnly bool if len(pathSpec) != 0 { @@ -165,8 +165,8 @@ func (c *Checkout) runCompatibleCheckout(g *Globals, r *zeta.Repository) error { } func (c *Checkout) Run(g *Globals) error { - if len(c.UnresolvedArgs) > 0 && transport.IsRemoteEndpoint(c.UnresolvedArgs[0]) { - return c.doRemote(g, c.UnresolvedArgs[0], c.destination()) + if len(c.Args) > 0 && transport.IsRemoteEndpoint(c.Args[0]) { + return c.doRemote(g, c.Args[0], c.destination()) } r, err := zeta.Open(context.Background(), &zeta.OpenOptions{ Worktree: g.CWD, diff --git a/pkg/command/command_clean.go b/pkg/command/command_clean.go index a1c530f..4b4e58d 100644 --- a/pkg/command/command_clean.go +++ b/pkg/command/command_clean.go @@ -15,8 +15,8 @@ import ( type Clean struct { DryRun bool `name:"dry-run" short:"n" help:"dry run"` Force bool `name:"force" short:"f" help:"force"` - Dir bool `name:":dir" short:"d" help:"Remove whole directories"` - ALL bool `name:":all" short:"x" help:"Remove ignored files, too"` + Dir bool `short:"d" shortonly:"" help:"Remove whole directories"` + ALL bool `short:"x" shortonly:"" help:"Remove ignored files, too"` } func (c *Clean) Run(g *Globals) error { diff --git a/pkg/command/command_commit.go b/pkg/command/command_commit.go index 5a6bb6b..aebddef 100644 --- a/pkg/command/command_commit.go +++ b/pkg/command/command_commit.go @@ -12,8 +12,8 @@ import ( ) type Commit struct { - Message []string `name:"message" short:"m" help:"Use the given as the commit message. Concatenate multiple -m options as separate paragraphs"` - File string `name:"file" short:"F" help:"Take the commit message from the given file. Use - to read the message from the standard input"` + Message []string `name:"message" short:"m" help:"Use the given as the commit message. Concatenate multiple -m options as separate paragraphs" placeholder:""` + File string `name:"file" short:"F" help:"Take the commit message from the given file. Use - to read the message from the standard input" placeholder:""` All bool `name:"all" short:"a" help:"Automatically stage modified and deleted files, but newly untracked files remain unaffected"` AllowEmpty bool `name:"allow-empty" help:"Allow creating a commit with the exact same tree structure as its parent commit"` AllowEmptyMessage bool `name:"allow-empty-message" help:"Like --allow-empty this command is primarily for use by foreign SCM interface scripts"` diff --git a/pkg/command/command_config.go b/pkg/command/command_config.go index 3d7bd2c..03adc7b 100644 --- a/pkg/command/command_config.go +++ b/pkg/command/command_config.go @@ -22,8 +22,8 @@ type Config struct { Get bool `name:"get" help:"Get the value for a given Key"` GetALL bool `name:"get-all" help:"Get all values for a given Key"` Add bool `name:"add" help:"Add a new variable: name value"` - Z bool `name:":z" short:"z" help:"Terminate values with NUL byte"` - Type string `name:"type" short:"T" help:"zeta config will ensure that any input or output is valid under the given type constraint(s), support: bool, int, float, date"` + Z bool `short:"z" shortonly:"" help:"Terminate values with NUL byte"` + Type string `name:"type" short:"T" help:"zeta config will ensure that any input or output is valid under the given type constraint(s), support: bool, int, float, date" placeholder:""` } func (c *Config) Run(g *Globals) error { diff --git a/pkg/command/command_diff.go b/pkg/command/command_diff.go index 89897af..24165c9 100644 --- a/pkg/command/command_diff.go +++ b/pkg/command/command_diff.go @@ -23,17 +23,17 @@ type Diff struct { Numstat bool `name:"numstat" help:"Show numeric diffstat instead of patch"` Stat bool `name:"stat" help:"Show diffstat instead of patch"` Shortstat bool `name:"shortstat" help:"Output only the last line of --stat format"` - Z bool `name:":z" short:"z" help:"Output diff-raw with lines terminated with NUL"` + Z bool `short:"z" shortonly:"" help:"Output diff-raw with lines terminated with NUL"` Staged bool `name:"staged" help:"Compare the differences between the staging area and "` Cached bool `name:"cached" help:"Compare the differences between the staging area and "` Textconv bool `name:"textconv" help:"Converting text to Unicode"` - MergeBase string `name:"merge-base" help:"If --merge-base is given, use the common ancestor of and HEAD instead"` + MergeBase string `name:"merge-base" help:"If --merge-base is given, use the common ancestor of and HEAD instead" placeholder:""` Histogram bool `name:"histogram" help:"Generate a diff using the \"Histogram diff\" algorithm"` ONP bool `name:"onp" help:"Generate a diff using the \"O(NP) diff\" algorithm"` Myers bool `name:"myers" help:"Generate a diff using the \"Myers diff\" algorithm"` Patience bool `name:"patience" help:"Generate a diff using the \"Patience diff\" algorithm"` Minimal bool `name:"minimal" help:"Spend extra time to make sure the smallest possible diff is produced"` - DiffAlgorithm string `name:"diff-algorithm" help:"Choose a diff algorithm, supported: histogram|onp|myers|patience|minimal"` + DiffAlgorithm string `name:"diff-algorithm" help:"Choose a diff algorithm, supported: histogram|onp|myers|patience|minimal" placeholder:""` Output string `name:"output" help:"Output to a specific file instead of stdout" placeholder:""` From string `arg:"" optional:"" name:"from" help:""` To string `arg:"" optional:"" name:"to" help:""` diff --git a/pkg/command/command_for_each_ref.go b/pkg/command/command_for_each_ref.go index dc22771..55d8236 100644 --- a/pkg/command/command_for_each_ref.go +++ b/pkg/command/command_for_each_ref.go @@ -13,7 +13,7 @@ import ( type ForEachRef struct { JSON bool `name:"json" short:"j" help:"Data will be returned in JSON format"` - Sort string `name:"sort" help:"Field name to sort on"` + Sort string `name:"sort" help:"Field name to sort on" placeholder:""` Pattern []string `arg:"" optional:"" name:"pattern" help:"If given, only refs matching at least one pattern are shown"` } diff --git a/pkg/command/command_hash_object.go b/pkg/command/command_hash_object.go index e4bca31..a8888f7 100644 --- a/pkg/command/command_hash_object.go +++ b/pkg/command/command_hash_object.go @@ -14,9 +14,9 @@ import ( ) type HashObject struct { - W bool `name:":w" short:"w" help:"Write the object into the object database"` + W bool `short:"w" shortonly:"" help:"Write the object into the object database"` Stdin bool `name:"stdin" help:"Read the object from stdin"` - Path string `name:"path" help:"Process file as it were from this path"` + Path string `name:"path" help:"Process file as it were from this path" placeholder:""` } func (c *HashObject) Run(g *Globals) error { diff --git a/pkg/command/command_init.go b/pkg/command/command_init.go index 119b351..7fd2f9a 100644 --- a/pkg/command/command_init.go +++ b/pkg/command/command_init.go @@ -15,8 +15,8 @@ import ( ) type Init struct { - Branch string `name:"branch" short:"b" help:"Override the name of the initial branch" default:"mainline"` - Remote string `name:"remote" help:"Initialize and start tracking a new repository"` + Branch string `name:"branch" short:"b" help:"Override the name of the initial branch" default:"mainline" placeholder:""` + Remote string `name:"remote" help:"Initialize and start tracking a new repository" placeholder:""` Directory string `arg:"" name:"directory" help:"Repository directory"` } diff --git a/pkg/command/command_ls_files.go b/pkg/command/command_ls_files.go index c2165fd..07acbf9 100644 --- a/pkg/command/command_ls_files.go +++ b/pkg/command/command_ls_files.go @@ -15,7 +15,7 @@ type LsFiles struct { Modified bool `name:"modified" short:"m" help:"Show modified files in the output"` Others bool `name:"others" short:"o" help:"Show other files in the output"` Stage bool `name:"stage" short:"s" help:"Show staged contents' object name in the output"` - Z bool `name:":z" short:"z" help:"Terminate entries with NUL byte"` + Z bool `short:"z" shortonly:"" help:"Terminate entries with NUL byte"` JSON bool `name:"json" short:"j" help:"Data will be returned in JSON format"` Paths []string `arg:"" name:"path" optional:"" help:"Given paths, show as match patterns; else, use root as sole argument"` } diff --git a/pkg/command/command_ls_tree.go b/pkg/command/command_ls_tree.go index 2b48b57..fcfcd09 100644 --- a/pkg/command/command_ls_tree.go +++ b/pkg/command/command_ls_tree.go @@ -12,13 +12,13 @@ import ( ) type LsTree struct { - OnlyTrees bool `name:":only-trees" short:"d" help:"Only show trees"` - Recurse bool `name:":recurse" short:"r" help:"Recurse into subtrees"` - Tree bool `name:":tree" short:"t" help:"Show trees when recursing"` - Z bool `name:":z" short:"z" help:"Terminate entries with NUL byte"` + OnlyTrees bool `short:"d" shortonly:"" help:"Only show trees"` + Recurse bool `short:"r" shortonly:"" help:"Recurse into subtrees"` + Tree bool `short:"t" shortonly:"" help:"Show trees when recursing"` + Z bool `short:"z" shortonly:"" help:"Terminate entries with NUL byte"` Long bool `name:"long" short:"l" help:"Include object size"` NameOnly bool `name:"name-only" alias:"name-status" help:"List only filenames"` - Abbrev int `name:"abbrev" help:"Use digits to display object names"` + Abbrev int `name:"abbrev" help:"Use digits to display object names" placeholder:""` JSON bool `name:"json" short:"j" help:"Data will be returned in JSON format"` Revision string `arg:"" name:"tree-ish" help:"ID of a tree-ish"` Paths []string `arg:"" name:"path" optional:"" help:"Given paths, show as match patterns; else, use root as sole argument"` diff --git a/pkg/command/command_merge.go b/pkg/command/command_merge.go index 04389f0..8b74b52 100644 --- a/pkg/command/command_merge.go +++ b/pkg/command/command_merge.go @@ -10,12 +10,6 @@ import ( "github.com/antgroup/hugescm/pkg/zeta" ) -const ( - mergeSummaryFormat = `%szeta merge [] [] -%szeta merge --abort -%szeta merge --continue` -) - // Join two or more development histories together type Merge struct { Revision string `arg:"" optional:"" name:"revision" help:"Merge specific revision into HEAD"` @@ -24,13 +18,19 @@ type Merge struct { Squash bool `name:"squash" help:"Create a single commit instead of doing a merge"` AllowUnrelatedHistories bool `name:"allow-unrelated-histories" help:"Allow merging unrelated histories"` Textconv bool `name:"textconv" help:"Converting text to Unicode"` - Message []string `name:"message" short:"m" help:"Merge commit message (for a non-fast-forward merge)"` - File string `name:"file" short:"F" help:"Read message from file"` + Message []string `name:"message" short:"m" help:"Merge commit message (for a non-fast-forward merge)" placeholder:""` + File string `name:"file" short:"F" help:"Read message from file" placeholder:""` Signoff bool `name:"signoff" negatable:"" help:"Add a Signed-off-by trailer" default:"false"` Abort bool `name:"abort" help:"Abort a conflicting merge"` Continue bool `name:"continue" help:"Continue a merge with resolved conflicts"` } +const ( + mergeSummaryFormat = `%szeta merge [] [] +%szeta merge --abort +%szeta merge --continue` +) + func (c *Merge) Summary() string { or := W(" or: ") return fmt.Sprintf(mergeSummaryFormat, W("Usage: "), or, or) diff --git a/pkg/command/command_merge_base.go b/pkg/command/command_merge_base.go index 2a14cd7..9d25979 100644 --- a/pkg/command/command_merge_base.go +++ b/pkg/command/command_merge_base.go @@ -10,6 +10,13 @@ import ( "github.com/antgroup/hugescm/pkg/zeta" ) +type MergeBase struct { + // --is-ancestor + All bool `name:"all" short:"a" negatable:"" default:"false" help:"Output all common ancestors"` + IsAncestor bool `name:"is-ancestor" help:"Is the first one ancestor of the other?"` + Args []string `arg:"" name:"commit"` +} + // usage: zeta merge-base [-a | --all] ... // or: zeta merge-base [-a | --all] --octopus ... // or: zeta merge-base --is-ancestor @@ -19,13 +26,6 @@ const ( %szeta merge-base --is-ancestor ` ) -type MergeBase struct { - // --is-ancestor - All bool `name:"all" short:"a" negatable:"" default:"false" help:"Output all common ancestors"` - IsAncestor bool `name:"is-ancestor" help:"Is the first one ancestor of the other?"` - Args []string `arg:"" name:"commit"` -} - func (c *MergeBase) Summary() string { or := W(" or: ") return fmt.Sprintf(mergeBaseSummaryFormat, W("Usage: "), or) diff --git a/pkg/command/command_merge_file.go b/pkg/command/command_merge_file.go index d6c533e..2c60428 100644 --- a/pkg/command/command_merge_file.go +++ b/pkg/command/command_merge_file.go @@ -15,8 +15,8 @@ type MergeFile struct { ObjectID bool `name:"object-id" negatable:"" help:"Use object IDs instead of filenames"` Diff3 bool `name:"diff3" negatable:"" help:"Use a diff3 based merge"` ZDiff3 bool `name:"zdiff3" negatable:"" help:"Use a zealous diff3 based merge"` - DiffAlgorithm string `name:"diff-algorithm" help:"Choose a diff algorithm, supported: histogram|onp|myers|patience|minimal"` - L []string `name:":L" short:"L" help:"Set labels for file1/orig-file/file2"` + DiffAlgorithm string `name:"diff-algorithm" help:"Choose a diff algorithm, supported: histogram|onp|myers|patience|minimal" placeholder:""` + L []string `short:"L" shortonly:"" help:"Set labels for file1/orig-file/file2"` F1 string `arg:"" name:"file1" help:""` O string `arg:"" name:"orig-file" help:""` F2 string `arg:"" name:"file2" help:""` diff --git a/pkg/command/command_merge_tree.go b/pkg/command/command_merge_tree.go index 1263a88..7834df8 100644 --- a/pkg/command/command_merge_tree.go +++ b/pkg/command/command_merge_tree.go @@ -12,11 +12,11 @@ import ( type MergeTree struct { Branch1 string `arg:"" name:"branch1" help:"branch1"` Branch2 string `arg:"" name:"branch2" help:"branch2"` - MergeBase string `name:"merge-base" help:"Specify a merge-base for the merge"` + MergeBase string `name:"merge-base" help:"Specify a merge-base for the merge" placeholder:""` AllowUnrelatedHistories bool `name:"allow-unrelated-histories" help:"If branches lack common history, merge-tree errors. Use this flag to force merge"` NameOnly bool `name:"name-only" help:"Only output conflict-related file names"` Textconv bool `name:"textconv" help:"Converting text to Unicode"` - Z bool `name:":z" short:"z" help:"Terminate entries with NUL byte"` + Z bool `short:"z" shortonly:"" help:"Terminate entries with NUL byte"` JSON bool `name:"json" help:"Convert conflict results to JSON"` } diff --git a/pkg/command/command_push.go b/pkg/command/command_push.go index c4d9372..3d96716 100644 --- a/pkg/command/command_push.go +++ b/pkg/command/command_push.go @@ -12,7 +12,7 @@ import ( type Push struct { Refspec string `arg:"" optional:"" name:"refspec" default:"" help:"Specify what destination ref to update with what source object"` - PushOptions []string `name:"push-option" short:"o" help:"Option to transmit"` + PushOptions []string `name:"push-option" short:"o" help:"Option to transmit" placeholder:"