mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 09:42:25 +00:00
move the cli to the cli/ package so enterprising individuals can call it
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
37
cli/main.go
Normal file
37
cli/main.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/mitchellh/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Run(args []string) int {
|
||||||
|
// Get the command line args. We shortcut "--version" and "-v" to
|
||||||
|
// just show the version.
|
||||||
|
for _, arg := range args {
|
||||||
|
if arg == "-v" || arg == "--version" {
|
||||||
|
newArgs := make([]string, len(args)+1)
|
||||||
|
newArgs[0] = "version"
|
||||||
|
copy(newArgs[1:], args)
|
||||||
|
args = newArgs
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cli := &cli.CLI{
|
||||||
|
Args: args,
|
||||||
|
Commands: Commands,
|
||||||
|
HelpFunc: cli.FilteredHelpFunc(
|
||||||
|
CommandsInclude, cli.BasicHelpFunc("vault")),
|
||||||
|
}
|
||||||
|
|
||||||
|
exitCode, err := cli.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return exitCode
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cli
|
||||||
|
|
||||||
// The git commit that was compiled. This will be filled in by the compiler.
|
// The git commit that was compiled. This will be filled in by the compiler.
|
||||||
var GitCommit string
|
var GitCommit string
|
||||||
35
main.go
35
main.go
@@ -1,42 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/hashicorp/vault/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Exit(realMain())
|
os.Exit(cli.Run(os.Args[1:]))
|
||||||
}
|
|
||||||
|
|
||||||
func realMain() int {
|
|
||||||
// Get the command line args. We shortcut "--version" and "-v" to
|
|
||||||
// just show the version.
|
|
||||||
args := os.Args[1:]
|
|
||||||
for _, arg := range args {
|
|
||||||
if arg == "-v" || arg == "--version" {
|
|
||||||
newArgs := make([]string, len(args)+1)
|
|
||||||
newArgs[0] = "version"
|
|
||||||
copy(newArgs[1:], args)
|
|
||||||
args = newArgs
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cli := &cli.CLI{
|
|
||||||
Args: args,
|
|
||||||
Commands: Commands,
|
|
||||||
HelpFunc: cli.FilteredHelpFunc(
|
|
||||||
CommandsInclude, cli.BasicHelpFunc("vault")),
|
|
||||||
}
|
|
||||||
|
|
||||||
exitCode, err := cli.Run()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return exitCode
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ echo "==> Building..."
|
|||||||
gox \
|
gox \
|
||||||
-os="${XC_OS}" \
|
-os="${XC_OS}" \
|
||||||
-arch="${XC_ARCH}" \
|
-arch="${XC_ARCH}" \
|
||||||
-ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
-ldflags "-X github.com/hashicorp/vault/cli.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||||
-output "pkg/{{.OS}}_{{.Arch}}/vault" \
|
-output "pkg/{{.OS}}_{{.Arch}}/vault" \
|
||||||
.
|
.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user