From 817f204a9eaf5d6a8597502124ea28c0a309a5f9 Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Thu, 31 Oct 2024 13:42:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20wip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/openstatus/main.go | 34 +++----------- config.openstatus.yml | 5 ++ go.mod | 19 ++++++-- go.sum | 57 ++++++++++++++++++---- internal/config/config.go | 13 ++++++ internal/monitors/monitor_info.go | 22 +++++++-- internal/monitors/monitor_trigger.go | 70 +++++++++++++++++++++------- internal/monitors/monitors.go | 43 ++++++++++++++++- internal/monitors/monitors_list.go | 38 +++++++++++---- internal/run/run.go | 38 +++++++++++++++ internal/whoami/whoami.go | 16 +++++-- 11 files changed, 279 insertions(+), 76 deletions(-) create mode 100644 config.openstatus.yml create mode 100644 internal/config/config.go create mode 100644 internal/run/run.go diff --git a/cmd/openstatus/main.go b/cmd/openstatus/main.go index b38357d..238860f 100644 --- a/cmd/openstatus/main.go +++ b/cmd/openstatus/main.go @@ -1,51 +1,29 @@ package main import ( - "fmt" + "context" "log" "os" "github.com/openstatusHQ/cli/internal/monitors" + "github.com/openstatusHQ/cli/internal/run" "github.com/openstatusHQ/cli/internal/whoami" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func main() { - app := &cli.App{ + app := &cli.Command{ Name: "OpenStatus", Usage: "This is OpenStatus Command Line Interface", Version: "v0.0.1", Commands: []*cli.Command{ - { - Name: "run", - Aliases: []string{"r"}, - Usage: "Run your synthetics tests defined in your configuration file", - Action: func(cCtx *cli.Context) error { - fmt.Println("Test ran 🔥") - return nil - }, - }, monitors.MonitorsCmd(), + run.RunCmd(), whoami.WhoamiCmd(), }, - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "config", - Usage: "The configuration file", - DefaultText: "config.openstatus.yaml", - Value: "config.openstatus.yaml", - }, - &cli.StringFlag{ - Name: "access-token", - Usage: "OpenStatus API Access Token", - Aliases: []string{"t"}, - EnvVars: []string{"OPENSTATUS_API_TOKEN"}, - Required: true, - }, - }, } - if err := app.Run(os.Args); err != nil { + if err := app.Run(context.Background(), os.Args); err != nil { log.Fatal(err) } } diff --git a/config.openstatus.yml b/config.openstatus.yml new file mode 100644 index 0000000..8fc733e --- /dev/null +++ b/config.openstatus.yml @@ -0,0 +1,5 @@ +tests: + - id: + - 1 + - 660 + diff --git a/go.mod b/go.mod index 790abf5..b12d203 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,20 @@ module github.com/openstatusHQ/cli go 1.23.2 +require github.com/urfave/cli/v3 v3.0.0-alpha9.2 // direct + +require ( + github.com/fatih/color v1.18.0 + github.com/knadh/koanf/v2 v2.1.1 + github.com/rodaine/table v1.3.0 +) + require ( - github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/urfave/cli/v2 v2.27.5 // direct - github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + golang.org/x/sys v0.26.0 // indirect ) diff --git a/go.sum b/go.sum index c8b6c7e..5d41651 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,49 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= -github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w= -github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= -github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= -github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= +github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/v2 v2.1.1 h1:/R8eXqasSTsmDCsAyYj+81Wteg8AqrV9CP6gvsTsOmM= +github.com/knadh/koanf/v2 v2.1.1/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rodaine/table v1.3.0 h1:4/3S3SVkHnVZX91EHFvAMV7K42AnJ0XuymRR2C5HlGE= +github.com/rodaine/table v1.3.0/go.mod h1:47zRsHar4zw0jgxGxL9YtFfs7EGN6B/TaS+/Dmk4WxU= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y= +github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..74f8ded --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,13 @@ +package config + +import "github.com/knadh/koanf/v2" + +var k = koanf.New(".") + +type TestsConfig struct { + Ids []int `koanf:"ids"` +} + +type Config struct { + Tests TestsConfig `koanf:"tests"` +} diff --git a/internal/monitors/monitor_info.go b/internal/monitors/monitor_info.go index 8e0ebc2..aebcf4a 100644 --- a/internal/monitors/monitor_info.go +++ b/internal/monitors/monitor_info.go @@ -1,12 +1,13 @@ package monitors import ( + "context" "encoding/json" "fmt" "io" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func getMonitorInfo(httpClient *http.Client, apiKey string, monitorId string) error { @@ -25,6 +26,9 @@ func getMonitorInfo(httpClient *http.Client, apiKey string, monitorId string) er if err != nil { return err } + if res.StatusCode != http.StatusOK { + return fmt.Errorf("Failed to get monitor information") + } defer res.Body.Close() body, _ := io.ReadAll(res.Body) @@ -43,12 +47,20 @@ func GetMonitorInfoCmd() *cli.Command { monitorInfoCmd := cli.Command{ Name: "info", Usage: "Get monitor information", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { fmt.Println("Monitor information") - monitorId := cCtx.Args().Get(cCtx.Args().Len() - 1) - getMonitorInfo(http.DefaultClient, cCtx.String("access-token"), monitorId) - return nil + monitorId := cmd.Args().Get(0) + err := getMonitorInfo(http.DefaultClient, cmd.String("access-token"), monitorId) + return err }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "access-token", + Usage: "OpenStatus API Access Token", + Aliases: []string{"t"}, + Sources: cli.EnvVars("OPENSTATUS_API_TOKEN"), + Required: true, + }}, } return &monitorInfoCmd } diff --git a/internal/monitors/monitor_trigger.go b/internal/monitors/monitor_trigger.go index 4f00bdc..1e15675 100644 --- a/internal/monitors/monitor_trigger.go +++ b/internal/monitors/monitor_trigger.go @@ -1,12 +1,15 @@ package monitors import ( + "context" "encoding/json" "fmt" "io" "net/http" - "github.com/urfave/cli/v2" + "github.com/fatih/color" + "github.com/rodaine/table" + "github.com/urfave/cli/v3" ) var ( @@ -19,31 +22,58 @@ func monitorTrigger(httpClient *http.Client, apiKey string, monitorId string) er if monitorId == "" { return fmt.Errorf("Monitor ID is required") } + fmt.Println("Waiting for the result...") - url := fmt.Sprintf("https://api.openstatus.dev/v1/monitor/%s/trigger", monitorId) + url := fmt.Sprintf("https://api.openstatus.dev/v1/monitor/%s/run", monitorId) - req, _ := http.NewRequest("POST", url, nil) + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return err + } req.Header.Add("x-openstatus-key", apiKey) res, err := httpClient.Do(req) if err != nil { return err } + if res.StatusCode != http.StatusOK { + return fmt.Errorf("Failed to trigger monitor test") + } + defer res.Body.Close() body, _ := io.ReadAll(res.Body) - var monitors []Monitor - err = json.Unmarshal(body, &monitors) + + var result []RunResult + err = json.Unmarshal(body, &result) if err != nil { return err } - fmt.Println("Monitors") - for _, monitor := range monitors { - if monitor.Active || allMonitor { - fmt.Printf("%d %s %s \n", monitor.ID, monitor.Name, monitor.URL) + headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc() + columnFmt := color.New(color.FgYellow).SprintfFunc() + + tbl := table.New("Region", "Latency (ms)", "Status") + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + + var inError bool + for _, r := range result { + if r.Error != "" { + inError = true + tbl.AddRow(r.Region, r.Latency, color.RedString("❌")) + } else { + tbl.AddRow(r.Region, r.Latency, color.GreenString("✔")) } + } + tbl.Print() + if inError { + fmt.Println(color.RedString("Some regions failed")) + + return fmt.Errorf("Some regions failed") + } else { + fmt.Println(color.GreenString("All regions passed")) + } return nil } @@ -52,21 +82,27 @@ func GetMonitorsTriggerCmd() *cli.Command { Name: "trigger", Usage: "Trigger a monitor test", Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "no-wait", - Usage: "Do not wait for the result, return immediately", - Destination: &noWait, - }, &cli.BoolFlag{ Name: "no-result", Usage: "Do not return the result of the test, return the result ID", Destination: &noResult, }, + &cli.StringFlag{ + Name: "access-token", + Usage: "OpenStatus API Access Token", + Aliases: []string{"t"}, + Sources: cli.EnvVars("OPENSTATUS_API_TOKEN"), + Required: true, + }, }, - Action: func(cCtx *cli.Context) error { - r := cCtx.String("access-token") - fmt.Println("Triggering monitor test", r) + Action: func(ctx context.Context, cmd *cli.Command) error { + monitorId := cmd.Args().Get(0) + err := monitorTrigger(http.DefaultClient, cmd.String("access-token"), monitorId) + if err != nil { + return err + } + // fmt.Println("Triggering monitor test", r) return nil }, } diff --git a/internal/monitors/monitors.go b/internal/monitors/monitors.go index 12882f1..4369ea5 100644 --- a/internal/monitors/monitors.go +++ b/internal/monitors/monitors.go @@ -1,7 +1,7 @@ package monitors import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type Monitor struct { @@ -17,12 +17,51 @@ type Monitor struct { DegradedAfter int `json:"degraded_after,omitempty"` } +type Timing struct { + DnsStart int64 `json:"dnsStart"` + DnsDone int64 `json:"dnsDone"` + ConnectStart int64 `json:"connectStart"` + ConnectDone int64 `json:"connectDone"` + TlsHandshakeStart int64 `json:"tlsHandshakeStart"` + TlsHandshakeDone int64 `json:"tlsHandshakeDone"` + FirstByteStart int64 `json:"firstByteStart"` + FirstByteDone int64 `json:"firstByteDone"` + TransferStart int64 `json:"transferStart"` + TransferDone int64 `json:"transferDone"` +} + +type MonitorTriggerResponse struct { + ResultId int `json:"resultId"` +} + +type TriggerResultResponse struct { + MonitorId string `json:"monitorId"` + Url string `json:"url"` + Error bool `json:"error"` + Region string `json:"region"` + Timestamp int `json:"timestamp"` + Latency int `json:"latency"` + StatusCode int `json:"statusCode"` + Timing Timing `json:"timing"` +} + +type RunResult struct { + Headers map[string]string `json:"headers,omitempty"` + Body string `json:"body,omitempty"` + Error string `json:"error,omitempty"` + Region string `json:"region"` + Latency int64 `json:"latency"` + Timestamp int64 `json:"timestamp"` + Status int `json:"status,omitempty"` + Timing Timing `json:"timing"` +} + func MonitorsCmd() *cli.Command { monitorsCmd := cli.Command{ Name: "monitors", Usage: "Manage your monitors", - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ GetMonitorInfoCmd(), GetMonitorsListCmd(), GetMonitorsTriggerCmd(), diff --git a/internal/monitors/monitors_list.go b/internal/monitors/monitors_list.go index e848ce1..a2a4244 100644 --- a/internal/monitors/monitors_list.go +++ b/internal/monitors/monitors_list.go @@ -1,24 +1,31 @@ package monitors import ( + "context" "encoding/json" "fmt" "io" "net/http" - "github.com/urfave/cli/v2" + "github.com/fatih/color" + "github.com/rodaine/table" + "github.com/urfave/cli/v3" ) var allMonitor bool -func listMonitors(httpClient *http.Client, apiKey string) { +func listMonitors(httpClient *http.Client, apiKey string) error { url := "https://api.openstatus.dev/v1/monitor" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-openstatus-key", apiKey) res, err := httpClient.Do(req) if err != nil { - return + return err + } + + if res.StatusCode != http.StatusOK { + return fmt.Errorf("Failed to list monitors") } defer res.Body.Close() @@ -26,15 +33,23 @@ func listMonitors(httpClient *http.Client, apiKey string) { var monitors []Monitor err = json.Unmarshal(body, &monitors) if err != nil { - return + return err } - fmt.Println("Monitors") + headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc() + columnFmt := color.New(color.FgYellow).SprintfFunc() + + tbl := table.New("ID", "Name", "Url") + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + for _, monitor := range monitors { if monitor.Active || allMonitor { - fmt.Printf("%d %s %s \n", monitor.ID, monitor.Name, monitor.URL) + tbl.AddRow(monitor.ID, monitor.Name, monitor.URL) } } + tbl.Print() + + return nil } func GetMonitorsListCmd() *cli.Command { @@ -47,10 +62,17 @@ func GetMonitorsListCmd() *cli.Command { Usage: "List all monitors including inactive ones", Destination: &allMonitor, }, + &cli.StringFlag{ + Name: "access-token", + Usage: "OpenStatus API Access Token", + Aliases: []string{"t"}, + Sources: cli.EnvVars("OPENSTATUS_API_TOKEN"), + Required: true, + }, }, - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { fmt.Println("List of all monitors") - listMonitors(http.DefaultClient, cCtx.String("access-token")) + listMonitors(http.DefaultClient, cmd.String("access-token")) return nil }, } diff --git a/internal/run/run.go b/internal/run/run.go new file mode 100644 index 0000000..8a74741 --- /dev/null +++ b/internal/run/run.go @@ -0,0 +1,38 @@ +package run + +import ( + "context" + "fmt" + + "github.com/urfave/cli/v3" +) + +func RunCmd() *cli.Command { + runCmd := cli.Command{ + Name: "run", + Aliases: []string{"r"}, + Usage: "Run your synthetics tests defined in your configuration file", + Action: func(ctx context.Context, cmd *cli.Command) error { + + fmt.Println(cmd.String("config")) + fmt.Println("Test ran 🔥") + return nil + }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config", + Usage: "The configuration file", + DefaultText: "config.openstatus.yaml", + Value: "config.openstatus.yaml", + }, + &cli.StringFlag{ + Name: "access-token", + Usage: "OpenStatus API Access Token", + Aliases: []string{"t"}, + Sources: cli.EnvVars("OPENSTATUS_API_TOKEN"), + Required: true, + }, + }, + } + return &runCmd +} diff --git a/internal/whoami/whoami.go b/internal/whoami/whoami.go index 5e8a0a7..22ce612 100644 --- a/internal/whoami/whoami.go +++ b/internal/whoami/whoami.go @@ -1,12 +1,13 @@ package whoami import ( + "context" "encoding/json" "fmt" "io" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type Whoami struct { @@ -44,12 +45,19 @@ func WhoamiCmd() *cli.Command { Name: "whoami", Aliases: []string{"w"}, Usage: "Get your current workspace information", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { fmt.Println("Your current workspace information") - - getWhoamiCmd(http.DefaultClient, cCtx.String("access-token")) + getWhoamiCmd(http.DefaultClient, cmd.String("access-token")) return nil }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "access-token", + Usage: "OpenStatus API Access Token", + Aliases: []string{"t"}, + Sources: cli.EnvVars("OPENSTATUS_API_TOKEN"), + Required: true, + }}, } return &whoamiCmd } -- knotmirror 0.0.1