Skip to content

Commit

Permalink
Fixing two related issues
Browse files Browse the repository at this point in the history
- Move default for -o to an environment variable
- Move the build information for version into main package

Signed-off-by: Craig Tracey <craig@arctir.com>
  • Loading branch information
craigtracey committed Nov 24, 2024
1 parent 68e53eb commit d2288d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ all: cli

.PHONY: cli
cli:
GOARCH=amd64 GOOS=linux GOPRIVATE=github.com/arctir go build -o ${BINDIR}/${CLI_BINARY}-linux-amd64 .
GOARCH=amd64 GOOS=darwin GOPRIVATE=github.com/arctir go build -o ${BINDIR}/${CLI_BINARY}-darwin-amd64 .
GOARCH=amd64 GOOS=windows GOPRIVATE=github.com/arctir go build -o ${BINDIR}/${CLI_BINARY}-windows-amd64 .
GOARCH=amd64 GOOS=linux GOPRIVATE=github.com/arctir go build -ldflags="-X main.commit=$(shell git rev-parse HEAD)" -o ${BINDIR}/${CLI_BINARY}-linux-amd64 .
GOARCH=amd64 GOOS=darwin GOPRIVATE=github.com/arctir go build -ldflags="-X main.commit=$(shell git rev-parse HEAD)" -o ${BINDIR}/${CLI_BINARY}-darwin-amd64 .
GOARCH=amd64 GOOS=windows GOPRIVATE=github.com/arctir go build -ldflags="-X main.commit=$(shell git rev-parse HEAD)" -o ${BINDIR}/${CLI_BINARY}-windows-amd64 .
11 changes: 3 additions & 8 deletions commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import (
"os"
"path"

"github.com/alecthomas/kong"
"github.com/arctir/flightdeck-cli/commands/common"
flightdeckclient "github.com/arctir/go-flightdeck/pkg/client"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

type Cli struct {
common.Globals

Expand All @@ -27,8 +22,8 @@ type Cli struct {

type VersionCommand struct{}

func (c VersionCommand) Run(parent *Cli, ctx *Context) error {
fmt.Printf("flightdeck %s, commit %s, built at %s", version, commit, date)
func (c VersionCommand) Run(vars kong.Vars) error {
fmt.Printf("flightdeck %s, commit %s, built at %s\n", vars["buildVersion"], vars["buildCommit"], vars["buildDate"])
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion commands/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import "github.com/google/uuid"

type OrgFlags struct {
Org *uuid.UUID `name:"org" short:"o" optional:"" default:"${defaultOrg}" help:"ID of the organization."`
Org uuid.UUID `name:"org" short:"o" required:"" env:"FLIGHTDECK_ORG" help:"ID of the organization."`
}

type PortalFlags struct {
Expand Down
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (

"github.com/alecthomas/kong"
"github.com/arctir/flightdeck-cli/commands"
"github.com/google/uuid"
)

const defaultAPIEndpoint = "https://api.arctir.cloud/v1"
const defaultLocalAPIEndpoint = "http://localhost:9090/v1"
const defaultAuthEndpoint = "https://auth.arctir.cloud/realms/arctir-prod"

var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
configPath, err := commands.ConfigPath()
if err != nil {
Expand All @@ -26,11 +31,6 @@ func main() {
apiEndpoint = defaultLocalAPIEndpoint
}

defaultOrg := os.Getenv("FLIGHTDECK_ORG")
if defaultOrg == "" {
defaultOrg = uuid.Nil.String()
}

cli := commands.Cli{}
commandContext := commands.Context{}
ctx := kong.Parse(&cli,
Expand All @@ -39,7 +39,9 @@ func main() {
"apiEndpoint": apiEndpoint,
"authEndpoint": authEndpoint,
"configPath": *configPath,
"defaultOrg": defaultOrg,
"buildVersion": version,
"buildCommit": commit,
"buildDate": date,
},
kong.Bind(&commandContext),
kong.Bind(&cli.Globals),
Expand Down

0 comments on commit d2288d2

Please sign in to comment.