cli, gapi: empty, lang, yaml: Refactor the args structs
Put these datastructures into an external package so they can be re-used for parsing elsewhere. Since we remove these dependencies, we need to manually import the GAPI's so that they register. Despite efforts to embed them deeper into the import tree without cycles, this failed. Logically what this told me is that it actually makes sense to allow a different binary with only one of the multiple GAPI's contained within.
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
cliUtil "github.com/purpleidea/mgmt/cli/util"
|
||||
"github.com/purpleidea/mgmt/engine"
|
||||
"github.com/purpleidea/mgmt/gapi"
|
||||
"github.com/purpleidea/mgmt/lang"
|
||||
@@ -53,29 +54,6 @@ func init() {
|
||||
gapi.Register(Name, func() gapi.GAPI { return &GAPI{} }) // register
|
||||
}
|
||||
|
||||
// Args is the CLI parsing structure and type of the parsed result.
|
||||
type Args struct {
|
||||
// Input is the input mcl code or file path or any input specification.
|
||||
Input string `arg:"positional,required"`
|
||||
|
||||
// TODO: removed (temporarily?)
|
||||
//Stdin bool `arg:"--stdin" help:"use passthrough stdin"`
|
||||
|
||||
Download bool `arg:"--download" help:"download any missing imports"`
|
||||
OnlyDownload bool `arg:"--only-download" help:"stop after downloading any missing imports"`
|
||||
Update bool `arg:"--update" help:"update all dependencies to the latest versions"`
|
||||
|
||||
OnlyUnify bool `arg:"--only-unify" help:"stop after type unification"`
|
||||
SkipUnify bool `arg:"--skip-unify" help:"skip type unification"`
|
||||
|
||||
Depth int `arg:"--depth" default:"-1" help:"max recursion depth limit (-1 is unlimited)"`
|
||||
|
||||
// The default of 0 means any error is a failure by default.
|
||||
Retry int `arg:"--depth" help:"max number of retries (-1 is unlimited)"`
|
||||
|
||||
ModulePath string `arg:"--module-path,env:MGMT_MODULE_PATH" help:"choose the modules path (absolute)"`
|
||||
}
|
||||
|
||||
// GAPI implements the main lang GAPI interface.
|
||||
type GAPI struct {
|
||||
InputURI string // input URI of code file system to run
|
||||
@@ -108,7 +86,7 @@ type GAPI struct {
|
||||
// to an etcdFs, and `run` copies to a memFs. All GAPI's run off of the fs that
|
||||
// is passed in.
|
||||
func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) {
|
||||
args, ok := info.Args.(*Args)
|
||||
args, ok := info.Args.(*cliUtil.LangArgs)
|
||||
if !ok {
|
||||
// programming error
|
||||
return nil, fmt.Errorf("could not convert to our struct")
|
||||
|
||||
Reference in New Issue
Block a user