Skip to content

Commit

Permalink
Initial restructure of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanratcliffe committed Feb 13, 2024
1 parent 1c980e8 commit 85a296f
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ovm-cli
# Overmind CLI

CLI to interact with the overmind API

Expand Down
34 changes: 34 additions & 0 deletions cmd/bookmarks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"github.com/spf13/cobra"
)

// bookmarksCmd represents the bookmarks command
var bookmarksCmd = &cobra.Command{
Use: "bookmarks",
GroupID: "api",
Short: "Interact with the bookarks that were created in the Explore view",
Long: `A bookmark in Overmind is a set of queries that are stored together and can be
executed as a single block.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
rootCmd.AddCommand(bookmarksCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// bookmarksCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// bookmarksCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
4 changes: 2 additions & 2 deletions cmd/createbookmark.go → cmd/bookmarks_create_bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -140,7 +140,7 @@ func CreateBookmark(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(createBookmarkCmd)
bookmarksCmd.AddCommand(createBookmarkCmd)

createBookmarkCmd.PersistentFlags().String("bookmark-url", "", "The bookmark service API endpoint (defaults to --url)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -116,7 +116,7 @@ func GetAffectedBookmarks(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(getAffectedBookmarksCmd)
bookmarksCmd.AddCommand(getAffectedBookmarksCmd)

getAffectedBookmarksCmd.PersistentFlags().String("bookmark-url", "", "The bookmark service API endpoint (defaults to --url)")
getAffectedBookmarksCmd.PersistentFlags().String("frontend", "https://app.overmind.tech/", "The frontend base URL")
Expand Down
4 changes: 2 additions & 2 deletions cmd/getbookmark.go → cmd/bookmarks_get_bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -113,7 +113,7 @@ func GetBookmark(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(getBookmarkCmd)
bookmarksCmd.AddCommand(getBookmarkCmd)

getBookmarkCmd.PersistentFlags().String("bookmark-url", "", "The bookmark service API endpoint (defaults to --url)")

Expand Down
32 changes: 32 additions & 0 deletions cmd/changes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"github.com/spf13/cobra"
)

// changesCmd represents the changes command
var changesCmd = &cobra.Command{
Use: "changes",
GroupID: "api",
Short: "Create, update and delete changes in Overmind",
Long: `Manage changes that are being tracked using Overmind. NOTE: It is probably
easier to use our IaC wrappers such as 'overmind terraform plan' rather than
using these commands directly, but they are provided for flexibility.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
rootCmd.AddCommand(changesCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// changesCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// changesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
4 changes: 2 additions & 2 deletions cmd/endchange.go → cmd/changes_end_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"connectrpc.com/connect"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -114,7 +114,7 @@ func EndChange(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(endChangeCmd)
changesCmd.AddCommand(endChangeCmd)

withChangeUuidFlags(endChangeCmd)

Expand Down
6 changes: 3 additions & 3 deletions cmd/getchange.go → cmd/changes_get_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
diffspan "github.com/hexops/gotextdiff/span"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -233,7 +233,7 @@ fetch:
BlastItems: int(changeRes.Msg.GetChange().GetMetadata().GetNumAffectedItems()),
BlastEdges: int(changeRes.Msg.GetChange().GetMetadata().GetNumAffectedEdges()),
Risks: []TemplateRisk{},
AssetPath: fmt.Sprintf("https://raw.githubusercontent.com/overmindtech/ovm-cli/%v/assets", assetVersion),
AssetPath: fmt.Sprintf("https://raw.githubusercontent.com/overmindtech/cli/%v/assets", assetVersion),
}

for _, item := range changeRes.Msg.GetChange().GetProperties().GetPlannedChanges() {
Expand Down Expand Up @@ -312,7 +312,7 @@ fetch:
}

func init() {
rootCmd.AddCommand(getChangeCmd)
changesCmd.AddCommand(getChangeCmd)

withChangeUuidFlags(getChangeCmd)
getChangeCmd.PersistentFlags().String("status", "", "The expected status of the change. Use this with --ticket-link. Allowed values: CHANGE_STATUS_UNSPECIFIED, CHANGE_STATUS_DEFINING, CHANGE_STATUS_HAPPENING, CHANGE_STATUS_PROCESSING, CHANGE_STATUS_DONE")
Expand Down
4 changes: 2 additions & 2 deletions cmd/listchanges.go → cmd/changes_list_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -287,7 +287,7 @@ func printJson(ctx context.Context, b []byte, prefix, id string) error {
}

func init() {
rootCmd.AddCommand(listChangesCmd)
changesCmd.AddCommand(listChangesCmd)

listChangesCmd.PersistentFlags().String("frontend", "https://app.overmind.tech/", "The frontend base URL")
listChangesCmd.PersistentFlags().String("format", "files", "How to render the change. Possible values: files, json")
Expand Down
4 changes: 2 additions & 2 deletions cmd/manualchange.go → cmd/changes_manual_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
"github.com/overmindtech/sdp-go/sdpws"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -225,7 +225,7 @@ func ManualChange(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(manualChangeCmd)
changesCmd.AddCommand(manualChangeCmd)

manualChangeCmd.PersistentFlags().String("changes-url", "", "The changes service API endpoint (defaults to --url)")
manualChangeCmd.PersistentFlags().String("management-url", "", "The management service API endpoint (defaults to --url)")
Expand Down
8 changes: 4 additions & 4 deletions cmd/submitplan.go → cmd/changes_submit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"connectrpc.com/connect"
"github.com/getsentry/sentry-go"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/cmd/datamaps"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/cmd/datamaps"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -730,13 +730,13 @@ func SubmitPlan(ctx context.Context, files []string, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(submitPlanCmd)
changesCmd.AddCommand(submitPlanCmd)

submitPlanCmd.PersistentFlags().String("changes-url", "", "The changes service API endpoint (defaults to --url)")
submitPlanCmd.PersistentFlags().String("management-url", "", "The management service API endpoint (defaults to --url)")
submitPlanCmd.PersistentFlags().String("frontend", "https://app.overmind.tech", "The frontend base URL")

submitPlanCmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, ovm-cli will try to come up with one for you.")
submitPlanCmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, overmind will try to come up with one for you.")
submitPlanCmd.PersistentFlags().String("description", "", "Quick description of the change.")
submitPlanCmd.PersistentFlags().String("ticket-link", "*", "Link to the ticket for this change.")
submitPlanCmd.PersistentFlags().String("owner", "", "The owner of this change.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/startchange.go → cmd/chnages_start_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"connectrpc.com/connect"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -114,7 +114,7 @@ func StartChange(ctx context.Context, ready chan bool) int {
}

func init() {
rootCmd.AddCommand(startChangeCmd)
changesCmd.AddCommand(startChangeCmd)

withChangeUuidFlags(startChangeCmd)

Expand Down
30 changes: 30 additions & 0 deletions cmd/invites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"github.com/spf13/cobra"
)

// invitesCmd represents the invites command
var invitesCmd = &cobra.Command{
Use: "invites",
GroupID: "api",
Short: "Manage invites for your team to Overmind",
Long: `Create and revoke Overmind invitations`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
rootCmd.AddCommand(invitesCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// invitesCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// invitesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
8 changes: 4 additions & 4 deletions cmd/invite.go → cmd/invites_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"connectrpc.com/connect"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -237,16 +237,16 @@ func InvitesList(ctx context.Context) int {

func init() {
// list sub-command
rootCmd.AddCommand(listCmd)
invitesCmd.AddCommand(listCmd)
listCmd.PersistentFlags().String("invite-url", "", "A custom URL for the invites API (optional)")

// create sub-command
rootCmd.AddCommand(createCmd)
invitesCmd.AddCommand(createCmd)
createCmd.PersistentFlags().String("invite-url", "", "A custom URL for the invites API (optional)")
createCmd.PersistentFlags().StringSlice("emails", []string{}, "A list of emails to invite")

// revoke sub-command
rootCmd.AddCommand(revokeCmd)
invitesCmd.AddCommand(revokeCmd)
revokeCmd.PersistentFlags().String("invite-url", "", "A custom URL for the invites API (optional)")
revokeCmd.PersistentFlags().String("email", "", "The email address to revoke")
}
7 changes: 4 additions & 3 deletions cmd/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
"github.com/overmindtech/sdp-go/sdpws"
log "github.com/sirupsen/logrus"
Expand All @@ -24,8 +24,9 @@ import (

// requestCmd represents the start command
var requestCmd = &cobra.Command{
Use: "request",
Short: "Runs a request against the overmind API",
Use: "request",
GroupID: "api",
Short: "Runs a request against the overmind API",
PreRun: func(cmd *cobra.Command, args []string) {
// Bind these to viper
err := viper.BindPFlags(cmd.Flags())
Expand Down
26 changes: 22 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"connectrpc.com/connect"
"github.com/google/uuid"
"github.com/overmindtech/ovm-cli/tracing"
"github.com/overmindtech/cli/tracing"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -34,9 +34,9 @@ var cliVersion string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ovm-cli",
Short: "A CLI to interact with the overmind API",
Long: `The ovm-cli allows direct access to the overmind API`,
Use: "overmind",
Short: "The Overmind CLI",
Long: `Calculate the blast radius of your changes, track risks, and make changes with confidence`,
Version: cliVersion,
PreRun: func(cmd *cobra.Command, args []string) {
// Bind these to viper
Expand Down Expand Up @@ -415,6 +415,14 @@ func withChangeUuidFlags(cmd *cobra.Command) {
func init() {
cobra.OnInitialize(initConfig)

// TODO: I'm leaving this for now but I want to go over these and remove a
// bunch of them, but I want to get options before I do. The things I'm
// considering are:
//
// * Move some into a helper like `withChangeUuidFlags` such as log level
// * For things that are only used internally, move to only using env vars i.e. honeycomb, sentry, client_id
// * Completely remove things that aren't used such as stdout trace dump

// General Config
rootCmd.PersistentFlags().StringVar(&logLevel, "log", "info", "Set the log level. Valid values: panic, fatal, error, warn, info, debug, trace")

Expand Down Expand Up @@ -442,6 +450,16 @@ func init() {
// debugging
rootCmd.PersistentFlags().Bool("stdout-trace-dump", false, "Dump all otel traces to stdout for debugging. This requires --otel to be set.")

// Create groups
rootCmd.AddGroup(&cobra.Group{
ID: "iac",
Title: "Infrastructure as Code:",
})
rootCmd.AddGroup(&cobra.Group{
ID: "api",
Title: "Overmind API:",
})

// Run this before we do anything to set up the loglevel
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
formatter := new(log.TextFormatter)
Expand Down
Loading

0 comments on commit 85a296f

Please sign in to comment.