mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 08:14:08 +00:00
add install only version
This commit is contained in:
parent
a089d12c87
commit
d6bb512b3e
4 changed files with 26 additions and 9 deletions
15
cmd/install_only/main.go
Normal file
15
cmd/install_only/main.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"apc-p15-tool/pkg/app"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// a version of the tool that always calls the `install` subcommand
|
||||||
|
func main() {
|
||||||
|
// insert install command
|
||||||
|
args := []string{os.Args[0], "install"}
|
||||||
|
args = append(args, os.Args[1:]...)
|
||||||
|
|
||||||
|
app.Start(args)
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import "apc-p15-tool/pkg/app"
|
import "apc-p15-tool/pkg/app"
|
||||||
|
|
||||||
|
// main command line tool
|
||||||
func main() {
|
func main() {
|
||||||
app.Start()
|
app.Start(nil)
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ type app struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// actual application start
|
// actual application start
|
||||||
func Start() {
|
func Start(args []string) {
|
||||||
// make app w/ initial logger pre-config
|
// make app w/ initial logger pre-config
|
||||||
initLogLevel := "debug"
|
initLogLevel := "debug"
|
||||||
app := &app{
|
app := &app{
|
||||||
|
@ -34,8 +34,13 @@ func Start() {
|
||||||
// log start
|
// log start
|
||||||
app.logger.Infof("apc-p15-tool v%s", appVersion)
|
app.logger.Infof("apc-p15-tool v%s", appVersion)
|
||||||
|
|
||||||
|
// get os.Args if args unspecified in func
|
||||||
|
if args == nil {
|
||||||
|
args = os.Args
|
||||||
|
}
|
||||||
|
|
||||||
// get & parse config
|
// get & parse config
|
||||||
err := app.getConfig()
|
err := app.getConfig(args)
|
||||||
|
|
||||||
// re-init logger with configured log level
|
// re-init logger with configured log level
|
||||||
app.logger = makeZapLogger(app.config.logLevel)
|
app.logger = makeZapLogger(app.config.logLevel)
|
||||||
|
@ -66,9 +71,6 @@ func Start() {
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get config
|
|
||||||
app.getConfig()
|
|
||||||
|
|
||||||
// run it
|
// run it
|
||||||
exitCode := 0
|
exitCode := 0
|
||||||
err = app.cmd.Run(context.Background())
|
err = app.cmd.Run(context.Background())
|
||||||
|
|
|
@ -2,7 +2,6 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/peterbourgon/ff/v4"
|
"github.com/peterbourgon/ff/v4"
|
||||||
)
|
)
|
||||||
|
@ -31,7 +30,7 @@ type config struct {
|
||||||
|
|
||||||
// getConfig returns the app's configuration from either command line args,
|
// getConfig returns the app's configuration from either command line args,
|
||||||
// or environment variables
|
// or environment variables
|
||||||
func (app *app) getConfig() error {
|
func (app *app) getConfig(args []string) error {
|
||||||
// make config
|
// make config
|
||||||
cfg := &config{}
|
cfg := &config{}
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@ func (app *app) getConfig() error {
|
||||||
// set cfg & parse
|
// set cfg & parse
|
||||||
app.config = cfg
|
app.config = cfg
|
||||||
app.cmd = rootCmd
|
app.cmd = rootCmd
|
||||||
err := app.cmd.Parse(os.Args[1:], ff.WithEnvVarPrefix(environmentVarPrefix))
|
err := app.cmd.Parse(args[1:], ff.WithEnvVarPrefix(environmentVarPrefix))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue