Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bp/firmware.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enapter.log("Hello from firmware.lua")
7 changes: 7 additions & 0 deletions bp/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
blueprint_spec: device/3.0
display_name: Simple Lua

runtime:
type: lua
options:
file: firmware.lua
12 changes: 6 additions & 6 deletions cmd/enapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ 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.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/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
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // 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
)
37 changes: 26 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
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/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/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/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=
2 changes: 1 addition & 1 deletion internal/app/cliflags/duration.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions internal/app/enaptercli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"sync"
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/enapter/enapter-cli/internal/app/enaptercli"
)

var errExitTimeout = errors.New("exit timed out")

type testApp struct {
app *cli.App
app *cli.Command
outBuf *lineBuffer
errCh chan error
cancel func()
Expand All @@ -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{
Expand Down
36 changes: 18 additions & 18 deletions internal/app/enaptercli/cmd_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -44,32 +44,32 @@ 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
},
},
&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{
Expand All @@ -80,27 +80,27 @@ 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.
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.apiAllowInsecure},
},
}

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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/enaptercli/cmd_base_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net/url"
"strconv"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

var errEndPagination = errors.New("end pagination")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/enaptercli/cmd_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package enaptercli
import (
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprint struct {
Expand All @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions internal/app/enaptercli/cmd_blueprint_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprintDownload struct {
Expand All @@ -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)
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/app/enaptercli/cmd_blueprint_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net/http"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprintGet struct {
Expand All @@ -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)
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/enaptercli/cmd_blueprint_profiles.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package enaptercli

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprintProfiles struct {
Expand All @@ -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(),
},
Expand Down
6 changes: 3 additions & 3 deletions internal/app/enaptercli/cmd_blueprint_profiles_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"os"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprintProfilesDownload struct {
Expand All @@ -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)
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/app/enaptercli/cmd_blueprint_profiles_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"os"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type cmdBlueprintProfilesUpload struct {
Expand All @@ -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)
},
}
}
Expand Down
Loading
Loading