Skip to content
Closed
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
12 changes: 10 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module github.com/nais/cli

go 1.24.4

replace (
github.com/charmbracelet/fang => ../../charmbracelet/fang
)

tool (
github.com/Khan/genqlient
github.com/goreleaser/nfpm/v2/cmd/nfpm
Expand Down Expand Up @@ -89,9 +93,12 @@ require (
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/colorprofile v0.3.0 // indirect
github.com/charmbracelet/fang v0.1.0 // indirect
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 // indirect
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/containerd/console v1.0.5 // indirect
Expand Down Expand Up @@ -158,6 +165,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-cobra v1.2.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ=
github.com/charmbracelet/colorprofile v0.3.0/go.mod h1:oHJ340RS2nmG1zRGPmhJKJ/jf4FPNNk0P39/wBPA1G0=
github.com/charmbracelet/fang v0.1.0 h1:SlZS2crf3/zQh7Mr4+W+7QR1k+L08rrPX5rm5z3d7Wg=
github.com/charmbracelet/fang v0.1.0/go.mod h1:Zl/zeUQ8EtQuGyiV0ZKZlZPDowKRTzu8s/367EpN/fc=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 h1:D9AJJuYTN5pvz6mpIGO1ijLKpfTYSHOtKGgwoTQ4Gog=
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1/go.mod h1:tRlx/Hu0lo/j9viunCN2H+Ze6JrmdjQlXUQvvArgaOc=
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 h1:IJDiTgVE56gkAGfq0lBEloWgkXMk4hl/bmuPoicI4R0=
github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0=
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a h1:G99klV19u0QnhiizODirwVksQB91TJKV/UaTnACcG30=
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
Expand Down Expand Up @@ -387,6 +397,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg=
Expand Down
8 changes: 4 additions & 4 deletions internal/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newApplication(flags *root.Flags) *cli.Application {
func Run(ctx context.Context, w io.Writer) error {
flags := &root.Flags{}
app := newApplication(flags)
executedCommand, err := app.Run(ctx, cli.NewWriter(w), os.Args[1:])
err := app.Run(ctx, cli.NewWriter(w), os.Args[1:])
autoComplete := slices.Contains(os.Args[1:], "__complete")

if !autoComplete {
Expand All @@ -57,9 +57,9 @@ func Run(ctx context.Context, w io.Writer) error {
}()
}

if !autoComplete && executedCommand != nil {
collectCommandHistogram(ctx, executedCommand, err)
}
// if !autoComplete && executedCommand != nil {
// collectCommandHistogram(ctx, executedCommand, err)
// }

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func runCommand(t *testing.T, ctx context.Context, cmd *cli.Command, parentComma
t.Fatalf("failed to run command %q: %v", strings.Join(helpCmd, " "), err)
}
}()
_, err := newApplication(&root.Flags{}).Run(ctx, out, helpCmd)
err := newApplication(&root.Flags{}).Run(ctx, out, helpCmd)
if err != nil {
t.Fatalf("failed to run command %s: %v", strings.Join(helpCmd, " "), err)
}
Expand Down
11 changes: 7 additions & 4 deletions internal/cli/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"iter"
"maps"

"github.com/charmbracelet/fang"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +28,7 @@ type Application struct {
cobraCmd *cobra.Command
}

func (a *Application) Run(ctx context.Context, out Output, args []string) ([]string, error) {
func (a *Application) Run(ctx context.Context, out Output, args []string) error {
cobra.EnableTraverseRunHooks = true

a.cobraCmd = &cobra.Command{
Expand All @@ -39,7 +40,7 @@ func (a *Application) Run(ctx context.Context, out Output, args []string) ([]str
DisableSuggestions: true,
}
a.cobraCmd.SetArgs(args)
a.cobraCmd.SetOut(out)
// a.cobraCmd.SetOut(out)

setupFlags(a.cobraCmd, a.StickyFlags, a.cobraCmd.PersistentFlags())

Expand All @@ -55,8 +56,10 @@ func (a *Application) Run(ctx context.Context, out Output, args []string) ([]str
a.cobraCmd.AddCommand(c.cobraCmd)
}

executedCommand, err := a.cobraCmd.ExecuteContextC(ctx)
return commandNames(executedCommand), err
return fang.Execute(ctx, a.cobraCmd)

// executedCommand, err := a.cobraCmd.ExecuteContextC(ctx)
// return commandNames(executedCommand), err
}

func allGroups(cmds []*Command) iter.Seq[string] {
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package main

import (
"context"
"fmt"
"os"

"github.com/nais/cli/internal/application"
)

func main() {
if err := application.Run(context.Background(), os.Stdout); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
Loading