From 10648412e6077fb99fecdd4b8ba7a4317648afc2 Mon Sep 17 00:00:00 2001 From: miaolz123 Date: Tue, 29 Sep 2020 00:18:39 +0800 Subject: [PATCH] feat: update flag --- flag/flag.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flag/flag.go b/flag/flag.go index ec1cdc6..e6965d9 100644 --- a/flag/flag.go +++ b/flag/flag.go @@ -3,6 +3,7 @@ package flag import ( "os" "path/filepath" + "sort" "github.com/urfave/cli/v2" ) @@ -31,14 +32,14 @@ func action(ctx *cli.Context) error { return nil } -func Add(flag cli.Flag, fn cli.ActionFunc) { +func Add(flag cli.Flag, acts ...cli.ActionFunc) { app.Flags = append(app.Flags, flag) - if fn != nil { - actions = append(actions, fn) - } + actions = append(actions, acts...) } func Run() error { app.Flags = append(app.Flags, cli.HelpFlag) + sort.Sort(cli.FlagsByName(app.Flags)) + sort.Sort(cli.CommandsByName(app.Commands)) return app.Run(os.Args) }