cli, entry, lang: Add an entry package for embeddable CLI's

This adds a new entry package that allows embedded programs to exist
inside of mgmt. This took a lot of refactoring to get the API right, but
I think it's incredibly elegant now. There is a chance we tweak things a
bit, but it's a good first start. All-in-one programs are coming soon!
This commit is contained in:
James Shubin
2024-03-04 22:09:44 -05:00
parent 9527d0dcbd
commit d52c90ede4
5 changed files with 339 additions and 0 deletions

12
main.go
View File

@@ -25,6 +25,7 @@ import (
"github.com/purpleidea/mgmt/cli"
cliUtil "github.com/purpleidea/mgmt/cli/util"
"github.com/purpleidea/mgmt/entry"
_ "github.com/purpleidea/mgmt/gapi/empty" // import so the gapi registers
_ "github.com/purpleidea/mgmt/lang/gapi" // import so the gapi registers
_ "github.com/purpleidea/mgmt/yamlgraph" // import so the gapi registers
@@ -72,6 +73,17 @@ func main() {
},
Args: os.Args,
}
// is there an alternate entry point for the cli?
if cli, err := entry.Lookup(); err == nil {
if err := cli.CLI(context.Background(), data); err != nil {
fmt.Println(err)
os.Exit(1)
//return // redundant
}
return
}
if err := cli.CLI(context.Background(), data); err != nil {
fmt.Println(err)
os.Exit(1)