From 50075e184affc244057cc9ad2c671c67598acb77 Mon Sep 17 00:00:00 2001 From: Aleksey Bakin Date: Wed, 15 Apr 2026 11:21:41 +0300 Subject: [PATCH 1/2] refactor: migrate to urfave/cli/v3 --- cmd/enapter/main.go | 12 +++---- go.mod | 7 ++-- go.sum | 14 +++----- internal/app/cliflags/duration.go | 2 +- internal/app/enaptercli/app_test.go | 8 ++--- internal/app/enaptercli/cmd_base.go | 36 +++++++++---------- .../app/enaptercli/cmd_base_pagination.go | 2 +- internal/app/enaptercli/cmd_blueprint.go | 4 +-- .../app/enaptercli/cmd_blueprint_download.go | 6 ++-- internal/app/enaptercli/cmd_blueprint_get.go | 6 ++-- .../app/enaptercli/cmd_blueprint_profiles.go | 4 +-- .../cmd_blueprint_profiles_download.go | 6 ++-- .../cmd_blueprint_profiles_upload.go | 6 ++-- .../app/enaptercli/cmd_blueprint_upload.go | 6 ++-- internal/app/enaptercli/cmd_connection.go | 4 +-- internal/app/enaptercli/cmd_connection_add.go | 13 +++---- .../app/enaptercli/cmd_connection_list.go | 15 ++++---- .../app/enaptercli/cmd_connection_remove.go | 13 ++++--- .../enaptercli/cmd_connection_set_default.go | 6 ++-- internal/app/enaptercli/cmd_device.go | 8 ++--- .../enaptercli/cmd_device_change_blueprint.go | 19 +++++----- internal/app/enaptercli/cmd_device_command.go | 4 +-- .../enaptercli/cmd_device_command_execute.go | 6 ++-- .../app/enaptercli/cmd_device_command_get.go | 23 ++++++------ .../app/enaptercli/cmd_device_command_list.go | 6 ++-- .../cmd_device_communication_config.go | 4 +-- ...md_device_communication_config_generate.go | 6 ++-- internal/app/enaptercli/cmd_device_create.go | 4 +-- .../cmd_device_create_lua_device.go | 19 +++++----- .../cmd_device_create_standalone.go | 6 ++-- internal/app/enaptercli/cmd_device_delete.go | 6 ++-- internal/app/enaptercli/cmd_device_get.go | 25 +++++++------ internal/app/enaptercli/cmd_device_list.go | 25 +++++++------ internal/app/enaptercli/cmd_device_logs.go | 30 ++++++++-------- internal/app/enaptercli/cmd_device_monitor.go | 6 ++-- .../app/enaptercli/cmd_device_run_terminal.go | 6 ++-- .../app/enaptercli/cmd_device_telemetry.go | 6 ++-- internal/app/enaptercli/cmd_device_update.go | 6 ++-- internal/app/enaptercli/cmd_rule_engine.go | 4 +-- .../app/enaptercli/cmd_rule_engine_get.go | 6 ++-- .../app/enaptercli/cmd_rule_engine_resume.go | 6 ++-- .../app/enaptercli/cmd_rule_engine_rule.go | 4 +-- .../enaptercli/cmd_rule_engine_rule_create.go | 8 ++--- .../enaptercli/cmd_rule_engine_rule_delete.go | 6 ++-- .../cmd_rule_engine_rule_disable.go | 16 ++++----- .../enaptercli/cmd_rule_engine_rule_enable.go | 16 ++++----- .../enaptercli/cmd_rule_engine_rule_get.go | 6 ++-- .../enaptercli/cmd_rule_engine_rule_list.go | 6 ++-- .../enaptercli/cmd_rule_engine_rule_logs.go | 11 +++--- .../enaptercli/cmd_rule_engine_rule_update.go | 13 +++---- .../cmd_rule_engine_rule_update_script.go | 8 ++--- .../app/enaptercli/cmd_rule_engine_suspend.go | 6 ++-- internal/app/enaptercli/cmd_site.go | 4 +-- internal/app/enaptercli/cmd_site_get.go | 6 ++-- internal/app/enaptercli/cmd_site_list.go | 6 ++-- internal/app/enaptercli/execute.go | 26 +++++++++----- .../app/enaptercli/testdata/helps/enapter | 4 +-- .../testdata/helps/enapter blueprint | 5 ++- .../testdata/helps/enapter blueprint download | 16 ++++----- .../testdata/helps/enapter blueprint get | 14 ++++---- .../testdata/helps/enapter blueprint profiles | 5 ++- .../helps/enapter blueprint profiles download | 14 ++++---- .../helps/enapter blueprint profiles upload | 14 ++++---- .../testdata/helps/enapter blueprint upload | 14 ++++---- .../testdata/helps/enapter connection | 5 ++- .../testdata/helps/enapter connection add | 16 ++++----- .../testdata/helps/enapter connection list | 4 +-- .../testdata/helps/enapter connection remove | 8 ++--- .../helps/enapter connection set-default | 8 ++--- .../enaptercli/testdata/helps/enapter device | 5 ++- .../helps/enapter device change-blueprint | 20 +++++------ .../testdata/helps/enapter device command | 5 ++- .../helps/enapter device command execute | 20 +++++------ .../testdata/helps/enapter device command get | 20 +++++------ .../helps/enapter device command list | 16 ++++----- .../helps/enapter device communication-config | 5 ++- ...apter device communication-config generate | 18 +++++----- .../testdata/helps/enapter device create | 5 ++- .../helps/enapter device create lua-device | 24 ++++++------- .../helps/enapter device create standalone | 18 +++++----- .../testdata/helps/enapter device delete | 16 ++++----- .../testdata/helps/enapter device get | 18 +++++----- .../testdata/helps/enapter device list | 18 +++++----- .../testdata/helps/enapter device logs | 32 ++++++++--------- .../testdata/helps/enapter device monitor | 18 +++++----- .../helps/enapter device run-terminal | 16 ++++----- .../testdata/helps/enapter device telemetry | 18 +++++----- .../testdata/helps/enapter device update | 20 +++++------ .../testdata/helps/enapter rule-engine | 5 ++- .../testdata/helps/enapter rule-engine get | 14 ++++---- .../testdata/helps/enapter rule-engine resume | 14 ++++---- .../testdata/helps/enapter rule-engine rule | 5 ++- .../helps/enapter rule-engine rule create | 24 ++++++------- .../helps/enapter rule-engine rule delete | 16 ++++----- .../helps/enapter rule-engine rule disable | 16 ++++----- .../helps/enapter rule-engine rule enable | 16 ++++----- .../helps/enapter rule-engine rule get | 16 ++++----- .../helps/enapter rule-engine rule list | 14 ++++---- .../helps/enapter rule-engine rule logs | 18 +++++----- .../helps/enapter rule-engine rule update | 18 +++++----- .../enapter rule-engine rule update-script | 22 ++++++------ .../helps/enapter rule-engine suspend | 14 ++++---- .../enaptercli/testdata/helps/enapter site | 9 +++-- .../testdata/helps/enapter site get | 14 ++++---- .../testdata/helps/enapter site list | 16 ++++----- 105 files changed, 615 insertions(+), 618 deletions(-) diff --git a/cmd/enapter/main.go b/cmd/enapter/main.go index 43bc5bd..3074581 100644 --- a/cmd/enapter/main.go +++ b/cmd/enapter/main.go @@ -7,7 +7,7 @@ import ( "os/signal" "runtime" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/enaptercli" ) @@ -20,13 +20,13 @@ var ( ) func main() { - cli.VersionPrinter = func(c *cli.Context) { + cli.VersionPrinter = func(cmd *cli.Command) { fmt.Printf("Enapter CLI %s, commit %s, built at %s, Go version %s\n", - c.App.Version, commit, date, runtime.Version()) + cmd.Root().Version, commit, date, runtime.Version()) } - app := enaptercli.NewApp() - app.Version = version + cmd := enaptercli.NewApp() + cmd.Version = version interruptCh := make(chan os.Signal, 1) signal.Notify(interruptCh, os.Interrupt) @@ -39,7 +39,7 @@ func main() { os.Exit(1) }() - if err := app.RunContext(ctx, os.Args); err != nil { + if err := cmd.Run(ctx, os.Args); err != nil { fmt.Println("") fmt.Println("Error:", err) os.Exit(1) diff --git a/go.mod b/go.mod index 215c2f5..dc384cb 100644 --- a/go.mod +++ b/go.mod @@ -4,17 +4,14 @@ go 1.24.0 require ( github.com/gorilla/websocket v1.5.3 - github.com/stretchr/testify v1.9.0 - github.com/urfave/cli/v2 v2.27.4 + github.com/stretchr/testify v1.11.1 + github.com/urfave/cli/v3 v3.7.0 golang.org/x/term v0.37.0 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect golang.org/x/sys v0.38.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2e6ee48..f357b29 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,13 @@ -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/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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 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/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/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/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8= -github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= -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/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/urfave/cli/v3 v3.7.0 h1:AGSnbUyjtLiM+WJUb4dzXKldl/gL+F8OwmRDtVr6g2U= +github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU= diff --git a/internal/app/cliflags/duration.go b/internal/app/cliflags/duration.go index cd68e37..61a87e7 100644 --- a/internal/app/cliflags/duration.go +++ b/internal/app/cliflags/duration.go @@ -1,7 +1,7 @@ package cliflags import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // Duration is a wrapper around cli.DurationFlag to implement cli.Flag interface. diff --git a/internal/app/enaptercli/app_test.go b/internal/app/enaptercli/app_test.go index 271ad05..c3fef22 100644 --- a/internal/app/enaptercli/app_test.go +++ b/internal/app/enaptercli/app_test.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/enaptercli" ) @@ -17,7 +17,7 @@ import ( var errExitTimeout = errors.New("exit timed out") type testApp struct { - app *cli.App + app *cli.Command outBuf *lineBuffer errCh chan error cancel func() @@ -30,12 +30,12 @@ func startTestApp(args ...string) *testApp { app.HideVersion = true app.Writer = outBuf app.ErrWriter = outBuf - app.ExitErrHandler = func(*cli.Context, error) {} + app.ExitErrHandler = func(context.Context, *cli.Command, error) {} errCh := make(chan error, 1) ctx, cancel := context.WithCancel(context.Background()) go func() { - errCh <- app.RunContext(ctx, args) + errCh <- app.Run(ctx, args) }() return &testApp{ diff --git a/internal/app/enaptercli/cmd_base.go b/internal/app/enaptercli/cmd_base.go index 583e6f0..dd23246 100644 --- a/internal/app/enaptercli/cmd_base.go +++ b/internal/app/enaptercli/cmd_base.go @@ -17,7 +17,7 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/configfile" ) @@ -44,24 +44,24 @@ func (c *cmdBase) Flags() []cli.Flag { Name: "connection", Usage: "Name of the connection to use", Aliases: []string{"c"}, - EnvVars: []string{"ENAPTER3_CONNECTION"}, + Sources: cli.EnvVars("ENAPTER3_CONNECTION"), Destination: &c.connName, }, &cli.StringFlag{ Name: "token", Usage: "Enapter API token", - EnvVars: []string{"ENAPTER3_API_TOKEN"}, + Sources: cli.EnvVars("ENAPTER3_API_TOKEN"), Hidden: true, Destination: &c.token, }, &cli.StringFlag{ Name: "api-url", Usage: "Override API base URL", - EnvVars: []string{"ENAPTER3_API_URL"}, + Sources: cli.EnvVars("ENAPTER3_API_URL"), Value: defaultURL, Hidden: true, Destination: &c.apiURL, - Action: func(_ *cli.Context, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { c.apiURL = strings.TrimSuffix(v, "/") return nil }, @@ -69,7 +69,7 @@ func (c *cmdBase) Flags() []cli.Flag { &cli.BoolFlag{ Name: "api-allow-insecure", Usage: "Allow insecure connections to the Enapter API", - EnvVars: []string{"ENAPTER3_API_ALLOW_INSECURE"}, + Sources: cli.EnvVars("ENAPTER3_API_ALLOW_INSECURE"), Destination: &c.apiAllowInsecure, }, &cli.BoolFlag{ @@ -80,16 +80,16 @@ func (c *cmdBase) Flags() []cli.Flag { } } -func (c *cmdBase) Before(cliCtx *cli.Context) error { - if err := c.setupCredentials(cliCtx); err != nil { - return err +func (c *cmdBase) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + if err := c.setupCredentials(cmd); err != nil { + return ctx, err } - c.writer = cliCtx.App.Writer - c.errWriter = cliCtx.App.ErrWriter + c.writer = cmd.Root().Writer + c.errWriter = cmd.Root().ErrWriter c.colorize = colorsSupported(c.writer) - c.userAgent = "enapter-cli/" + cliCtx.App.Version + c.userAgent = "enapter-cli/" + cmd.Root().Version c.httpClient = &http.Client{ Transport: &http.Transport{ //nolint:gosec // This is needed to allow self-signed certificates on Gateway. @@ -97,10 +97,10 @@ func (c *cmdBase) Before(cliCtx *cli.Context) error { }, } - return nil + return ctx, nil } -func (c *cmdBase) setupCredentials(cliCtx *cli.Context) error { +func (c *cmdBase) setupCredentials(cmd *cli.Command) error { config, err := configfile.Load() if err != nil { return err @@ -111,8 +111,8 @@ func (c *cmdBase) setupCredentials(cliCtx *cli.Context) error { if !ok { return cli.Exit("Unknown connection name.", 1) } - if cliCtx.IsSet("token") || cliCtx.IsSet("api-url") || cliCtx.IsSet("api-allow-insecure") { - fmt.Fprintln(cliCtx.App.ErrWriter, + if cmd.IsSet("token") || cmd.IsSet("api-url") || cmd.IsSet("api-allow-insecure") { + fmt.Fprintln(cmd.Root().ErrWriter, "WARNING: credentials set via environment variables or flags are ignored.") } c.token = conn.Token.Value @@ -400,8 +400,8 @@ func parseRespErrorMessage(resp *http.Response) string { return fmt.Sprintf("Request finished with HTTP status %q, but without error message", resp.Status) } -func validateExpandFlag(cliCtx *cli.Context, supportedFields []string) error { - for _, field := range cliCtx.StringSlice("expand") { +func validateExpandFlag(cmd *cli.Command, supportedFields []string) error { + for _, field := range cmd.StringSlice("expand") { if err := validateFlag("expand", field, supportedFields); err != nil { return err } diff --git a/internal/app/enaptercli/cmd_base_pagination.go b/internal/app/enaptercli/cmd_base_pagination.go index f8318f7..b7ad585 100644 --- a/internal/app/enaptercli/cmd_base_pagination.go +++ b/internal/app/enaptercli/cmd_base_pagination.go @@ -11,7 +11,7 @@ import ( "net/url" "strconv" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) var errEndPagination = errors.New("end pagination") diff --git a/internal/app/enaptercli/cmd_blueprint.go b/internal/app/enaptercli/cmd_blueprint.go index 62f563a..7119dd4 100644 --- a/internal/app/enaptercli/cmd_blueprint.go +++ b/internal/app/enaptercli/cmd_blueprint.go @@ -3,7 +3,7 @@ package enaptercli import ( "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprint struct { @@ -16,7 +16,7 @@ func buildCmdBlueprint() *cli.Command { Name: "blueprint", Usage: "Manage blueprints", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdBlueprintProfiles(), buildCmdBlueprintUpload(), buildCmdBlueprintDownload(), diff --git a/internal/app/enaptercli/cmd_blueprint_download.go b/internal/app/enaptercli/cmd_blueprint_download.go index ed423b5..3092170 100644 --- a/internal/app/enaptercli/cmd_blueprint_download.go +++ b/internal/app/enaptercli/cmd_blueprint_download.go @@ -9,7 +9,7 @@ import ( "os" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintDownload struct { @@ -26,8 +26,8 @@ func buildCmdBlueprintDownload() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_blueprint_get.go b/internal/app/enaptercli/cmd_blueprint_get.go index 09153c0..f1b3236 100644 --- a/internal/app/enaptercli/cmd_blueprint_get.go +++ b/internal/app/enaptercli/cmd_blueprint_get.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintGet struct { @@ -20,8 +20,8 @@ func buildCmdBlueprintGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.get(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.get(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_blueprint_profiles.go b/internal/app/enaptercli/cmd_blueprint_profiles.go index 8976de7..0fc1300 100644 --- a/internal/app/enaptercli/cmd_blueprint_profiles.go +++ b/internal/app/enaptercli/cmd_blueprint_profiles.go @@ -1,7 +1,7 @@ package enaptercli import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintProfiles struct { @@ -14,7 +14,7 @@ func buildCmdBlueprintProfiles() *cli.Command { Name: "profiles", Usage: "Manage blueprint profiles", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdBlueprintProfilesDownload(), buildCmdBlueprintProfilesUpload(), }, diff --git a/internal/app/enaptercli/cmd_blueprint_profiles_download.go b/internal/app/enaptercli/cmd_blueprint_profiles_download.go index 8130754..6a8ec09 100644 --- a/internal/app/enaptercli/cmd_blueprint_profiles_download.go +++ b/internal/app/enaptercli/cmd_blueprint_profiles_download.go @@ -7,7 +7,7 @@ import ( "net/http" "os" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintProfilesDownload struct { @@ -23,8 +23,8 @@ func buildCmdBlueprintProfilesDownload() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_blueprint_profiles_upload.go b/internal/app/enaptercli/cmd_blueprint_profiles_upload.go index 7ba0bca..13973a2 100644 --- a/internal/app/enaptercli/cmd_blueprint_profiles_upload.go +++ b/internal/app/enaptercli/cmd_blueprint_profiles_upload.go @@ -7,7 +7,7 @@ import ( "net/http" "os" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintProfilesUpload struct { @@ -23,8 +23,8 @@ func buildCmdBlueprintProfilesUpload() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.upload(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.upload(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_blueprint_upload.go b/internal/app/enaptercli/cmd_blueprint_upload.go index 1578e2f..58b176d 100644 --- a/internal/app/enaptercli/cmd_blueprint_upload.go +++ b/internal/app/enaptercli/cmd_blueprint_upload.go @@ -8,7 +8,7 @@ import ( "net/http" "os" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdBlueprintUpload struct { @@ -24,8 +24,8 @@ func buildCmdBlueprintUpload() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.upload(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.upload(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_connection.go b/internal/app/enaptercli/cmd_connection.go index e8d91d8..494aec1 100644 --- a/internal/app/enaptercli/cmd_connection.go +++ b/internal/app/enaptercli/cmd_connection.go @@ -1,14 +1,14 @@ package enaptercli import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func buildCmdConnection() *cli.Command { return &cli.Command{ Name: "connection", Usage: "Manage connections to Enapter Cloud and Gateways", - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdConnectionAdd(), buildCmdConnectionRemove(), buildCmdConnectionList(), diff --git a/internal/app/enaptercli/cmd_connection_add.go b/internal/app/enaptercli/cmd_connection_add.go index d357aaa..64134bc 100644 --- a/internal/app/enaptercli/cmd_connection_add.go +++ b/internal/app/enaptercli/cmd_connection_add.go @@ -1,6 +1,7 @@ package enaptercli import ( + "context" "crypto/tls" "encoding/json" "errors" @@ -8,7 +9,7 @@ import ( "net/http" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/configfile" ) @@ -67,7 +68,7 @@ func buildCmdConnectionAdd() *cli.Command { } } -func (c *cmdConnectionAdd) do(cliCtx *cli.Context) error { +func (c *cmdConnectionAdd) do(ctx context.Context, cliCmd *cli.Command) error { config, err := configfile.Load() if err != nil { return err @@ -90,7 +91,7 @@ func (c *cmdConnectionAdd) do(cliCtx *cli.Context) error { if c.siteID != "" { return cli.Exit("The site-id option cannot be used with gateway connections.", 1) } - siteID, err := c.resolveGatewaySiteID(cliCtx) + siteID, err := c.resolveGatewaySiteID(ctx, cliCmd) if err != nil { return err } @@ -111,7 +112,7 @@ func (c *cmdConnectionAdd) do(cliCtx *cli.Context) error { return configfile.Save(config) } -func (c *cmdConnectionAdd) resolveGatewaySiteID(cliCtx *cli.Context) (string, error) { +func (c *cmdConnectionAdd) resolveGatewaySiteID(ctx context.Context, cliCmd *cli.Command) (string, error) { client := &http.Client{ Transport: &http.Transport{ //nolint:gosec // This is needed to allow self-signed certificates on Gateway. @@ -120,13 +121,13 @@ func (c *cmdConnectionAdd) resolveGatewaySiteID(cliCtx *cli.Context) (string, er } req, err := http.NewRequestWithContext( - cliCtx.Context, http.MethodGet, c.url+"/v3/site", nil) + ctx, http.MethodGet, c.url+"/v3/site", nil) if err != nil { return "", fmt.Errorf("new http request: %w", err) } req.Header.Set("X-Enapter-Auth-Token", c.token) - req.Header.Set("User-Agent", "enapter-cli/"+cliCtx.App.Version) + req.Header.Set("User-Agent", "enapter-cli/"+cliCmd.Root().Version) resp, err := client.Do(req) if err != nil { diff --git a/internal/app/enaptercli/cmd_connection_list.go b/internal/app/enaptercli/cmd_connection_list.go index 90a0cd7..5b5d3fb 100644 --- a/internal/app/enaptercli/cmd_connection_list.go +++ b/internal/app/enaptercli/cmd_connection_list.go @@ -1,12 +1,13 @@ package enaptercli import ( + "context" "fmt" "maps" "slices" "text/tabwriter" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/configfile" ) @@ -16,20 +17,22 @@ type cmdConnectionList struct{} func buildCmdConnectionList() *cli.Command { cmd := &cmdConnectionList{} return &cli.Command{ - Name: "list", - Usage: "List all connections", - Action: cmd.do, + Name: "list", + Usage: "List all connections", + Action: func(_ context.Context, cliCmd *cli.Command) error { + return cmd.do(cliCmd) + }, } } -func (c *cmdConnectionList) do(cliCtx *cli.Context) error { +func (c *cmdConnectionList) do(cliCmd *cli.Command) error { config, err := configfile.Load() if err != nil { return err } const padding = 3 - w := tabwriter.NewWriter(cliCtx.App.Writer, 0, 0, padding, ' ', 0) + w := tabwriter.NewWriter(cliCmd.Root().Writer, 0, 0, padding, ' ', 0) fmt.Fprintln(w, "NAME\tTYPE\tURL\tALLOW INSECURE\tSITE ID") diff --git a/internal/app/enaptercli/cmd_connection_remove.go b/internal/app/enaptercli/cmd_connection_remove.go index d9916a8..60adc48 100644 --- a/internal/app/enaptercli/cmd_connection_remove.go +++ b/internal/app/enaptercli/cmd_connection_remove.go @@ -1,9 +1,10 @@ package enaptercli import ( + "context" "fmt" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/configfile" ) @@ -25,24 +26,26 @@ func buildCmdConnectionRemove() *cli.Command { Required: true, }, }, - Action: cmd.do, + Action: func(_ context.Context, cliCmd *cli.Command) error { + return cmd.do(cliCmd) + }, } } -func (c *cmdConnectionRemove) do(cliCtx *cli.Context) error { +func (c *cmdConnectionRemove) do(cliCmd *cli.Command) error { config, err := configfile.Load() if err != nil { return err } if _, ok := config.Connections[c.name]; !ok { - fmt.Fprintln(cliCtx.App.ErrWriter, "WARNING: unknown connection.") + fmt.Fprintln(cliCmd.Root().ErrWriter, "WARNING: unknown connection.") return nil } delete(config.Connections, c.name) if config.DefaultConn == c.name { - fmt.Fprintln(cliCtx.App.ErrWriter, "WARNING: removed connection was set as default.") + fmt.Fprintln(cliCmd.Root().ErrWriter, "WARNING: removed connection was set as default.") config.DefaultConn = "" } diff --git a/internal/app/enaptercli/cmd_connection_set_default.go b/internal/app/enaptercli/cmd_connection_set_default.go index 4fe1c27..f33cf7e 100644 --- a/internal/app/enaptercli/cmd_connection_set_default.go +++ b/internal/app/enaptercli/cmd_connection_set_default.go @@ -1,7 +1,9 @@ package enaptercli import ( - "github.com/urfave/cli/v2" + "context" + + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/configfile" ) @@ -27,7 +29,7 @@ func buildCmdConnectionSetDefault() *cli.Command { } } -func (c *cmdConnectionSetDefault) do(*cli.Context) error { +func (c *cmdConnectionSetDefault) do(context.Context, *cli.Command) error { config, err := configfile.Load() if err != nil { return err diff --git a/internal/app/enaptercli/cmd_device.go b/internal/app/enaptercli/cmd_device.go index 3ef5836..c90142a 100644 --- a/internal/app/enaptercli/cmd_device.go +++ b/internal/app/enaptercli/cmd_device.go @@ -6,7 +6,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDevice struct { @@ -20,7 +20,7 @@ func buildCmdDevice() *cli.Command { Name: "device", Usage: "Manage devices", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdDeviceCreate(), buildCmdDeviceList(), buildCmdDeviceGet(), @@ -64,8 +64,8 @@ func (c *cmdDevice) runWebSocket(ctx context.Context, p runWebSocketParams) erro return c.cmdBase.runWebSocket(ctx, p) } -func (c *cmdDevice) validateExpandFlag(cliCtx *cli.Context) error { - return validateExpandFlag(cliCtx, c.supportedExpandFields()) +func (c *cmdDevice) validateExpandFlag(cmd *cli.Command) error { + return validateExpandFlag(cmd, c.supportedExpandFields()) } func (c *cmdDevice) supportedExpandFields() []string { diff --git a/internal/app/enaptercli/cmd_device_change_blueprint.go b/internal/app/enaptercli/cmd_device_change_blueprint.go index 41486a6..e435431 100644 --- a/internal/app/enaptercli/cmd_device_change_blueprint.go +++ b/internal/app/enaptercli/cmd_device_change_blueprint.go @@ -7,7 +7,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceChangeBlueprint struct { @@ -25,8 +25,8 @@ func buildCmdDeviceChangeBlueprint() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -51,17 +51,18 @@ func (c *cmdDeviceChangeBlueprint) Flags() []cli.Flag { }) } -func (c *cmdDeviceChangeBlueprint) Before(cliCtx *cli.Context) error { - if err := c.cmdDevice.Before(cliCtx); err != nil { - return err +func (c *cmdDeviceChangeBlueprint) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + ctx, err := c.cmdDevice.Before(ctx, cmd) + if err != nil { + return ctx, err } if c.blueprintID != "" && c.blueprintPath != "" { - return errOnlyOneBlueprinFlag + return ctx, errOnlyOneBlueprinFlag } if c.blueprintID == "" && c.blueprintPath == "" { - return errMissedBlueprintFlag + return ctx, errMissedBlueprintFlag } - return c.validateExpandFlag(cliCtx) + return ctx, c.validateExpandFlag(cmd) } func (c *cmdDeviceChangeBlueprint) do(ctx context.Context) error { diff --git a/internal/app/enaptercli/cmd_device_command.go b/internal/app/enaptercli/cmd_device_command.go index 2b57e19..d8f4be6 100644 --- a/internal/app/enaptercli/cmd_device_command.go +++ b/internal/app/enaptercli/cmd_device_command.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommand struct { @@ -19,7 +19,7 @@ func buildCmdDeviceCommand() *cli.Command { Name: "command", Usage: "Manage device commands", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdDeviceCommandExecute(), buildCmdDeviceCommandList(), buildCmdDeviceCommandGet(), diff --git a/internal/app/enaptercli/cmd_device_command_execute.go b/internal/app/enaptercli/cmd_device_command_execute.go index 9c9c47c..dbd2e23 100644 --- a/internal/app/enaptercli/cmd_device_command_execute.go +++ b/internal/app/enaptercli/cmd_device_command_execute.go @@ -7,7 +7,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommandExecute struct { @@ -26,8 +26,8 @@ func buildCmdDeviceCommandExecute() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_command_get.go b/internal/app/enaptercli/cmd_device_command_get.go index 271173b..a063c84 100644 --- a/internal/app/enaptercli/cmd_device_command_get.go +++ b/internal/app/enaptercli/cmd_device_command_get.go @@ -6,7 +6,7 @@ import ( "net/url" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommandGet struct { @@ -23,8 +23,8 @@ func buildCmdDeviceCommandGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -37,21 +37,20 @@ func (c *cmdDeviceCommandGet) Flags() []cli.Flag { Usage: "Execution ID", Destination: &c.executionID, Required: true, - }, &cli.MultiStringFlag{ - Target: &cli.StringSliceFlag{ - Name: "expand", - Usage: "Comma-separated list of expanded options (supported values: log)", - }, + }, &cli.StringSliceFlag{ + Name: "expand", + Usage: "Comma-separated list of expanded options (supported values: log)", Destination: &c.expand, }, ) } -func (c *cmdDeviceCommandGet) Before(cliCtx *cli.Context) error { - if err := c.cmdDevice.Before(cliCtx); err != nil { - return err +func (c *cmdDeviceCommandGet) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + ctx, err := c.cmdDevice.Before(ctx, cmd) + if err != nil { + return ctx, err } - return validateExpandFlag(cliCtx, []string{"log"}) + return ctx, validateExpandFlag(cmd, []string{"log"}) } func (c *cmdDeviceCommandGet) do(ctx context.Context) error { diff --git a/internal/app/enaptercli/cmd_device_command_list.go b/internal/app/enaptercli/cmd_device_command_list.go index 3cc6ee4..f33fae9 100644 --- a/internal/app/enaptercli/cmd_device_command_list.go +++ b/internal/app/enaptercli/cmd_device_command_list.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommandList struct { @@ -19,8 +19,8 @@ func buildCmdDeviceCommandList() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_communication_config.go b/internal/app/enaptercli/cmd_device_communication_config.go index c076aed..65d0ca2 100644 --- a/internal/app/enaptercli/cmd_device_communication_config.go +++ b/internal/app/enaptercli/cmd_device_communication_config.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommunicationConfig struct { @@ -19,7 +19,7 @@ func buildCmdDeviceCommunicationConfig() *cli.Command { Name: "communication-config", Usage: "Manage device communication config", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdDeviceCommunicationConfigGenerate(), }, } diff --git a/internal/app/enaptercli/cmd_device_communication_config_generate.go b/internal/app/enaptercli/cmd_device_communication_config_generate.go index 5dcf3b2..871dab2 100644 --- a/internal/app/enaptercli/cmd_device_communication_config_generate.go +++ b/internal/app/enaptercli/cmd_device_communication_config_generate.go @@ -7,7 +7,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCommunicationConfigGenerate struct { @@ -23,8 +23,8 @@ func buildCmdDeviceCommunicationConfigGenerate() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_create.go b/internal/app/enaptercli/cmd_device_create.go index 1154c1a..5b790c0 100644 --- a/internal/app/enaptercli/cmd_device_create.go +++ b/internal/app/enaptercli/cmd_device_create.go @@ -1,7 +1,7 @@ package enaptercli import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCreate struct { @@ -14,7 +14,7 @@ func buildCmdDeviceCreate() *cli.Command { Name: "create", Usage: "Create devices of different types", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdDeviceCreateStandalone(), buildCmdDeviceCreateLua(), }, diff --git a/internal/app/enaptercli/cmd_device_create_lua_device.go b/internal/app/enaptercli/cmd_device_create_lua_device.go index 1dc8853..3d5a38b 100644 --- a/internal/app/enaptercli/cmd_device_create_lua_device.go +++ b/internal/app/enaptercli/cmd_device_create_lua_device.go @@ -9,7 +9,7 @@ import ( "net/http" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCreateLua struct { @@ -30,8 +30,8 @@ func buildCmdDeviceCreateLua() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -70,17 +70,18 @@ func (c *cmdDeviceCreateLua) Flags() []cli.Flag { }) } -func (c *cmdDeviceCreateLua) Before(cliCtx *cli.Context) error { - if err := c.cmdDeviceCreate.Before(cliCtx); err != nil { - return err +func (c *cmdDeviceCreateLua) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + ctx, err := c.cmdDeviceCreate.Before(ctx, cmd) + if err != nil { + return ctx, err } if c.blueprintID != "" && c.blueprintPath != "" { - return errOnlyOneBlueprinFlag + return ctx, errOnlyOneBlueprinFlag } if c.blueprintID == "" && c.blueprintPath == "" { - return errMissedBlueprintFlag + return ctx, errMissedBlueprintFlag } - return nil + return ctx, nil } func (c *cmdDeviceCreateLua) do(ctx context.Context) error { diff --git a/internal/app/enaptercli/cmd_device_create_standalone.go b/internal/app/enaptercli/cmd_device_create_standalone.go index 2418c55..8dc23b5 100644 --- a/internal/app/enaptercli/cmd_device_create_standalone.go +++ b/internal/app/enaptercli/cmd_device_create_standalone.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceCreateStandalone struct { @@ -26,8 +26,8 @@ func buildCmdDeviceCreateStandalone() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_delete.go b/internal/app/enaptercli/cmd_device_delete.go index fa68ccf..a2ab7e7 100644 --- a/internal/app/enaptercli/cmd_device_delete.go +++ b/internal/app/enaptercli/cmd_device_delete.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceDelete struct { @@ -20,8 +20,8 @@ func buildCmdDeviceDelete() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_get.go b/internal/app/enaptercli/cmd_device_get.go index a890e0c..fda3295 100644 --- a/internal/app/enaptercli/cmd_device_get.go +++ b/internal/app/enaptercli/cmd_device_get.go @@ -6,7 +6,7 @@ import ( "net/url" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceGet struct { @@ -23,8 +23,8 @@ func buildCmdDeviceGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -37,21 +37,20 @@ func (c *cmdDeviceGet) Flags() []cli.Flag { Usage: "Device ID", Destination: &c.deviceID, Required: true, - }, &cli.MultiStringFlag{ - Target: &cli.StringSliceFlag{ - Name: "expand", - Usage: "Comma-separated list of expanded device information (supported values: " + - strings.Join(c.supportedExpandFields(), ", ") + ")", - }, + }, &cli.StringSliceFlag{ + Name: "expand", + Usage: "Comma-separated list of expanded device information (supported values: " + + strings.Join(c.supportedExpandFields(), ", ") + ")", Destination: &c.expand, }) } -func (c *cmdDeviceGet) Before(cliCtx *cli.Context) error { - if err := c.cmdDevice.Before(cliCtx); err != nil { - return err +func (c *cmdDeviceGet) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + ctx, err := c.cmdDevice.Before(ctx, cmd) + if err != nil { + return ctx, err } - return c.validateExpandFlag(cliCtx) + return ctx, c.validateExpandFlag(cmd) } func (c *cmdDeviceGet) do(ctx context.Context) error { diff --git a/internal/app/enaptercli/cmd_device_list.go b/internal/app/enaptercli/cmd_device_list.go index c2e3e69..ee2c221 100644 --- a/internal/app/enaptercli/cmd_device_list.go +++ b/internal/app/enaptercli/cmd_device_list.go @@ -6,7 +6,7 @@ import ( "net/url" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceList struct { @@ -23,20 +23,18 @@ func buildCmdDeviceList() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } func (c *cmdDeviceList) Flags() []cli.Flag { flags := c.cmdDevice.Flags() - return append(flags, &cli.MultiStringFlag{ - Target: &cli.StringSliceFlag{ - Name: "expand", - Usage: "Comma-separated list of expanded device information (supported values: " + - strings.Join(c.supportedExpandFields(), ", ") + ")", - }, + return append(flags, &cli.StringSliceFlag{ + Name: "expand", + Usage: "Comma-separated list of expanded device information (supported values: " + + strings.Join(c.supportedExpandFields(), ", ") + ")", Destination: &c.expand, }, &cli.IntFlag{ Name: "limit", @@ -46,11 +44,12 @@ func (c *cmdDeviceList) Flags() []cli.Flag { }) } -func (c *cmdDeviceList) Before(cliCtx *cli.Context) error { - if err := c.cmdDevice.Before(cliCtx); err != nil { - return err +func (c *cmdDeviceList) Before(ctx context.Context, cmd *cli.Command) (context.Context, error) { + ctx, err := c.cmdDevice.Before(ctx, cmd) + if err != nil { + return ctx, err } - return c.validateExpandFlag(cliCtx) + return ctx, c.validateExpandFlag(cmd) } func (c *cmdDeviceList) do(ctx context.Context) error { diff --git a/internal/app/enaptercli/cmd_device_logs.go b/internal/app/enaptercli/cmd_device_logs.go index 40950ea..e9d3fa3 100644 --- a/internal/app/enaptercli/cmd_device_logs.go +++ b/internal/app/enaptercli/cmd_device_logs.go @@ -10,15 +10,15 @@ import ( "strconv" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceLogs struct { cmdDevice deviceID string follow bool - receivedAtGte cli.Timestamp - receivedAtLt cli.Timestamp + receivedAtGte time.Time + receivedAtLt time.Time offset int limit int severity string @@ -34,8 +34,8 @@ func buildCmdDeviceLogs() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -57,12 +57,12 @@ func (c *cmdDeviceLogs) Flags() []cli.Flag { Name: "received-at-gte", Usage: "From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)", Destination: &c.receivedAtGte, - Layout: time.RFC3339, + Config: cli.TimestampConfig{Layouts: []string{time.RFC3339}}, }, &cli.TimestampFlag{ Name: "received-at-lt", Usage: "To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)", Destination: &c.receivedAtLt, - Layout: time.RFC3339, + Config: cli.TimestampConfig{Layouts: []string{time.RFC3339}}, }, &cli.IntFlag{ Name: "limit", Aliases: []string{"l"}, @@ -82,7 +82,7 @@ func (c *cmdDeviceLogs) Flags() []cli.Flag { Name: "order", Usage: "Order logs by criteria (RECEIVED_AT_ASC[default], RECEIVED_AT_DESC)", Destination: &c.order, - Action: func(_ *cli.Context, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { if v != "RECEIVED_AT_ASC" && v != "RECEIVED_AT_DESC" { return fmt.Errorf("%w: should be one of [RECEIVED_AT_ASC, RECEIVED_AT_DESC]", errUnsupportedFlagValue) } @@ -92,7 +92,7 @@ func (c *cmdDeviceLogs) Flags() []cli.Flag { Name: "retention", Usage: "Filter logs by retention (ALL[default], PERSISTENT, EPHEMERAL)", Destination: &c.retention, - Action: func(_ *cli.Context, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { if v != "ALL" && v != "PERSISTENT" && v != "EPHEMERAL" { return fmt.Errorf("%w: should be one of [ALL, PERSISTENT, EPHEMERAL]", errUnsupportedFlagValue) } @@ -109,10 +109,10 @@ func (c *cmdDeviceLogs) do(ctx context.Context) error { } func (c *cmdDeviceLogs) doFollow(ctx context.Context) error { - if c.receivedAtGte.Value() != nil { + if !c.receivedAtGte.IsZero() { return cli.Exit("Option --received-at-gte is unsupported in follow mode.", 1) } - if c.receivedAtLt.Value() != nil { + if !c.receivedAtLt.IsZero() { return cli.Exit("Option --received-at-lt is unsupported in follow mode.", 1) } if c.offset > 0 { @@ -164,11 +164,11 @@ func (c *cmdDeviceLogs) doFollow(ctx context.Context) error { func (c *cmdDeviceLogs) doList(ctx context.Context) error { query := url.Values{} - if c.receivedAtGte.Value() != nil { - query.Add("received_at.gte", c.receivedAtGte.Value().Format(time.RFC3339)) + if !c.receivedAtGte.IsZero() { + query.Add("received_at.gte", c.receivedAtGte.Format(time.RFC3339)) } - if c.receivedAtLt.Value() != nil { - query.Add("received_at.lt", c.receivedAtLt.Value().Format(time.RFC3339)) + if !c.receivedAtLt.IsZero() { + query.Add("received_at.lt", c.receivedAtLt.Format(time.RFC3339)) } if c.offset > 0 { query.Add("offset", strconv.Itoa(c.offset)) diff --git a/internal/app/enaptercli/cmd_device_monitor.go b/internal/app/enaptercli/cmd_device_monitor.go index 347745f..9e8667d 100644 --- a/internal/app/enaptercli/cmd_device_monitor.go +++ b/internal/app/enaptercli/cmd_device_monitor.go @@ -10,7 +10,7 @@ import ( "slices" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceMonitor struct { @@ -27,8 +27,8 @@ func buildCmdDeviceStream() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_run_terminal.go b/internal/app/enaptercli/cmd_device_run_terminal.go index ce87948..b45f009 100644 --- a/internal/app/enaptercli/cmd_device_run_terminal.go +++ b/internal/app/enaptercli/cmd_device_run_terminal.go @@ -10,7 +10,7 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "golang.org/x/term" ) @@ -31,8 +31,8 @@ func buildCmdDeviceRunTerminal() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_telemetry.go b/internal/app/enaptercli/cmd_device_telemetry.go index 9a3636c..5e36840 100644 --- a/internal/app/enaptercli/cmd_device_telemetry.go +++ b/internal/app/enaptercli/cmd_device_telemetry.go @@ -7,7 +7,7 @@ import ( "net/http" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceTelemetry struct { @@ -24,8 +24,8 @@ func buildCmdDeviceTelemetry() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_device_update.go b/internal/app/enaptercli/cmd_device_update.go index 688a4e1..853aac7 100644 --- a/internal/app/enaptercli/cmd_device_update.go +++ b/internal/app/enaptercli/cmd_device_update.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdDeviceUpdate struct { @@ -26,8 +26,8 @@ func buildCmdDeviceUpdate() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine.go b/internal/app/enaptercli/cmd_rule_engine.go index 9751f13..e0e9645 100644 --- a/internal/app/enaptercli/cmd_rule_engine.go +++ b/internal/app/enaptercli/cmd_rule_engine.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngine struct { @@ -19,7 +19,7 @@ func buildCmdRuleEngine() *cli.Command { Name: "rule-engine", Usage: "Manage the rule engine", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdRuleEngineGet(), buildCmdRuleEngineSuspend(), buildCmdRuleEngineResume(), diff --git a/internal/app/enaptercli/cmd_rule_engine_get.go b/internal/app/enaptercli/cmd_rule_engine_get.go index 69a9bf4..a2ce3cd 100644 --- a/internal/app/enaptercli/cmd_rule_engine_get.go +++ b/internal/app/enaptercli/cmd_rule_engine_get.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineGet struct { @@ -19,8 +19,8 @@ func buildCmdRuleEngineGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine_resume.go b/internal/app/enaptercli/cmd_rule_engine_resume.go index b40b0eb..54e1668 100644 --- a/internal/app/enaptercli/cmd_rule_engine_resume.go +++ b/internal/app/enaptercli/cmd_rule_engine_resume.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineResume struct { @@ -19,8 +19,8 @@ func buildCmdRuleEngineResume() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine_rule.go b/internal/app/enaptercli/cmd_rule_engine_rule.go index 7fdfbf0..283fb54 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) const ( @@ -23,7 +23,7 @@ func buildCmdRuleEngineRule() *cli.Command { Name: "rule", Usage: "Manage rules", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdRuleEngineRuleCreate(), buildCmdRuleEngineRuleDelete(), buildCmdRuleEngineRuleDisable(), diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_create.go b/internal/app/enaptercli/cmd_rule_engine_rule_create.go index d865b06..f33f6c8 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_create.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_create.go @@ -10,7 +10,7 @@ import ( "os" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/cliflags" ) @@ -32,8 +32,8 @@ func buildCmdRuleEngineRuleCreate() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -57,7 +57,7 @@ func (c *cmdRuleEngineRuleCreate) Flags() []cli.Flag { Usage: "Version of the runtime to use for the script execution", Destination: &c.runtimeVersion, Value: ruleRuntimeV3, - Action: func(_ *cli.Context, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { return c.validateRuntimeVersion(v) }, }, diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_delete.go b/internal/app/enaptercli/cmd_rule_engine_rule_delete.go index ef82b7d..495fc9b 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_delete.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_delete.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleDelete struct { @@ -20,8 +20,8 @@ func buildCmdRuleEngineRuleDelete() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_disable.go b/internal/app/enaptercli/cmd_rule_engine_rule_disable.go index a5c76fc..006bd14 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_disable.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_disable.go @@ -7,7 +7,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleDisable struct { @@ -23,20 +23,18 @@ func buildCmdRuleEngineRuleDisable() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } func (c *cmdRuleEngineRuleDisable) Flags() []cli.Flag { return append(c.cmdRuleEngineRule.Flags(), - &cli.MultiStringFlag{ - Target: &cli.StringSliceFlag{ - Name: "rule-id", - Usage: "Rule IDs or slugs", - Required: true, - }, + &cli.StringSliceFlag{ + Name: "rule-id", + Usage: "Rule IDs or slugs", + Required: true, Destination: &c.ruleIDs, }, ) diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_enable.go b/internal/app/enaptercli/cmd_rule_engine_rule_enable.go index 44e9580..dfb1d41 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_enable.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_enable.go @@ -7,7 +7,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleEnable struct { @@ -23,20 +23,18 @@ func buildCmdRuleEngineRuleEnable() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } func (c *cmdRuleEngineRuleEnable) Flags() []cli.Flag { return append(c.cmdRuleEngineRule.Flags(), - &cli.MultiStringFlag{ - Target: &cli.StringSliceFlag{ - Name: "rule-id", - Usage: "Rule IDs or slugs", - Required: true, - }, + &cli.StringSliceFlag{ + Name: "rule-id", + Usage: "Rule IDs or slugs", + Required: true, Destination: &c.ruleIDs, }, ) diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_get.go b/internal/app/enaptercli/cmd_rule_engine_rule_get.go index abf31f1..5ff57ea 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_get.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_get.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleGet struct { @@ -20,8 +20,8 @@ func buildCmdRuleEngineRuleGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_list.go b/internal/app/enaptercli/cmd_rule_engine_rule_list.go index cb1de8e..4049959 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_list.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_list.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleList struct { @@ -19,8 +19,8 @@ func buildCmdRuleEngineRuleList() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_logs.go b/internal/app/enaptercli/cmd_rule_engine_rule_logs.go index 6e328ee..17957e4 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_logs.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_logs.go @@ -1,12 +1,13 @@ package enaptercli import ( + "context" "encoding/json" "fmt" "io" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleLogs struct { @@ -23,8 +24,8 @@ func buildCmdRuleEngineRuleLogs() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -46,14 +47,14 @@ func (c *cmdRuleEngineRuleLogs) Flags() []cli.Flag { ) } -func (c *cmdRuleEngineRuleLogs) do(cliCtx *cli.Context) error { +func (c *cmdRuleEngineRuleLogs) do(ctx context.Context) error { if !c.follow { return cli.Exit("Currently, only follow mode (--follow) is supported.", 1) } path := fmt.Sprintf("/site/rule_engine/rules/%s/logs", c.ruleID) - return c.runWebSocket(cliCtx.Context, runWebSocketParams{ + return c.runWebSocket(ctx, runWebSocketParams{ Path: path, RespProcessor: func(r io.Reader) error { var msg struct { diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_update.go b/internal/app/enaptercli/cmd_rule_engine_rule_update.go index 9009ec6..d2d7974 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_update.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_update.go @@ -2,11 +2,12 @@ package enaptercli import ( "bytes" + "context" "encoding/json" "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineRuleUpdate struct { @@ -23,8 +24,8 @@ func buildCmdRuleEngineRuleUpdate() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx) + Action: func(ctx context.Context, cliCmd *cli.Command) error { + return cmd.do(ctx, cliCmd) }, } } @@ -45,10 +46,10 @@ func (c *cmdRuleEngineRuleUpdate) Flags() []cli.Flag { ) } -func (c *cmdRuleEngineRuleUpdate) do(cliCtx *cli.Context) error { +func (c *cmdRuleEngineRuleUpdate) do(ctx context.Context, cliCmd *cli.Command) error { payload := make(map[string]any) - if cliCtx.IsSet("slug") { + if cliCmd.IsSet("slug") { payload["slug"] = c.slug } @@ -57,7 +58,7 @@ func (c *cmdRuleEngineRuleUpdate) do(cliCtx *cli.Context) error { return fmt.Errorf("build request: %w", err) } - return c.doHTTPRequest(cliCtx.Context, doHTTPRequestParams{ + return c.doHTTPRequest(ctx, doHTTPRequestParams{ Method: http.MethodPatch, Path: "/" + c.ruleID, Body: bytes.NewReader(body), diff --git a/internal/app/enaptercli/cmd_rule_engine_rule_update_script.go b/internal/app/enaptercli/cmd_rule_engine_rule_update_script.go index 9e1ee24..69375a0 100644 --- a/internal/app/enaptercli/cmd_rule_engine_rule_update_script.go +++ b/internal/app/enaptercli/cmd_rule_engine_rule_update_script.go @@ -10,7 +10,7 @@ import ( "os" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/enapter/enapter-cli/internal/app/cliflags" ) @@ -31,8 +31,8 @@ func buildCmdRuleEngineRuleUpdateScript() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } @@ -56,7 +56,7 @@ func (c *cmdRuleEngineRuleUpdateScript) Flags() []cli.Flag { Usage: "Version of the runtime to use for the script execution", Destination: &c.runtimeVersion, Value: ruleRuntimeV3, - Action: func(_ *cli.Context, v string) error { + Action: func(_ context.Context, _ *cli.Command, v string) error { return c.validateRuntimeVersion(v) }, }, diff --git a/internal/app/enaptercli/cmd_rule_engine_suspend.go b/internal/app/enaptercli/cmd_rule_engine_suspend.go index 5637e48..57d9b43 100644 --- a/internal/app/enaptercli/cmd_rule_engine_suspend.go +++ b/internal/app/enaptercli/cmd_rule_engine_suspend.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdRuleEngineSuspend struct { @@ -19,8 +19,8 @@ func buildCmdRuleEngineSuspend() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_site.go b/internal/app/enaptercli/cmd_site.go index 75fc336..1acd92a 100644 --- a/internal/app/enaptercli/cmd_site.go +++ b/internal/app/enaptercli/cmd_site.go @@ -5,7 +5,7 @@ import ( "fmt" "net/url" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdSite struct { @@ -18,7 +18,7 @@ func buildCmdSite() *cli.Command { Name: "site", Usage: "Manage sites", CustomHelpTemplate: cmd.SubcommandHelpTemplate(), - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ buildCmdSiteList(), buildCmdSiteGet(), }, diff --git a/internal/app/enaptercli/cmd_site_get.go b/internal/app/enaptercli/cmd_site_get.go index 168b786..c884155 100644 --- a/internal/app/enaptercli/cmd_site_get.go +++ b/internal/app/enaptercli/cmd_site_get.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdSiteGet struct { @@ -20,8 +20,8 @@ func buildCmdSiteGet() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/cmd_site_list.go b/internal/app/enaptercli/cmd_site_list.go index f134f89..a238b08 100644 --- a/internal/app/enaptercli/cmd_site_list.go +++ b/internal/app/enaptercli/cmd_site_list.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type cmdSiteList struct { @@ -23,8 +23,8 @@ func buildCmdSiteList() *cli.Command { CustomHelpTemplate: cmd.CommandHelpTemplate(), Flags: cmd.Flags(), Before: cmd.Before, - Action: func(cliCtx *cli.Context) error { - return cmd.do(cliCtx.Context) + Action: func(ctx context.Context, _ *cli.Command) error { + return cmd.do(ctx) }, } } diff --git a/internal/app/enaptercli/execute.go b/internal/app/enaptercli/execute.go index 8010ce4..ddeb59d 100644 --- a/internal/app/enaptercli/execute.go +++ b/internal/app/enaptercli/execute.go @@ -8,19 +8,29 @@ import ( "io/fs" "os" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // NewApp creates a new Enapter CLI tool application instance. -func NewApp() *cli.App { - app := cli.NewApp() +func NewApp() *cli.Command { + cmd := &cli.Command{} - app.Usage = "Command Line Interface (CLI) for Enapter services." - app.Description = "The Enapter CLI requires an access token for authentication. " + + cmd.Name = "enapter3" + cmd.Usage = "Command Line Interface (CLI) for Enapter services." + cmd.Description = "The Enapter CLI requires an access token for authentication. " + "You can obtain the token in your Enapter Cloud account settings." - app.CustomAppHelpTemplate = cli.AppHelpTemplate + enapterAPIEnvVarsHelp + cmd.CustomRootCommandHelpTemplate = cli.RootCommandHelpTemplate + enapterAPIEnvVarsHelp - app.Commands = []*cli.Command{ + cli.ShowSubcommandHelp = func(cmd *cli.Command) error { + tmpl := cmd.CustomHelpTemplate + if tmpl == "" { + tmpl = cli.SubcommandHelpTemplate + } + cli.HelpPrinter(cmd.Root().Writer, tmpl, cmd) + return nil + } + + cmd.Commands = []*cli.Command{ buildCmdSite(), buildCmdDevice(), buildCmdBlueprint(), @@ -28,7 +38,7 @@ func NewApp() *cli.App { buildCmdConnection(), } - return app + return cmd } func zipDir(path string) ([]byte, error) { diff --git a/internal/app/enaptercli/testdata/helps/enapter b/internal/app/enaptercli/testdata/helps/enapter index d5e7165..08600cf 100644 --- a/internal/app/enaptercli/testdata/helps/enapter +++ b/internal/app/enaptercli/testdata/helps/enapter @@ -1,8 +1,8 @@ NAME: - enaptercli.test - Command Line Interface (CLI) for Enapter services. + enapter3 - Command Line Interface (CLI) for Enapter services. USAGE: - enaptercli.test [global options] command [command options] + enapter3 [global options] [command [command options]] DESCRIPTION: The Enapter CLI requires an access token for authentication. You can obtain the token in your Enapter Cloud account settings. diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint b/internal/app/enaptercli/testdata/helps/enapter blueprint index 3aaec8a..22253cc 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint @@ -1,15 +1,14 @@ NAME: - enaptercli.test blueprint - Manage blueprints + enapter3 blueprint - Manage blueprints USAGE: - enaptercli.test blueprint command [command options] + enapter3 blueprint [command [command options]] COMMANDS: profiles Manage blueprint profiles upload Upload the blueprint to the Platform download Download the blueprint zip from the Platform get Retrieve blueprint metadata - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint download b/internal/app/enaptercli/testdata/helps/enapter blueprint download index e64d496..2cd50b6 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint download +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint download @@ -1,16 +1,16 @@ NAME: - enaptercli.test blueprint download - Download the blueprint zip from the Platform + enapter3 blueprint download - Download the blueprint zip from the Platform USAGE: - enaptercli.test blueprint download [command options] + enapter3 blueprint download [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --blueprint-id value, -b value Blueprint name or ID to download - --output value, -o value Blueprint file name to save the blueprint - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --blueprint-id string, -b string Blueprint name or ID to download + --output string, -o string Blueprint file name to save the blueprint + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint get b/internal/app/enaptercli/testdata/helps/enapter blueprint get index d1dc661..a7a2bd9 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint get +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint get @@ -1,15 +1,15 @@ NAME: - enaptercli.test blueprint get - Retrieve blueprint metadata + enapter3 blueprint get - Retrieve blueprint metadata USAGE: - enaptercli.test blueprint get [command options] + enapter3 blueprint get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --blueprint-id value, -b value blueprint name or ID to retrieve - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --blueprint-id string, -b string blueprint name or ID to retrieve + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles index 3b84606..f98bb65 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles @@ -1,13 +1,12 @@ NAME: - enaptercli.test blueprint profiles - Manage blueprint profiles + enapter3 blueprint profiles - Manage blueprint profiles USAGE: - enaptercli.test blueprint profiles command [command options] + enapter3 blueprint profiles [command [command options]] COMMANDS: download Download profiles zip from the Platform upload Upload profiles to the Platform - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles download b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles download index e6d96e2..2f741f9 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles download +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles download @@ -1,15 +1,15 @@ NAME: - enaptercli.test blueprint profiles download - Download profiles zip from the Platform + enapter3 blueprint profiles download - Download profiles zip from the Platform USAGE: - enaptercli.test blueprint profiles download [command options] + enapter3 blueprint profiles download [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --output value, -o value File name to save the downloaded profiles - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --output string, -o string File name to save the downloaded profiles + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles upload b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles upload index bc72b62..bb5acc0 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint profiles upload +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint profiles upload @@ -1,15 +1,15 @@ NAME: - enaptercli.test blueprint profiles upload - Upload profiles to the Platform + enapter3 blueprint profiles upload - Upload profiles to the Platform USAGE: - enaptercli.test blueprint profiles upload [command options] + enapter3 blueprint profiles upload [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --path value, -p value Profiles zip file path - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --path string, -p string Profiles zip file path + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter blueprint upload b/internal/app/enaptercli/testdata/helps/enapter blueprint upload index 72aa08d..f0b6363 100644 --- a/internal/app/enaptercli/testdata/helps/enapter blueprint upload +++ b/internal/app/enaptercli/testdata/helps/enapter blueprint upload @@ -1,15 +1,15 @@ NAME: - enaptercli.test blueprint upload - Upload the blueprint to the Platform + enapter3 blueprint upload - Upload the blueprint to the Platform USAGE: - enaptercli.test blueprint upload [command options] + enapter3 blueprint upload [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --path value, -p value Blueprint path (zip file or directory) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --path string, -p string Blueprint path (zip file or directory) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter connection b/internal/app/enaptercli/testdata/helps/enapter connection index 8438469..90aed4a 100644 --- a/internal/app/enaptercli/testdata/helps/enapter connection +++ b/internal/app/enaptercli/testdata/helps/enapter connection @@ -1,15 +1,14 @@ NAME: - enaptercli.test connection - Manage connections to Enapter Cloud and Gateways + enapter3 connection - Manage connections to Enapter Cloud and Gateways USAGE: - enaptercli.test connection command [command options] + enapter3 connection [command [command options]] COMMANDS: add Add a new connection remove Remove a connection list List all connections set-default Set default connection - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter connection add b/internal/app/enaptercli/testdata/helps/enapter connection add index 3a2d618..06da1a4 100644 --- a/internal/app/enaptercli/testdata/helps/enapter connection add +++ b/internal/app/enaptercli/testdata/helps/enapter connection add @@ -1,14 +1,14 @@ NAME: - enaptercli.test connection add - Add a new connection + enapter3 connection add - Add a new connection USAGE: - enaptercli.test connection add [command options] + enapter3 connection add [options] OPTIONS: - --name value Connection name - --gateway Indicates that the connection is to a Gateway (default: false) - --url value Enapter API base URL (default: "https://api.enapter.com") - --token value Enapter API access token - --site-id value If specified, the connection will be limited to this site (available only for Cloud connections) - --allow-insecure Allow insecure connections to the Enapter API (default: false) + --name string Connection name + --gateway Indicates that the connection is to a Gateway + --url string Enapter API base URL (default: "https://api.enapter.com") + --token string Enapter API access token + --site-id string If specified, the connection will be limited to this site (available only for Cloud connections) + --allow-insecure Allow insecure connections to the Enapter API --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter connection list b/internal/app/enaptercli/testdata/helps/enapter connection list index 84afb87..322b98e 100644 --- a/internal/app/enaptercli/testdata/helps/enapter connection list +++ b/internal/app/enaptercli/testdata/helps/enapter connection list @@ -1,8 +1,8 @@ NAME: - enaptercli.test connection list - List all connections + enapter3 connection list - List all connections USAGE: - enaptercli.test connection list [command options] + enapter3 connection list [options] OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter connection remove b/internal/app/enaptercli/testdata/helps/enapter connection remove index 37f218c..f40b8c8 100644 --- a/internal/app/enaptercli/testdata/helps/enapter connection remove +++ b/internal/app/enaptercli/testdata/helps/enapter connection remove @@ -1,9 +1,9 @@ NAME: - enaptercli.test connection remove - Remove a connection + enapter3 connection remove - Remove a connection USAGE: - enaptercli.test connection remove [command options] + enapter3 connection remove [options] OPTIONS: - --name value Connection name - --help, -h show help + --name string Connection name + --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter connection set-default b/internal/app/enaptercli/testdata/helps/enapter connection set-default index 255a0c0..0123512 100644 --- a/internal/app/enaptercli/testdata/helps/enapter connection set-default +++ b/internal/app/enaptercli/testdata/helps/enapter connection set-default @@ -1,9 +1,9 @@ NAME: - enaptercli.test connection set-default - Set default connection + enapter3 connection set-default - Set default connection USAGE: - enaptercli.test connection set-default [command options] + enapter3 connection set-default [options] OPTIONS: - --name value Connection name - --help, -h show help + --name string Connection name + --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter device b/internal/app/enaptercli/testdata/helps/enapter device index 3fa1bcd..7b18f6b 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device +++ b/internal/app/enaptercli/testdata/helps/enapter device @@ -1,8 +1,8 @@ NAME: - enaptercli.test device - Manage devices + enapter3 device - Manage devices USAGE: - enaptercli.test device command [command options] + enapter3 device [command [command options]] COMMANDS: create Create devices of different types @@ -17,7 +17,6 @@ COMMANDS: monitor Monitor device traffic communication-config Manage device communication config run-terminal Run new remote terminal session - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter device change-blueprint b/internal/app/enaptercli/testdata/helps/enapter device change-blueprint index 85a2f79..e96c1cf 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device change-blueprint +++ b/internal/app/enaptercli/testdata/helps/enapter device change-blueprint @@ -1,18 +1,18 @@ NAME: - enaptercli.test device change-blueprint - Change device blueprint + enapter3 device change-blueprint - Change device blueprint USAGE: - enaptercli.test device change-blueprint [command options] + enapter3 device change-blueprint [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --blueprint-id value, -b value blueprint ID to use as new device blueprint - --blueprint-path value blueprint path (zip file or directory) to use as new device blueprint - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --blueprint-id string, -b string blueprint ID to use as new device blueprint + --blueprint-path string blueprint path (zip file or directory) to use as new device blueprint + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device command b/internal/app/enaptercli/testdata/helps/enapter device command index 6510b1b..ec3976f 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device command +++ b/internal/app/enaptercli/testdata/helps/enapter device command @@ -1,14 +1,13 @@ NAME: - enaptercli.test device command - Manage device commands + enapter3 device command - Manage device commands USAGE: - enaptercli.test device command command [command options] + enapter3 device command [command [command options]] COMMANDS: execute Execute a device command list List device command executions get Retrieve a device command execution - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter device command execute b/internal/app/enaptercli/testdata/helps/enapter device command execute index 1c13060..5024b86 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device command execute +++ b/internal/app/enaptercli/testdata/helps/enapter device command execute @@ -1,18 +1,18 @@ NAME: - enaptercli.test device command execute - Execute a device command + enapter3 device command execute - Execute a device command USAGE: - enaptercli.test device command execute [command options] + enapter3 device command execute [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --name value Command name - --arguments value Command arguments (should be a JSON string) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --name string Command name + --arguments string Command arguments (should be a JSON string) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device command get b/internal/app/enaptercli/testdata/helps/enapter device command get index eef98c2..905e822 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device command get +++ b/internal/app/enaptercli/testdata/helps/enapter device command get @@ -1,18 +1,18 @@ NAME: - enaptercli.test device command get - Retrieve a device command execution + enapter3 device command get - Retrieve a device command execution USAGE: - enaptercli.test device command get [command options] + enapter3 device command get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --execution-id value Execution ID - --expand value [ --expand value ] Comma-separated list of expanded options (supported values: log) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --execution-id string Execution ID + --expand string [ --expand string ] Comma-separated list of expanded options (supported values: log) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device command list b/internal/app/enaptercli/testdata/helps/enapter device command list index ff517b4..0143579 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device command list +++ b/internal/app/enaptercli/testdata/helps/enapter device command list @@ -1,16 +1,16 @@ NAME: - enaptercli.test device command list - List device command executions + enapter3 device command list - List device command executions USAGE: - enaptercli.test device command list [command options] + enapter3 device command list [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device communication-config b/internal/app/enaptercli/testdata/helps/enapter device communication-config index 6593730..82c3ad2 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device communication-config +++ b/internal/app/enaptercli/testdata/helps/enapter device communication-config @@ -1,12 +1,11 @@ NAME: - enaptercli.test device communication-config - Manage device communication config + enapter3 device communication-config - Manage device communication config USAGE: - enaptercli.test device communication-config command [command options] + enapter3 device communication-config [command [command options]] COMMANDS: generate Generate a new communication config for device - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter device communication-config generate b/internal/app/enaptercli/testdata/helps/enapter device communication-config generate index de996d4..0aa1088 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device communication-config generate +++ b/internal/app/enaptercli/testdata/helps/enapter device communication-config generate @@ -1,17 +1,17 @@ NAME: - enaptercli.test device communication-config generate - Generate a new communication config for device + enapter3 device communication-config generate - Generate a new communication config for device USAGE: - enaptercli.test device communication-config generate [command options] + enapter3 device communication-config generate [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --protocol value Connection protocol (supported values: MQTT, MQTTS) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --protocol string Connection protocol (supported values: MQTT, MQTTS) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device create b/internal/app/enaptercli/testdata/helps/enapter device create index 8b6082c..b8f8e59 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device create +++ b/internal/app/enaptercli/testdata/helps/enapter device create @@ -1,13 +1,12 @@ NAME: - enaptercli.test device create - Create devices of different types + enapter3 device create - Create devices of different types USAGE: - enaptercli.test device create command [command options] + enapter3 device create [command [command options]] COMMANDS: standalone Create a new standalone device lua-device Create a new Lua device - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter device create lua-device b/internal/app/enaptercli/testdata/helps/enapter device create lua-device index 49cffad..0175065 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device create lua-device +++ b/internal/app/enaptercli/testdata/helps/enapter device create lua-device @@ -1,20 +1,20 @@ NAME: - enaptercli.test device create lua-device - Create a new Lua device + enapter3 device create lua-device - Create a new Lua device USAGE: - enaptercli.test device create lua-device [command options] + enapter3 device create lua-device [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --runtime-id value, -r value UCM device ID where the new Lua device will run - --device-name value, -n value name for the new Lua device - --device-slug value slug for the new Lua device - --blueprint-id value, -b value blueprint ID to use for the new Lua device - --blueprint-path value Blueprint path (zip file or directory) to use for the new Lua device - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --runtime-id string, -r string UCM device ID where the new Lua device will run + --device-name string, -n string name for the new Lua device + --device-slug string slug for the new Lua device + --blueprint-id string, -b string blueprint ID to use for the new Lua device + --blueprint-path string Blueprint path (zip file or directory) to use for the new Lua device + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device create standalone b/internal/app/enaptercli/testdata/helps/enapter device create standalone index fef4556..947b8a4 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device create standalone +++ b/internal/app/enaptercli/testdata/helps/enapter device create standalone @@ -1,17 +1,17 @@ NAME: - enaptercli.test device create standalone - Create a new standalone device + enapter3 device create standalone - Create a new standalone device USAGE: - enaptercli.test device create standalone [command options] + enapter3 device create standalone [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value, -s value Site ID where the device will be created - --device-name value, -n value Name for the new device - --device-slug value Slug for the new standalone device - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string, -s string Site ID where the device will be created + --device-name string, -n string Name for the new device + --device-slug string Slug for the new standalone device + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device delete b/internal/app/enaptercli/testdata/helps/enapter device delete index b138c29..09f1aa1 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device delete +++ b/internal/app/enaptercli/testdata/helps/enapter device delete @@ -1,16 +1,16 @@ NAME: - enaptercli.test device delete - Delete a device + enapter3 device delete - Delete a device USAGE: - enaptercli.test device delete [command options] + enapter3 device delete [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device get b/internal/app/enaptercli/testdata/helps/enapter device get index 0045f4e..bc99259 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device get +++ b/internal/app/enaptercli/testdata/helps/enapter device get @@ -1,17 +1,17 @@ NAME: - enaptercli.test device get - Retrieve device information + enapter3 device get - Retrieve device information USAGE: - enaptercli.test device get [command options] + enapter3 device get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --expand value [ --expand value ] Comma-separated list of expanded device information (supported values: connectivity, manifest, properties, communication, site) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --expand string [ --expand string ] Comma-separated list of expanded device information (supported values: connectivity, manifest, properties, communication, site) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device list b/internal/app/enaptercli/testdata/helps/enapter device list index eafcda0..d601b39 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device list +++ b/internal/app/enaptercli/testdata/helps/enapter device list @@ -1,17 +1,17 @@ NAME: - enaptercli.test device list - List user devices ordered by device ID + enapter3 device list - List user devices ordered by device ID USAGE: - enaptercli.test device list [command options] + enapter3 device list [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --expand value [ --expand value ] Comma-separated list of expanded device information (supported values: connectivity, manifest, properties, communication, site) - --limit value maximum number of devices to retrieve (default: retrieves all) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --expand string [ --expand string ] Comma-separated list of expanded device information (supported values: connectivity, manifest, properties, communication, site) + --limit int maximum number of devices to retrieve (default: retrieves all) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device logs b/internal/app/enaptercli/testdata/helps/enapter device logs index 1466fa1..1d55201 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device logs +++ b/internal/app/enaptercli/testdata/helps/enapter device logs @@ -1,24 +1,24 @@ NAME: - enaptercli.test device logs - Show device logs + enapter3 device logs - Show device logs USAGE: - enaptercli.test device logs [command options] + enapter3 device logs [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --follow, -f Follow the log output (default: false) - --received-at-gte value From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z) - --received-at-lt value To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z) - --limit value, -l value Maximum number of logs to retrieve (default: 0) - --offset value, -o value Number of logs to skip when retrieving (default: 0) - --severity value, -s value Filter logs by severity - --order value Order logs by criteria (RECEIVED_AT_ASC[default], RECEIVED_AT_DESC) - --retention value Filter logs by retention (ALL[default], PERSISTENT, EPHEMERAL) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --follow, -f Follow the log output + --received-at-gte time From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z) + --received-at-lt time To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z) + --limit int, -l int Maximum number of logs to retrieve (default: 0) + --offset int, -o int Number of logs to skip when retrieving (default: 0) + --severity string, -s string Filter logs by severity + --order string Order logs by criteria (RECEIVED_AT_ASC[default], RECEIVED_AT_DESC) + --retention string Filter logs by retention (ALL[default], PERSISTENT, EPHEMERAL) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device monitor b/internal/app/enaptercli/testdata/helps/enapter device monitor index c4c7a1d..943d6ed 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device monitor +++ b/internal/app/enaptercli/testdata/helps/enapter device monitor @@ -1,17 +1,17 @@ NAME: - enaptercli.test device monitor - Monitor device traffic + enapter3 device monitor - Monitor device traffic USAGE: - enaptercli.test device monitor [command options] + enapter3 device monitor [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --include-runtime Monitor device's runtime traffic too (default: false) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --include-runtime Monitor device's runtime traffic too + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device run-terminal b/internal/app/enaptercli/testdata/helps/enapter device run-terminal index 6402b26..a562248 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device run-terminal +++ b/internal/app/enaptercli/testdata/helps/enapter device run-terminal @@ -1,19 +1,19 @@ NAME: - enaptercli.test device run-terminal - Run new remote terminal session + enapter3 device run-terminal - Run new remote terminal session USAGE: - enaptercli.test device run-terminal [command options] + enapter3 device run-terminal [options] DESCRIPTION: Remote terminal feature should be enabled in gateway settings. Use Ctrl+] sequence to force connection close. OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Gateway device ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Gateway device ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device telemetry b/internal/app/enaptercli/testdata/helps/enapter device telemetry index 77b61dc..34ff212 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device telemetry +++ b/internal/app/enaptercli/testdata/helps/enapter device telemetry @@ -1,17 +1,17 @@ NAME: - enaptercli.test device telemetry - Show device telemetry + enapter3 device telemetry - Show device telemetry USAGE: - enaptercli.test device telemetry [command options] + enapter3 device telemetry [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --follow, -f Follow the telemetry output (default: false) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --follow, -f Follow the telemetry output + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter device update b/internal/app/enaptercli/testdata/helps/enapter device update index 6846a93..4f16b52 100644 --- a/internal/app/enaptercli/testdata/helps/enapter device update +++ b/internal/app/enaptercli/testdata/helps/enapter device update @@ -1,18 +1,18 @@ NAME: - enaptercli.test device update - Update a device + enapter3 device update - Update a device USAGE: - enaptercli.test device update [command options] + enapter3 device update [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --device-id value, -d value Device ID - --name value Device name - --slug value Device slug - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --device-id string, -d string Device ID + --name string Device name + --slug string Device slug + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine b/internal/app/enaptercli/testdata/helps/enapter rule-engine index 182711a..2ae91b2 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine @@ -1,15 +1,14 @@ NAME: - enaptercli.test rule-engine - Manage the rule engine + enapter3 rule-engine - Manage the rule engine USAGE: - enaptercli.test rule-engine command [command options] + enapter3 rule-engine [command [command options]] COMMANDS: get Retrieve the rule engine suspend Suspend execution of rules resume Resume execution of rules rule Manage rules - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine get b/internal/app/enaptercli/testdata/helps/enapter rule-engine get index 1f1ef7d..f8e5f6e 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine get +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine get @@ -1,15 +1,15 @@ NAME: - enaptercli.test rule-engine get - Retrieve the rule engine + enapter3 rule-engine get - Retrieve the rule engine USAGE: - enaptercli.test rule-engine get [command options] + enapter3 rule-engine get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine resume b/internal/app/enaptercli/testdata/helps/enapter rule-engine resume index c5d2184..8c122bc 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine resume +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine resume @@ -1,15 +1,15 @@ NAME: - enaptercli.test rule-engine resume - Resume execution of rules + enapter3 rule-engine resume - Resume execution of rules USAGE: - enaptercli.test rule-engine resume [command options] + enapter3 rule-engine resume [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule index 3e60cf8..2623358 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule @@ -1,8 +1,8 @@ NAME: - enaptercli.test rule-engine rule - Manage rules + enapter3 rule-engine rule - Manage rules USAGE: - enaptercli.test rule-engine rule command [command options] + enapter3 rule-engine rule [command [command options]] COMMANDS: create Create a new rule @@ -14,7 +14,6 @@ COMMANDS: update Update a rule update-script Update the script of a rule logs Show rule logs - help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule create b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule create index c7568b1..2965dc7 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule create +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule create @@ -1,20 +1,20 @@ NAME: - enaptercli.test rule-engine rule create - Create a new rule + enapter3 rule-engine rule create - Create a new rule USAGE: - enaptercli.test rule-engine rule create [command options] + enapter3 rule-engine rule create [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --slug value Slug for the new rule - --script value Path to the file containing the script code - --runtime-version value Version of the runtime to use for the script execution (default: "V3") - --exec-interval value How frequently to execute the script (compatible only with runtime version 1) in duration format (e.g., 5s, 2m) - --disable Disable the rule upon creation (default: false) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --slug string Slug for the new rule + --script string Path to the file containing the script code + --runtime-version string Version of the runtime to use for the script execution (default: "V3") + --exec-interval duration How frequently to execute the script (compatible only with runtime version 1) in duration format (e.g., 5s, 2m) (default: 0s) + --disable Disable the rule upon creation + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule delete b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule delete index abfe916..5b7e9a1 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule delete +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule delete @@ -1,16 +1,16 @@ NAME: - enaptercli.test rule-engine rule delete - Delete a rule + enapter3 rule-engine rule delete - Delete a rule USAGE: - enaptercli.test rule-engine rule delete [command options] + enapter3 rule-engine rule delete [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value Rule ID or slug - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string Rule ID or slug + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule disable b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule disable index cee4257..56ed9e7 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule disable +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule disable @@ -1,16 +1,16 @@ NAME: - enaptercli.test rule-engine rule disable - Disable one or more rules + enapter3 rule-engine rule disable - Disable one or more rules USAGE: - enaptercli.test rule-engine rule disable [command options] + enapter3 rule-engine rule disable [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value [ --rule-id value ] Rule IDs or slugs - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string [ --rule-id string ] Rule IDs or slugs + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule enable b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule enable index e72fb26..b8e2012 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule enable +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule enable @@ -1,16 +1,16 @@ NAME: - enaptercli.test rule-engine rule enable - Enable one or more rules + enapter3 rule-engine rule enable - Enable one or more rules USAGE: - enaptercli.test rule-engine rule enable [command options] + enapter3 rule-engine rule enable [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value [ --rule-id value ] Rule IDs or slugs - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string [ --rule-id string ] Rule IDs or slugs + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule get b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule get index d1c2ddd..15a00f4 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule get +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule get @@ -1,16 +1,16 @@ NAME: - enaptercli.test rule-engine rule get - Retrieve a rule + enapter3 rule-engine rule get - Retrieve a rule USAGE: - enaptercli.test rule-engine rule get [command options] + enapter3 rule-engine rule get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value Rule ID or slug - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string Rule ID or slug + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule list b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule list index b35ffb9..e5ac7f7 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule list +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule list @@ -1,15 +1,15 @@ NAME: - enaptercli.test rule-engine rule list - List rules + enapter3 rule-engine rule list - List rules USAGE: - enaptercli.test rule-engine rule list [command options] + enapter3 rule-engine rule list [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule logs b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule logs index bcbb41c..ad28a33 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule logs +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule logs @@ -1,17 +1,17 @@ NAME: - enaptercli.test rule-engine rule logs - Show rule logs + enapter3 rule-engine rule logs - Show rule logs USAGE: - enaptercli.test rule-engine rule logs [command options] + enapter3 rule-engine rule logs [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value rule ID - --follow, -f follow the log output (default: false) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string rule ID + --follow, -f follow the log output + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update index ddb7a08..2538272 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update @@ -1,17 +1,17 @@ NAME: - enaptercli.test rule-engine rule update - Update a rule + enapter3 rule-engine rule update - Update a rule USAGE: - enaptercli.test rule-engine rule update [command options] + enapter3 rule-engine rule update [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value Rule ID or slug to update - --slug value A new rule slug - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string Rule ID or slug to update + --slug string A new rule slug + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update-script b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update-script index d3b9479..dcd81d0 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update-script +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine rule update-script @@ -1,19 +1,19 @@ NAME: - enaptercli.test rule-engine rule update-script - Update the script of a rule + enapter3 rule-engine rule update-script - Update the script of a rule USAGE: - enaptercli.test rule-engine rule update-script [command options] + enapter3 rule-engine rule update-script [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --rule-id value Rule ID or slug to update - --script value Path to a file containing the script code - --runtime-version value Version of the runtime to use for the script execution (default: "V3") - --exec-interval value How frequently to execute the script (compatible only with runtime version 1) in duration format (e.g., 5s, 2m) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --rule-id string Rule ID or slug to update + --script string Path to a file containing the script code + --runtime-version string Version of the runtime to use for the script execution (default: "V3") + --exec-interval duration How frequently to execute the script (compatible only with runtime version 1) in duration format (e.g., 5s, 2m) (default: 0s) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter rule-engine suspend b/internal/app/enaptercli/testdata/helps/enapter rule-engine suspend index d0d02d3..4d95226 100644 --- a/internal/app/enaptercli/testdata/helps/enapter rule-engine suspend +++ b/internal/app/enaptercli/testdata/helps/enapter rule-engine suspend @@ -1,15 +1,15 @@ NAME: - enaptercli.test rule-engine suspend - Suspend execution of rules + enapter3 rule-engine suspend - Suspend execution of rules USAGE: - enaptercli.test rule-engine suspend [command options] + enapter3 rule-engine suspend [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter site b/internal/app/enaptercli/testdata/helps/enapter site index 20ca425..50303ca 100644 --- a/internal/app/enaptercli/testdata/helps/enapter site +++ b/internal/app/enaptercli/testdata/helps/enapter site @@ -1,13 +1,12 @@ NAME: - enaptercli.test site - Manage sites + enapter3 site - Manage sites USAGE: - enaptercli.test site command [command options] + enapter3 site [command [command options]] COMMANDS: - list List user sites - get Get a site - help, h Shows a list of commands or help for one command + list List user sites + get Get a site OPTIONS: --help, -h show help diff --git a/internal/app/enaptercli/testdata/helps/enapter site get b/internal/app/enaptercli/testdata/helps/enapter site get index eeccfe8..ec0b156 100644 --- a/internal/app/enaptercli/testdata/helps/enapter site get +++ b/internal/app/enaptercli/testdata/helps/enapter site get @@ -1,15 +1,15 @@ NAME: - enaptercli.test site get - Get a site + enapter3 site get - Get a site USAGE: - enaptercli.test site get [command options] + enapter3 site get [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --site-id value Site ID - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --site-id string Site ID + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token diff --git a/internal/app/enaptercli/testdata/helps/enapter site list b/internal/app/enaptercli/testdata/helps/enapter site list index 9fabe3c..9f5bd26 100644 --- a/internal/app/enaptercli/testdata/helps/enapter site list +++ b/internal/app/enaptercli/testdata/helps/enapter site list @@ -1,16 +1,16 @@ NAME: - enaptercli.test site list - List user sites + enapter3 site list - List user sites USAGE: - enaptercli.test site list [command options] + enapter3 site list [options] OPTIONS: - --connection value, -c value Name of the connection to use [$ENAPTER3_CONNECTION] - --api-allow-insecure Allow insecure connections to the Enapter API (default: false) [$ENAPTER3_API_ALLOW_INSECURE] - --verbose Log extra details about the operation (default: false) - --my-sites Returns only sites where user is owner or installer (default: false) - --limit value Maximum number of sites to retrieve (default: retrieves all) - --help, -h show help + --connection string, -c string Name of the connection to use [$ENAPTER3_CONNECTION] + --api-allow-insecure Allow insecure connections to the Enapter API [$ENAPTER3_API_ALLOW_INSECURE] + --verbose Log extra details about the operation + --my-sites Returns only sites where user is owner or installer + --limit int Maximum number of sites to retrieve (default: retrieves all) + --help, -h show help ENVIRONMENT VARIABLES: ENAPTER3_API_TOKEN Enapter API access token From 82ee2c0875f5d2ff71c3de5a7cc060ad1bfc3598 Mon Sep 17 00:00:00 2001 From: Aleksey Bakin Date: Thu, 16 Apr 2026 13:00:55 +0300 Subject: [PATCH 2/2] feat: support .blueprintignore --- bp/firmware.lua | 1 + bp/manifest.yml | 7 ++ go.mod | 6 ++ go.sum | 23 +++++- internal/app/enaptercli/execute.go | 73 ++++++++++++++++++- internal/app/enaptercli/execute_test.go | 5 ++ .../blueprints/with_ignore/.blueprintignore | 5 ++ .../blueprints/with_ignore/build/output.bin | 1 + .../testdata/blueprints/with_ignore/debug.log | 1 + .../blueprints/with_ignore/firmware.lua | 1 + .../blueprints/with_ignore/manifest.yml | 7 ++ .../cmd.tmpl | 2 + .../blueprint_upload_with_blueprintignore/out | 1 + .../req_0 | 22 ++++++ .../resp_0 | 1 + .../device_change_blueprint_by_path/req_0 | 2 +- 16 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 bp/firmware.lua create mode 100644 bp/manifest.yml create mode 100644 internal/app/enaptercli/testdata/blueprints/with_ignore/.blueprintignore create mode 100644 internal/app/enaptercli/testdata/blueprints/with_ignore/build/output.bin create mode 100644 internal/app/enaptercli/testdata/blueprints/with_ignore/debug.log create mode 100644 internal/app/enaptercli/testdata/blueprints/with_ignore/firmware.lua create mode 100644 internal/app/enaptercli/testdata/blueprints/with_ignore/manifest.yml create mode 100644 internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/cmd.tmpl create mode 100644 internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/out create mode 100644 internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/req_0 create mode 100644 internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/resp_0 diff --git a/bp/firmware.lua b/bp/firmware.lua new file mode 100644 index 0000000..aa6fd65 --- /dev/null +++ b/bp/firmware.lua @@ -0,0 +1 @@ +enapter.log("Hello from firmware.lua") diff --git a/bp/manifest.yml b/bp/manifest.yml new file mode 100644 index 0000000..fc8f08a --- /dev/null +++ b/bp/manifest.yml @@ -0,0 +1,7 @@ +blueprint_spec: device/3.0 +display_name: Simple Lua + +runtime: + type: lua + options: + file: firmware.lua diff --git a/go.mod b/go.mod index dc384cb..ab7ab2b 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/enapter/enapter-cli go 1.24.0 require ( + github.com/go-git/go-git/v5 v5.17.2 github.com/gorilla/websocket v1.5.3 github.com/stretchr/testify v1.11.1 github.com/urfave/cli/v3 v3.7.0 @@ -11,7 +12,12 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.8.0 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/net v0.47.0 // indirect golang.org/x/sys v0.38.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f357b29..c55b3e1 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,39 @@ 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/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.8.0 h1:I8hjc3LbBlXTtVuFNJuwYuMiHvQJDq1AT6u4DwDzZG0= +github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5SqfmrrheCY= +github.com/go-git/go-git/v5 v5.17.2 h1:B+nkdlxdYrvyFK4GPXVU8w1U+YkbsgciIR7f2sZJ104= +github.com/go-git/go-git/v5 v5.17.2/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/urfave/cli/v3 v3.7.0 h1:AGSnbUyjtLiM+WJUb4dzXKldl/gL+F8OwmRDtVr6g2U= github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU= golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= 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/app/enaptercli/execute.go b/internal/app/enaptercli/execute.go index ddeb59d..3da99ae 100644 --- a/internal/app/enaptercli/execute.go +++ b/internal/app/enaptercli/execute.go @@ -2,12 +2,16 @@ package enaptercli import ( "archive/zip" + "bufio" "bytes" "fmt" "io" "io/fs" "os" + "path/filepath" + "strings" + "github.com/go-git/go-git/v5/plumbing/format/gitignore" "github.com/urfave/cli/v3" ) @@ -41,16 +45,34 @@ func NewApp() *cli.Command { return cmd } -func zipDir(path string) ([]byte, error) { - fsys := os.DirFS(path) +const blueprintIgnoreFile = ".blueprintignore" + +func zipDir(dir string) ([]byte, error) { + fsys := os.DirFS(dir) + + matcher, err := loadBlueprintIgnore(dir) + if err != nil { + return nil, fmt.Errorf("load %s: %w", blueprintIgnoreFile, err) + } buf := &bytes.Buffer{} zw := zip.NewWriter(buf) - err := fs.WalkDir(fsys, ".", func(path string, entry fs.DirEntry, err error) error { + err = fs.WalkDir(fsys, ".", func(path string, entry fs.DirEntry, err error) error { if err != nil { return err } + if path == "." { + return nil + } + + if matcher.Match(path, entry.IsDir()) { + if entry.IsDir() { + return fs.SkipDir + } + return nil + } + if entry.IsDir() { return nil } @@ -81,3 +103,48 @@ func zipDir(path string) ([]byte, error) { return buf.Bytes(), nil } + +type blueprintIgnoreMatcher struct { + m gitignore.Matcher + noFile bool +} + +func (m *blueprintIgnoreMatcher) Match(path string, isDir bool) bool { + if m.noFile { + return false + } + + if path == blueprintIgnoreFile { + return true + } + + parts := strings.Split(path, string(filepath.Separator)) + return m.m.Match(parts, isDir) +} + +func loadBlueprintIgnore(dir string) (*blueprintIgnoreMatcher, error) { + f, err := os.Open(filepath.Join(dir, blueprintIgnoreFile)) + if os.IsNotExist(err) { + return &blueprintIgnoreMatcher{noFile: true}, nil + } + if err != nil { + return nil, err + } + defer f.Close() + + var patterns []gitignore.Pattern + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + patterns = append(patterns, gitignore.ParsePattern(line, nil)) + } + if err := scanner.Err(); err != nil { + return nil, err + } + + return &blueprintIgnoreMatcher{m: gitignore.NewMatcher(patterns)}, nil +} diff --git a/internal/app/enaptercli/execute_test.go b/internal/app/enaptercli/execute_test.go index 9227850..32dcdfb 100644 --- a/internal/app/enaptercli/execute_test.go +++ b/internal/app/enaptercli/execute_test.go @@ -2,6 +2,7 @@ package enaptercli_test import ( "bytes" + "encoding/base64" "encoding/json" "io" "net/http" @@ -12,6 +13,7 @@ import ( "strings" "testing" "text/template" + "unicode/utf8" "github.com/stretchr/testify/require" ) @@ -176,6 +178,9 @@ func readBodyAsString(t *testing.T, r io.Reader) string { t.Helper() d, err := io.ReadAll(r) require.NoError(t, err) + if !utf8.Valid(d) { + return "base64:" + base64.StdEncoding.EncodeToString(d) + } return string(d) } diff --git a/internal/app/enaptercli/testdata/blueprints/with_ignore/.blueprintignore b/internal/app/enaptercli/testdata/blueprints/with_ignore/.blueprintignore new file mode 100644 index 0000000..ef933e2 --- /dev/null +++ b/internal/app/enaptercli/testdata/blueprints/with_ignore/.blueprintignore @@ -0,0 +1,5 @@ +# Ignore build artifacts +build/ + +# Ignore log files +*.log diff --git a/internal/app/enaptercli/testdata/blueprints/with_ignore/build/output.bin b/internal/app/enaptercli/testdata/blueprints/with_ignore/build/output.bin new file mode 100644 index 0000000..2126dc7 --- /dev/null +++ b/internal/app/enaptercli/testdata/blueprints/with_ignore/build/output.bin @@ -0,0 +1 @@ +this should be ignored too diff --git a/internal/app/enaptercli/testdata/blueprints/with_ignore/debug.log b/internal/app/enaptercli/testdata/blueprints/with_ignore/debug.log new file mode 100644 index 0000000..9a0adbc --- /dev/null +++ b/internal/app/enaptercli/testdata/blueprints/with_ignore/debug.log @@ -0,0 +1 @@ +this should be ignored diff --git a/internal/app/enaptercli/testdata/blueprints/with_ignore/firmware.lua b/internal/app/enaptercli/testdata/blueprints/with_ignore/firmware.lua new file mode 100644 index 0000000..aa6fd65 --- /dev/null +++ b/internal/app/enaptercli/testdata/blueprints/with_ignore/firmware.lua @@ -0,0 +1 @@ +enapter.log("Hello from firmware.lua") diff --git a/internal/app/enaptercli/testdata/blueprints/with_ignore/manifest.yml b/internal/app/enaptercli/testdata/blueprints/with_ignore/manifest.yml new file mode 100644 index 0000000..fc8f08a --- /dev/null +++ b/internal/app/enaptercli/testdata/blueprints/with_ignore/manifest.yml @@ -0,0 +1,7 @@ +blueprint_spec: device/3.0 +display_name: Simple Lua + +runtime: + type: lua + options: + file: firmware.lua diff --git a/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/cmd.tmpl b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/cmd.tmpl new file mode 100644 index 0000000..921518a --- /dev/null +++ b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/cmd.tmpl @@ -0,0 +1,2 @@ +enapter3 connection add --name my-conn --url {{.URL}} --token {{.Token}} +enapter3 blueprint upload --connection my-conn --path ./testdata/blueprints/with_ignore \ No newline at end of file diff --git a/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/out b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/out new file mode 100644 index 0000000..7223181 --- /dev/null +++ b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/out @@ -0,0 +1 @@ +{ "blueprint": {"id": "test_blueprint_id"} } \ No newline at end of file diff --git a/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/req_0 b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/req_0 new file mode 100644 index 0000000..565e16c --- /dev/null +++ b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/req_0 @@ -0,0 +1,22 @@ +{ + "Method": "POST", + "URL": "/v3/blueprints/upload", + "Header": { + "Accept-Encoding": [ + "gzip" + ], + "Content-Length": [ + "400" + ], + "Content-Type": [ + "" + ], + "User-Agent": [ + "enapter-cli/" + ], + "X-Enapter-Auth-Token": [ + "enapter_api_test_token" + ] + }, + "Body": "base64:UEsDBBQACAAIAAAAAAAAAAAAAAAAAAAAAAAMAAAAZmlybXdhcmUubHVhSs1LLChJLdLLyU/XUPJIzcnJV0grys9VSMssyi1PLErVyylNVNLkAgQAAP//UEsHCNL3diotAAAAJwAAAFBLAwQUAAgACAAAAAAAAAAAAAAAAAAAAAAADAAAAG1hbmlmZXN0LnltbBTKy6nDQAwF0L2quBX4PchONWSXAoxiX4NAMxbzSXD3wdvDecdkNq9j7clNsfPjG/8ey7/s3jPsWqsVKl5eMojnNJE26/BCFWBcSUVME+DM4WftNwOHBxWHt/K1xuUevwAAAP//UEsHCCoRGUFlAAAAbAAAAFBLAQIUABQACAAIAAAAAADS93YqLQAAACcAAAAMAAAAAAAAAAAAAAAAAAAAAABmaXJtd2FyZS5sdWFQSwECFAAUAAgACAAAAAAAKhEZQWUAAABsAAAADAAAAAAAAAAAAAAAAABnAAAAbWFuaWZlc3QueW1sUEsFBgAAAAACAAIAdAAAAAYBAAAAAA==" +} \ No newline at end of file diff --git a/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/resp_0 b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/resp_0 new file mode 100644 index 0000000..7223181 --- /dev/null +++ b/internal/app/enaptercli/testdata/http_req_resp/blueprint_upload_with_blueprintignore/resp_0 @@ -0,0 +1 @@ +{ "blueprint": {"id": "test_blueprint_id"} } \ No newline at end of file diff --git a/internal/app/enaptercli/testdata/http_req_resp/device_change_blueprint_by_path/req_0 b/internal/app/enaptercli/testdata/http_req_resp/device_change_blueprint_by_path/req_0 index 0a841e2..565e16c 100644 --- a/internal/app/enaptercli/testdata/http_req_resp/device_change_blueprint_by_path/req_0 +++ b/internal/app/enaptercli/testdata/http_req_resp/device_change_blueprint_by_path/req_0 @@ -18,5 +18,5 @@ "enapter_api_test_token" ] }, - "Body": "PK\u0003\u0004\u0014\u0000\b\u0000\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\f\u0000\u0000\u0000firmware.luaJ\ufffdK,(I-\ufffd\ufffd\ufffdO\ufffdP\ufffdH\ufffd\ufffd\ufffdWH+\ufffd\ufffdUH\ufffd,\ufffd-O,J\ufffd\ufffd)MT\ufffd\ufffd\u0002\u0004\u0000\u0000\ufffd\ufffdPK\u0007\b\ufffd\ufffdv*-\u0000\u0000\u0000'\u0000\u0000\u0000PK\u0003\u0004\u0014\u0000\b\u0000\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\f\u0000\u0000\u0000manifest.yml\u0014\ufffd˩\ufffd@\f\u0005н\ufffd\ufffd\u0015\ufffd=\ufffdN5d\ufffd\u0002\ufffdb_\ufffd@3\u0016\ufffdIp\ufffd\ufffd\ufffd\ufffdy\ufffdd6\ufffdc\ufffd\ufffdM\ufffd\ufffd\ufffd\u001b\ufffd\u001e˿\ufffd\ufffd3\ufffdZ\ufffd\u0015*^^2\ufffd\ufffd4\ufffd6\ufffd\ufffdB\u0015`\\IEL\u0013\ufffd\ufffd\ufffdg\ufffd7\u0003\ufffd\u0007\u0015\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u001e\ufffd\u0000\u0000\u0000\ufffd\ufffdPK\u0007\b*\u0011\u0019Ae\u0000\u0000\u0000l\u0000\u0000\u0000PK\u0001\u0002\u0014\u0000\u0014\u0000\b\u0000\b\u0000\u0000\u0000\u0000\u0000\ufffd\ufffdv*-\u0000\u0000\u0000'\u0000\u0000\u0000\f\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000firmware.luaPK\u0001\u0002\u0014\u0000\u0014\u0000\b\u0000\b\u0000\u0000\u0000\u0000\u0000*\u0011\u0019Ae\u0000\u0000\u0000l\u0000\u0000\u0000\f\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000g\u0000\u0000\u0000manifest.ymlPK\u0005\u0006\u0000\u0000\u0000\u0000\u0002\u0000\u0002\u0000t\u0000\u0000\u0000\u0006\u0001\u0000\u0000\u0000\u0000" + "Body": "base64:UEsDBBQACAAIAAAAAAAAAAAAAAAAAAAAAAAMAAAAZmlybXdhcmUubHVhSs1LLChJLdLLyU/XUPJIzcnJV0grys9VSMssyi1PLErVyylNVNLkAgQAAP//UEsHCNL3diotAAAAJwAAAFBLAwQUAAgACAAAAAAAAAAAAAAAAAAAAAAADAAAAG1hbmlmZXN0LnltbBTKy6nDQAwF0L2quBX4PchONWSXAoxiX4NAMxbzSXD3wdvDecdkNq9j7clNsfPjG/8ey7/s3jPsWqsVKl5eMojnNJE26/BCFWBcSUVME+DM4WftNwOHBxWHt/K1xuUevwAAAP//UEsHCCoRGUFlAAAAbAAAAFBLAQIUABQACAAIAAAAAADS93YqLQAAACcAAAAMAAAAAAAAAAAAAAAAAAAAAABmaXJtd2FyZS5sdWFQSwECFAAUAAgACAAAAAAAKhEZQWUAAABsAAAADAAAAAAAAAAAAAAAAABnAAAAbWFuaWZlc3QueW1sUEsFBgAAAAACAAIAdAAAAAYBAAAAAA==" } \ No newline at end of file