Centralize CLI flag set setup
This commit is contained in:
12
internal/cli/flags.go
Normal file
12
internal/cli/flags.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newFlagSet(name string, stderr io.Writer) *flag.FlagSet {
|
||||||
|
flags := flag.NewFlagSet(name, flag.ContinueOnError)
|
||||||
|
flags.SetOutput(stderr)
|
||||||
|
return flags
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -30,8 +29,7 @@ func manifestCreateCommand(ctx context.Context, args []string, stdout, stderr io
|
|||||||
printManifestCreateHelp(stdout)
|
printManifestCreateHelp(stdout)
|
||||||
return exitOK
|
return exitOK
|
||||||
}
|
}
|
||||||
flags := flag.NewFlagSet("manifest create", flag.ContinueOnError)
|
flags := newFlagSet("manifest create", stderr)
|
||||||
flags.SetOutput(stderr)
|
|
||||||
id := flags.String("id", "", "source bundle id")
|
id := flags.String("id", "", "source bundle id")
|
||||||
created := flags.String("created", "", "source created timestamp")
|
created := flags.String("created", "", "source created timestamp")
|
||||||
overwrite := flags.Bool("overwrite", false, "replace an existing manifest.json")
|
overwrite := flags.Bool("overwrite", false, "replace an existing manifest.json")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -15,8 +14,7 @@ func runCommand(ctx context.Context, args []string, stdout, stderr io.Writer) in
|
|||||||
return exitOK
|
return exitOK
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := flag.NewFlagSet("run", flag.ContinueOnError)
|
flags := newFlagSet("run", stderr)
|
||||||
flags.SetOutput(stderr)
|
|
||||||
configPath := flags.String("config", "", "path to config file")
|
configPath := flags.String("config", "", "path to config file")
|
||||||
dryRun := flags.Bool("dry-run", false, "load and validate config without publishing")
|
dryRun := flags.Bool("dry-run", false, "load and validate config without publishing")
|
||||||
force := flags.Bool("force", false, "allow explicit destructive replacement for supported conflicts")
|
force := flags.Bool("force", false, "allow explicit destructive replacement for supported conflicts")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -17,8 +16,7 @@ func serveCommand(ctx context.Context, args []string, stdout, stderr io.Writer)
|
|||||||
return exitOK
|
return exitOK
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := flag.NewFlagSet("serve", flag.ContinueOnError)
|
flags := newFlagSet("serve", stderr)
|
||||||
flags.SetOutput(stderr)
|
|
||||||
configPath := flags.String("config", "", "path to config file")
|
configPath := flags.String("config", "", "path to config file")
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
return exitUsage
|
return exitUsage
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -17,8 +16,7 @@ type sourceDiagnosticArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseSourceDiagnosticArgs(stderr io.Writer, command string, args []string) (sourceDiagnosticArgs, bool) {
|
func parseSourceDiagnosticArgs(stderr io.Writer, command string, args []string) (sourceDiagnosticArgs, bool) {
|
||||||
flags := flag.NewFlagSet(command, flag.ContinueOnError)
|
flags := newFlagSet(command, stderr)
|
||||||
flags.SetOutput(stderr)
|
|
||||||
configPath := flags.String("config", "", "path to config file")
|
configPath := flags.String("config", "", "path to config file")
|
||||||
pipelineID := flags.String("pipeline", "", "pipeline id")
|
pipelineID := flags.String("pipeline", "", "pipeline id")
|
||||||
bundlePath := flags.String("bundle", "", "source-root-relative bundle path")
|
bundlePath := flags.String("bundle", "", "source-root-relative bundle path")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -14,8 +13,7 @@ func versionCommand(_ context.Context, args []string, stdout, stderr io.Writer)
|
|||||||
printVersionHelp(stdout)
|
printVersionHelp(stdout)
|
||||||
return exitOK
|
return exitOK
|
||||||
}
|
}
|
||||||
flags := flag.NewFlagSet("version", flag.ContinueOnError)
|
flags := newFlagSet("version", stderr)
|
||||||
flags.SetOutput(stderr)
|
|
||||||
formatFlag := addFormatFlag(flags)
|
formatFlag := addFormatFlag(flags)
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
return exitUsage
|
return exitUsage
|
||||||
|
|||||||
Reference in New Issue
Block a user