Skip to content
Open
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
13 changes: 6 additions & 7 deletions autocomplete/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"github.com/EarthBuild/earthbuild/domain"
"github.com/EarthBuild/earthbuild/earthfile2llb"
"github.com/EarthBuild/earthbuild/util/fileutil"

gwclient "github.com/moby/buildkit/frontend/gateway/client"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

var errCompPointOutOfBounds = errors.New("COMP_POINT out of bounds")
Expand Down Expand Up @@ -412,14 +411,14 @@ func GetPotentials(
gwClient gwclient.Client,
compLine string,
compPoint int,
app *cli.App,
app *cli.Command,
) ([]string, error) {
if compPoint > len(compLine) {
return nil, errCompPointOutOfBounds
}

compLine = compLine[:compPoint]
subCommands := app.Commands
commands := app.Commands

flagValues := map[string]string{}
flagValuePotentialFuncs := map[string]FlagValuePotentialFn{}
Expand Down Expand Up @@ -503,9 +502,9 @@ func GetPotentials(
target = w
} else {
// must be under a command
foundCmd := getCmd(w, subCommands)
foundCmd := getCmd(w, commands)
if foundCmd != nil {
subCommands = foundCmd.Subcommands
commands = foundCmd.Commands
cmd = foundCmd
}

Expand Down Expand Up @@ -546,7 +545,7 @@ func GetPotentials(

case rootState, commandState:
if cmd != nil {
potentials = getVisibleCommands(cmd.Subcommands)
potentials = getVisibleCommands(cmd.Commands)
potentials = padStrings(potentials, "", " ")
} else {
potentials = getVisibleCommands(app.Commands)
Expand Down
11 changes: 5 additions & 6 deletions autocomplete/complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (

"github.com/EarthBuild/earthbuild/buildcontext"
"github.com/EarthBuild/earthbuild/conslogging"

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

func getApp() *cli.App {
app := cli.NewApp()
func getApp() *cli.Command {
app := new(cli.Command)
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "flag",
Expand Down Expand Up @@ -41,7 +40,7 @@ func getApp() *cli.App {
Name: "subflag",
},
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
{
Name: "abc",
},
Expand All @@ -55,7 +54,7 @@ func getApp() *cli.App {
Name: "surf-the-internet",
},
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
{
Name: "dancing-queen",
},
Expand Down
52 changes: 23 additions & 29 deletions cmd/earthly/app/before.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"context"
"fmt"
"net/http"
"os"
Expand All @@ -9,7 +10,6 @@ import (
"time"

"github.com/EarthBuild/earthbuild/cmd/earthly/subcmd"

"github.com/EarthBuild/earthbuild/config"
"github.com/EarthBuild/earthbuild/conslogging"
logbussetup "github.com/EarthBuild/earthbuild/logbus/setup"
Expand All @@ -20,26 +20,26 @@ import (
"github.com/EarthBuild/earthbuild/util/fileutil"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

func (app *EarthlyApp) before(cliCtx *cli.Context) error {
func (app *EarthlyApp) before(ctx context.Context, cmd *cli.Command) (context.Context, error) {
flags := app.BaseCLI.Flags()

if flags.EnableProfiler {
go profhandler()
}

if flags.InstallationName != "" {
if !cliCtx.IsSet("config") {
if !cmd.IsSet("config") {
flags.ConfigPath = defaultConfigPath(flags.InstallationName)
}

if !cliCtx.IsSet("buildkit-container-name") {
if !cmd.IsSet("buildkit-container-name") {
flags.ContainerName = flags.InstallationName + "-buildkitd"
}

if !cliCtx.IsSet("buildkit-volume-name") {
if !cmd.IsSet("buildkit-volume-name") {
flags.BuildkitdSettings.VolumeName = flags.InstallationName + "-cache"
}
}
Expand All @@ -58,7 +58,7 @@ func (app *EarthlyApp) before(cliCtx *cli.Context) error {
}

busSetup, err := logbussetup.New(
cliCtx.Context,
ctx,
app.BaseCLI.Logbus(),
flags.Debug,
flags.Verbose,
Expand All @@ -72,12 +72,12 @@ func (app *EarthlyApp) before(cliCtx *cli.Context) error {
flags.GithubAnnotations,
)
if err != nil {
return errors.Wrap(err, "logbus setup")
return ctx, errors.Wrap(err, "logbus setup")
}

app.BaseCLI.SetLogbusSetup(busSetup)

if cliCtx.IsSet("config") {
if cmd.IsSet("config") {
app.BaseCLI.Console().Printf("loading config values from %q\n", flags.ConfigPath)
}

Expand All @@ -86,32 +86,28 @@ func (app *EarthlyApp) before(cliCtx *cli.Context) error {
if flags.ConfigPath != "" {
yamlData, err = config.ReadConfigFile(flags.ConfigPath)
if err != nil {
if cliCtx.IsSet("config") || !errors.Is(err, os.ErrNotExist) {
return errors.Wrapf(err, "read config")
if cmd.IsSet("config") || !errors.Is(err, os.ErrNotExist) {
return ctx, errors.Wrapf(err, "read config")
}
}
}

cfg, err := config.ParseYAML(yamlData, flags.InstallationName)
if err != nil {
return errors.Wrapf(err, "failed to parse %s", flags.ConfigPath)
return ctx, errors.Wrapf(err, "failed to parse %s", flags.ConfigPath)
}

app.BaseCLI.SetCfg(&cfg)
app.processDeprecatedCommandOptions(app.BaseCLI.Cfg())

err = app.processDeprecatedCommandOptions(app.BaseCLI.Cfg())
if err != nil {
return err
}

err = app.parseFrontend(cliCtx)
err = app.parseFrontend(ctx)
if err != nil {
return err
return ctx, err
}

// Make a small attempt to check if we are not bootstrapped. If not, then do that before we do anything else.
isBootstrapCmd := false
for _, f := range cliCtx.Args().Slice() {
for _, f := range cmd.Args().Slice() {
isBootstrapCmd = f == "bootstrap"

if isBootstrapCmd {
Expand All @@ -124,16 +120,16 @@ func (app *EarthlyApp) before(cliCtx *cli.Context) error {
app.BaseCLI.Flags().BootstrapNoBuildkit = true
newBootstrap := subcmd.NewBootstrap(app.BaseCLI)

err = newBootstrap.Action(cliCtx)
err = newBootstrap.Action(ctx, cmd)
if err != nil {
return errors.Wrap(err, "bootstrap unbootstrclied installation")
return ctx, errors.Wrap(err, "bootstrap unbootstrclied installation")
}
}

return nil
return ctx, nil
}

func (app *EarthlyApp) parseFrontend(cliCtx *cli.Context) error {
func (app *EarthlyApp) parseFrontend(ctx context.Context) error {
console := app.BaseCLI.Console().WithPrefix("frontend")
feCfg := &containerutil.FrontendConfig{
BuildkitHostCLIValue: app.BaseCLI.Flags().BuildkitHost,
Expand All @@ -144,11 +140,11 @@ func (app *EarthlyApp) parseFrontend(cliCtx *cli.Context) error {
Console: console,
}

fe, err := containerutil.FrontendForSetting(cliCtx.Context, app.BaseCLI.Cfg().Global.ContainerFrontend, feCfg)
fe, err := containerutil.FrontendForSetting(ctx, app.BaseCLI.Cfg().Global.ContainerFrontend, feCfg)
if err != nil {
origErr := err

stub, err := containerutil.NewStubFrontend(cliCtx.Context, feCfg)
stub, err := containerutil.NewStubFrontend(ctx, feCfg)
if err != nil {
return errors.Wrap(err, "failed stub frontend initialization")
}
Expand Down Expand Up @@ -178,7 +174,7 @@ func (app *EarthlyApp) parseFrontend(cliCtx *cli.Context) error {
return nil
}

func (app *EarthlyApp) processDeprecatedCommandOptions(cfg *config.Config) error {
func (app *EarthlyApp) processDeprecatedCommandOptions(cfg *config.Config) {
app.warnIfEarth()

if cfg.Global.CachePath != "" {
Expand Down Expand Up @@ -217,8 +213,6 @@ func (app *EarthlyApp) processDeprecatedCommandOptions(cfg *config.Config) error
cfg.Git[k] = v
}
}

return nil
}

func (app *EarthlyApp) warnIfEarth() {
Expand Down
17 changes: 8 additions & 9 deletions cmd/earthly/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ import (
"strings"
"time"

"github.com/EarthBuild/earthbuild/logstream"
"github.com/fatih/color"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"google.golang.org/grpc/codes"

"github.com/EarthBuild/earthbuild/buildkitd"
"github.com/EarthBuild/earthbuild/cmd/earthly/common"
"github.com/EarthBuild/earthbuild/cmd/earthly/helper"
"github.com/EarthBuild/earthbuild/conslogging"
"github.com/EarthBuild/earthbuild/earthfile2llb"
"github.com/EarthBuild/earthbuild/inputgraph"
"github.com/EarthBuild/earthbuild/logstream"
"github.com/EarthBuild/earthbuild/util/containerutil"
"github.com/EarthBuild/earthbuild/util/errutil"
"github.com/EarthBuild/earthbuild/util/hint"
"github.com/EarthBuild/earthbuild/util/params"
"github.com/EarthBuild/earthbuild/util/reflectutil"
"github.com/EarthBuild/earthbuild/util/stringutil"
"github.com/EarthBuild/earthbuild/util/syncutil"
"github.com/fatih/color"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/pkg/errors"
"github.com/urfave/cli/v3"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

Expand Down Expand Up @@ -102,7 +101,7 @@ func unhideFlagsCommands(cmds []*cli.Command) {
reflectutil.SetBool(flg, "Hidden", false)
}

unhideFlagsCommands(cmd.Subcommands)
unhideFlagsCommands(cmd.Commands)
}
}

Expand Down Expand Up @@ -136,7 +135,7 @@ func (app *EarthlyApp) run(ctx context.Context, args []string, lastSignal *syncu
)
}()

err := app.BaseCLI.App().RunContext(ctx, args)
err := app.BaseCLI.App().Run(ctx, args)
if err != nil {
return app.handleError(ctx, err, args, lastSignal)
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/earthly/base/buildkit.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package base

import (
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"context"

"github.com/EarthBuild/earthbuild/buildkitd"
"github.com/moby/buildkit/client"
"github.com/pkg/errors"
"github.com/urfave/cli/v3"
)

func (cli *CLI) GetBuildkitClient(cliCtx *cli.Context) (c *client.Client, err error) {
err = cli.InitFrontend(cliCtx)
func (cli *CLI) GetBuildkitClient(ctx context.Context, cmd *cli.Command) (c *client.Client, err error) {
err = cli.InitFrontend(ctx, cmd)
if err != nil {
return nil, err
}

c, err = buildkitd.NewClient(
cliCtx.Context, cli.Console(), cli.Flags().BuildkitdImage, cli.Flags().ContainerName, cli.Flags().InstallationName,
ctx, cli.Console(), cli.Flags().BuildkitdImage, cli.Flags().ContainerName, cli.Flags().InstallationName,
cli.Flags().ContainerFrontend, cli.Version(), cli.Flags().BuildkitdSettings)
if err != nil {
return nil, errors.Wrap(err, "could not construct new buildkit client")
Expand Down
11 changes: 5 additions & 6 deletions cmd/earthly/base/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package base
import (
"github.com/EarthBuild/earthbuild/buildkitd"
"github.com/EarthBuild/earthbuild/cmd/earthly/flag"
"github.com/EarthBuild/earthbuild/logbus"
"github.com/urfave/cli/v2"

"github.com/EarthBuild/earthbuild/config"
"github.com/EarthBuild/earthbuild/conslogging"
"github.com/EarthBuild/earthbuild/logbus"
"github.com/EarthBuild/earthbuild/logbus/setup"
"github.com/urfave/cli/v3"
)

type CLI struct {
Expand All @@ -19,7 +18,7 @@ type CLI struct {
defaultBuildkitdImage string
defaultInstallationName string
deferredFuncs []func()
app *cli.App
app *cli.Command
cfg *config.Config
logbusSetup *setup.BusSetup
logbus *logbus.Bus
Expand Down Expand Up @@ -66,7 +65,7 @@ func WithDefaultInstallationName(name string) CLIOpt {

func NewCLI(console conslogging.ConsoleLogger, opts ...CLIOpt) *CLI {
cli := CLI{
app: cli.NewApp(),
app: new(cli.Command),
console: console,
logbus: logbus.New(),
flags: flag.Global{
Expand All @@ -81,7 +80,7 @@ func NewCLI(console conslogging.ConsoleLogger, opts ...CLIOpt) *CLI {
return &cli
}

func (c *CLI) App() *cli.App {
func (c *CLI) App() *cli.Command {
return c.app
}

Expand Down
Loading
Loading