lib: Move to go modules and shed a few tears

The old system with vendor/ and git submodules worked great,
unfortunately FUD around git submodules seemed to scare people away and
golang moved to a go.mod system that adds a new lock file format instead
of using the built-in git version. It's now almost impossible to use
modern golang without this, so we've switched.

So much for the golang compatibility promise-- turns out it doesn't
apply to the useful parts that I actually care about like this.

Thanks to frebib for his incredibly valuable contributions to this
patch. This snide commit message is mine alone.

This patch also mixes in some changes due to legacy golang as we've also
bumped the minimum version to 1.16 in the docs and tests.

Lastly, we had to disable some tests and fix up a few other misc things
to get this passing. We've definitely hot bugs in the go.mod system, and
our Makefile tries to workaround those.
This commit is contained in:
James Shubin
2021-05-25 01:44:30 -04:00
parent 9c75c55fa4
commit 88516546fa
80 changed files with 1115 additions and 287 deletions

View File

@@ -23,22 +23,35 @@ import (
"os"
"sort"
"github.com/purpleidea/mgmt/bindata"
"github.com/purpleidea/mgmt/gapi"
_ "github.com/purpleidea/mgmt/lang" // import so the GAPI registers
_ "github.com/purpleidea/mgmt/langpuppet"
_ "github.com/purpleidea/mgmt/puppet"
_ "github.com/purpleidea/mgmt/yamlgraph"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
// CLIArgs is a struct of values that we pass to the main CLI function.
type CLIArgs struct {
Program string
Version string
Copying string
Flags Flags
}
// CLI is the entry point for using mgmt normally from the CLI.
func CLI(program, version string, flags Flags) error {
func CLI(cliArgs *CLIArgs) error {
// test for sanity
if program == "" || version == "" {
if cliArgs == nil {
return fmt.Errorf("this CLI was not run correctly")
}
if cliArgs.Program == "" || cliArgs.Version == "" {
return fmt.Errorf("program was not compiled correctly, see Makefile")
}
if cliArgs.Copying == "" {
return fmt.Errorf("program copyrights we're removed, can't run")
}
// All of these flags can be accessed in your GAPI implementation with
// the `c.Lineage()[1].Type` and `c.Lineage()[1].IsSet` functions. Their own
@@ -302,23 +315,18 @@ func CLI(program, version string, flags Flags) error {
}
app := cli.NewApp()
app.Name = program // App.name and App.version pass these values through
app.Version = version
app.Name = cliArgs.Program // App.name and App.version pass these values through
app.Version = cliArgs.Version
app.Usage = "next generation config management"
app.Metadata = map[string]interface{}{ // additional flags
"flags": flags,
"flags": cliArgs.Flags,
}
// if no app.Command is specified
app.Action = func(c *cli.Context) error {
// print the license
if c.Bool("license") {
license, err := bindata.Asset("../COPYING") // use go-bindata to get the bytes
if err != nil {
return err
}
fmt.Printf("%s", license)
fmt.Printf("%s", cliArgs.Copying)
return nil
}