Skip to content

Commit

Permalink
Merge pull request #40 from latitudesh/release/v1.3.0
Browse files Browse the repository at this point in the history
Release/v1.3.0
  • Loading branch information
ynhummel committed Apr 11, 2024
2 parents f03baa6 + 3baf0c7 commit 92f02f1
Show file tree
Hide file tree
Showing 67 changed files with 1,218 additions and 469 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:

jobs:

goreleaser:
goreleaser:
runs-on: ubuntu-latest
steps:
-
Expand All @@ -34,3 +34,25 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }}

generate-docs:
runs-on: ubuntu-latest
steps:
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.6'
-
name: Generate documentation
run: go run internal/generator/documentation/generate.go
-
name: Sync to readme
run: |
docs=$( jq -sR '{"body": .}' commands.md )
curl --request PUT \
--url https://dash.readme.com/api/v1/docs/cli-commands \
--header 'accept: application/json' \
--header 'authorization: Basic ${{ secrets.README_API_KEY }}' \
--header 'content-type: application/json' \
--data $docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

dist/
commands.md
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ before:
- go mod download

builds:
- main: ./cmd/lsh/main.go
-
env:
- CGO_ENABLED=0
ldflags:
Expand Down
9 changes: 5 additions & 4 deletions cli/assign_server_virtual_network_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/latitudesh/lsh/client/virtual_network_assignments"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"

Expand All @@ -26,7 +27,7 @@ type CreateVirtualNetworkAssignmentOperation struct {
func (o *CreateVirtualNetworkAssignmentOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "create",
Short: "Assign a server to a virtual network.",
Short: "Assign a server to a virtual network",
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -72,8 +73,8 @@ func (o *CreateVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [
params := virtual_network_assignments.NewAssignServerVirtualNetworkParams()
o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes)

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -83,7 +84,7 @@ func (o *CreateVirtualNetworkAssignmentOperation) run(cmd *cobra.Command, args [
return nil
}

if !debug {
if !lsh.Debug {
utils.Render(response.GetData())
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/autocomplete.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 7 additions & 31 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cli

import (
"fmt"
"log"
"os"
"path"
"path/filepath"

"github.com/latitudesh/lsh/client"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/version"

"github.com/go-openapi/runtime"
Expand All @@ -18,26 +18,12 @@ import (
"github.com/spf13/viper"
)

// debug flag indicating that cli should output debug logs
var debug bool

// config file location
var configFile string

// dry run flag
var dryRun bool

// name of the executable
var exeName string = filepath.Base(os.Args[0])

// logDebugf writes debug log to stdout
func logDebugf(format string, v ...interface{}) {
if !debug {
return
}
log.Printf(format, v...)
}

// depth of recursion to construct model flags
var maxDepth int = 5

Expand All @@ -49,7 +35,7 @@ func makeClient(cmd *cobra.Command, args []string) (*client.LatitudeShAPI, error
scheme := viper.GetString("scheme")

r := httptransport.New(hostname, basePath, []string{scheme})
r.SetDebug(debug)
r.SetDebug(lsh.Debug)
// set custom producer and consumer to use the default ones

r.Consumers["application/json"] = runtime.JSONConsumer()
Expand All @@ -64,20 +50,14 @@ func makeClient(cmd *cobra.Command, args []string) (*client.LatitudeShAPI, error
r.DefaultAuthentication = auth

appCli := client.New(r, strfmt.Default)
logDebugf("Server url: %v://%v", scheme, hostname)
lsh.LogDebugf("Server url: %v://%v", scheme, hostname)
return appCli, nil
}

// MakeRootCmd returns the root cmd
func MakeRootCmd() (*cobra.Command, error) {
func MakeRootCmd(rootCmd *cobra.Command) (*cobra.Command, error) {
cobra.OnInitialize(initViperConfigs)

// Use executable name as the command name
rootCmd := &cobra.Command{
Use: exeName,
Version: version.Version,
}

// Edit commands template
rootCmd.SetVersionTemplate(fmt.Sprintf("lsh %s\n", rootCmd.Version))

Expand All @@ -100,12 +80,8 @@ func MakeRootCmd() (*cobra.Command, error) {
var noInput bool
rootCmd.PersistentFlags().BoolVar(&noInput, "no-input", false, "skip interactive mode")

// configure debug flag
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "output debug logs")
// configure config location
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file path")
// configure dry run flag
rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "do not send the request to server")

// register security flags
if err := registerAuthInoWriterFlags(rootCmd); err != nil {
Expand Down Expand Up @@ -185,10 +161,10 @@ func initViperConfigs() {
}

if err := viper.ReadInConfig(); err != nil {
logDebugf("Error: loading config file: %v", err)
lsh.LogDebugf("Error: loading config file: %v", err)
return
}
logDebugf("Using config file: %v", viper.ConfigFileUsed())
lsh.LogDebugf("Using config file: %v", viper.ConfigFileUsed())
}

// registerAuthInoWriterFlags registers all flags needed to perform authentication
Expand All @@ -213,7 +189,7 @@ func makeAuthInfoWriter(cmd *cobra.Command) (runtime.ClientAuthInfoWriter, error
auths = append(auths, httptransport.APIKeyAuth("User-Agent", "header", userAgent))
}
if len(auths) == 0 {
logDebugf("Warning: No auth params detected.")
lsh.LogDebugf("Warning: No auth params detected.")
return nil, nil
}
// compose all auths together
Expand Down
9 changes: 5 additions & 4 deletions cli/create_project_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/latitudesh/lsh/client/projects"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/api/resource"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"
Expand All @@ -27,7 +28,7 @@ type CreateProjectOperation struct {
func (o *CreateProjectOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "create",
Short: "Creates a project.",
Short: "Create a project",
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -86,8 +87,8 @@ func (o *CreateProjectOperation) run(cmd *cobra.Command, args []string) error {
params := projects.NewCreateProjectParams()
o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes)

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -97,7 +98,7 @@ func (o *CreateProjectOperation) run(cmd *cobra.Command, args []string) error {
return nil
}

if !debug {
if !lsh.Debug {
utils.Render(response.GetData())
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions cli/create_server_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/latitudesh/lsh/client/servers"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/api/resource"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"
Expand All @@ -27,7 +28,7 @@ type CreateServerOperation struct {
func (o *CreateServerOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "create",
Short: "Deploy a new server.",
Short: "Deploy a bare metal server",
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -126,8 +127,8 @@ func (o *CreateServerOperation) run(cmd *cobra.Command, args []string) error {
params := servers.NewCreateServerParams()
o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes)

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -137,7 +138,7 @@ func (o *CreateServerOperation) run(cmd *cobra.Command, args []string) error {
return nil
}

if !debug {
if !lsh.Debug {
utils.Render(response.GetData())
}

Expand Down
10 changes: 6 additions & 4 deletions cli/create_server_reinstall_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/latitudesh/lsh/client/server_reinstall"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/api/resource"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"
Expand Down Expand Up @@ -31,7 +32,8 @@ type CreateServerReinstallOperation struct {
func (o *CreateServerReinstallOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "reinstall",
Short: "Submit a reinstall request to a server.",
Short: "Reintall a server",
Long: "Submit a reinstall request to a server.",
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -121,8 +123,8 @@ func (o *CreateServerReinstallOperation) run(cmd *cobra.Command, args []string)
return nil
}

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -132,7 +134,7 @@ func (o *CreateServerReinstallOperation) run(cmd *cobra.Command, args []string)
return nil
}

if !debug {
if !lsh.Debug {
response.Render()
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions cli/create_virtual_network_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/latitudesh/lsh/client/virtual_networks"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/api/resource"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"
Expand All @@ -27,7 +28,7 @@ type CreateVirtualNetworkOperation struct {
func (o *CreateVirtualNetworkOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "create",
Short: "Creates a new Virtual Network.",
Short: "Creates a virtual network",
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -80,8 +81,8 @@ func (o *CreateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e
params := virtual_networks.NewCreateVirtualNetworkParams()
o.BodyAttributesFlags.AssignValues(params.Body.Data.Attributes)

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -91,7 +92,7 @@ func (o *CreateVirtualNetworkOperation) run(cmd *cobra.Command, args []string) e
return nil
}

if !debug {
if !lsh.Debug {
utils.Render(response.GetData())
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions cli/delete_api_key_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/latitudesh/lsh/client/api_keys"
"github.com/latitudesh/lsh/cmd/lsh"
"github.com/latitudesh/lsh/internal/cmdflag"
"github.com/latitudesh/lsh/internal/utils"

Expand All @@ -26,7 +27,8 @@ type DeleteAPIKeyOperation struct {
func (o *DeleteAPIKeyOperation) Register() (*cobra.Command, error) {
cmd := &cobra.Command{
Use: "destroy",
Short: `Delete an existing API Key. Once deleted, the API Key can no longer be used to access the API.`,
Short: "Delete an API Key",
Long: `Delete an existing API Key. Once deleted, the API Key can no longer be used to access the API.`,
RunE: o.run,
PreRun: o.preRun,
}
Expand Down Expand Up @@ -64,8 +66,8 @@ func (o *DeleteAPIKeyOperation) run(cmd *cobra.Command, args []string) error {
params := api_keys.NewDeleteAPIKeyParams()
o.PathParamFlags.AssignValues(params)

if dryRun {
logDebugf("dry-run flag specified. Skip sending request.")
if lsh.DryRun {
lsh.LogDebugf("dry-run flag specified. Skip sending request.")
return nil
}

Expand All @@ -75,7 +77,7 @@ func (o *DeleteAPIKeyOperation) run(cmd *cobra.Command, args []string) error {
return nil
}

if !debug {
if !lsh.Debug {
response.Render()
}
return nil
Expand Down
Loading

0 comments on commit 92f02f1

Please sign in to comment.