Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create command & terminal styling #131

Merged
merged 2 commits into from
Dec 4, 2024
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
7 changes: 6 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ jobs:
runs-on: elvia-runner
strategy:
matrix:
command: [build, scan]
command:
- build
- scan
- create
fail-fast: false
steps:
- name: Checkout repository
Expand All @@ -36,3 +39,5 @@ jobs:

- name: 'Run tests for ${{ matrix.command }} command'
run: './tests/${{ matrix.command }}/run_tests.sh'
env:
3LV_NON_INTERACTIVE: 'true'
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.19.5
0.20.0
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ module github.com/3lvia/cli
go 1.22.3

require (
github.com/charmbracelet/lipgloss v1.0.0
github.com/google/go-github/v66 v66.0.0
github.com/samber/lo v1.47.0
github.com/urfave/cli/v3 v3.0.0-beta1
golang.org/x/mod v0.22.0
golang.org/x/text v0.20.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.5.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/text v0.20.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.27.0 // indirect
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
github.com/charmbracelet/x/ansi v0.5.2 h1:dEa1x2qdOZXD/6439s+wF7xjV+kZLu/iN00GuXXrU9E=
github.com/charmbracelet/x/ansi v0.5.2/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q=
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/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -7,8 +13,19 @@ github.com/google/go-github/v66 v66.0.0 h1:ADJsaXj9UotwdgK8/iFZtv7MLc8E8WBl62WLd
github.com/google/go-github/v66 v66.0.0/go.mod h1:+4SO9Zkuyf8ytMj0csN1NR/5OTR+MfqPp8P8dVlcvY4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -17,6 +34,9 @@ github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjc
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package main
import (
"context"
"embed"
"fmt"
"log"
"os"
"strings"

"github.com/3lvia/cli/pkg/build"
"github.com/3lvia/cli/pkg/create"
"github.com/3lvia/cli/pkg/deploy"
"github.com/3lvia/cli/pkg/githubactions"
"github.com/3lvia/cli/pkg/run"
"github.com/3lvia/cli/pkg/scan"
"github.com/3lvia/cli/pkg/style"
"github.com/google/go-github/v66/github"
"github.com/urfave/cli/v3"
"golang.org/x/mod/semver"
Expand All @@ -34,10 +37,20 @@ func main() {
Usage: "Command Line Interface tool for developing, building and securing Elvia applications ⚡",
Version: version,
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "non-interactive",
Usage: "Run in non-interactive mode. Accepts all default values without prompting for confirmation.",
Sources: cli.EnvVars("3LV_NON_INTERACTIVE"),
},
},
After: func(ctx context.Context, c *cli.Command) error {
latestVersion, _ := getLatestVersion(ctx)
if semver.Compare("v"+version, "v"+latestVersion) == -1 {
log.Printf("\n\nA new version of 3lv is available! %s -> %s", version, latestVersion)
style.Print(
fmt.Sprintf("\n\nA new version of 3lv is available! %s -> %s", version, latestVersion),
&style.PrintOptions{Color: "yellow"},
)
}

return nil
Expand All @@ -48,6 +61,7 @@ func main() {
scan.Command,
githubactions.Command,
run.Command,
create.Command,
},
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package build
import (
"context"
"fmt"
"log"
"os"
"os/exec"
"strings"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/3lvia/cli/pkg/command"
"github.com/3lvia/cli/pkg/scan"
"github.com/3lvia/cli/pkg/shared"
"github.com/3lvia/cli/pkg/style"
"github.com/3lvia/cli/pkg/utils"
"github.com/urfave/cli/v3"
)
Expand Down Expand Up @@ -133,7 +133,10 @@ func Build(ctx context.Context, c *cli.Command) error {
possibleSystemName := c.String("system-name")

if possibleSystemName == "" {
log.Println("System name not provided, will try to use the current git repository name")
style.Print(
"System name not provided, will try to use the current git repository name.",
nil,
)

repositoryName, err := utils.ResolveRepositoryName("")
if err != nil {
Expand Down Expand Up @@ -166,7 +169,10 @@ func Build(ctx context.Context, c *cli.Command) error {
}

if c.Bool("generate-only") {
log.Printf("Dockerfile generated at %s\n", dockerfilePath)
style.Print(
fmt.Sprintf("Dockerfile generated at %s\n", dockerfilePath),
nil,
)
return nil
}

Expand All @@ -177,7 +183,7 @@ func Build(ctx context.Context, c *cli.Command) error {
skipAuthentication := c.Bool("skip-authentication") || !push

if strings.Contains(registry, "azurecr.io") && !skipAuthentication {
log.Println("Azure registry detected, will try to authenticate with Azure")
style.Print("Azure registry detected, will try to authenticate with Azure.", nil)

azureTenantID := utils.StringWithDefault(
c.String("azure-tenant-id"),
Expand Down
9 changes: 7 additions & 2 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package command
import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"
"testing"

"github.com/3lvia/cli/pkg/style"
)

type Output struct {
Expand Down Expand Up @@ -48,7 +50,10 @@ func Run(cmd exec.Cmd, options *RunOptions) Output {
}
}

log.Print(cmd.String())
style.Print(
fmt.Sprintf("%s\n", cmd.String()),
&style.PrintOptions{Color: "cyan"},
)

var errBuf, outBuf bytes.Buffer
cmd.Stderr = io.MultiWriter(os.Stderr, &errBuf)
Expand Down
Loading