Expand logging, and daemonless command support.

This adds more logging in certain places, and adds logging to the CLI.
It also allows for certain commands in the CLI to be used without a
daemon connection, namely `init`, which previously required the daemon
to be connected, but now does not since it doesnt need it.
This commit is contained in:
Zoe
2025-05-08 09:53:41 -05:00
parent 5bb696052a
commit c51eca5dab
16 changed files with 538 additions and 470 deletions

View File

@@ -3,11 +3,13 @@ package commands
import (
"github.com/juls0730/flux/pkg"
"github.com/juls0730/flux/pkg/API"
"go.uber.org/zap"
)
type CommandCtx struct {
Config pkg.CLIConfig
Info API.Info
Logger *zap.SugaredLogger
Info *API.Info
Interactive bool
}

View File

@@ -49,7 +49,7 @@ func deleteAll(ctx CommandCtx, noConfirm *bool) error {
}
}
util.DeleteRequest(ctx.Config.DaemonURL + "/deployments")
util.DeleteRequest(ctx.Config.DaemonURL+"/deployments", ctx.Logger)
fmt.Printf("Successfully deleted all projects\n")
return nil
@@ -80,7 +80,7 @@ func DeleteCommand(ctx CommandCtx, args []string) error {
return deleteAll(ctx, noConfirm)
}
project, err := util.GetProject("delete", args, ctx.Config)
project, err := util.GetProject("delete", args, ctx.Config, ctx.Logger)
if err != nil {
return fmt.Errorf("\tfailed to get project name: %v.\n\tSee flux delete -help for more information", err)
}
@@ -101,7 +101,7 @@ func DeleteCommand(ctx CommandCtx, args []string) error {
}
}
err = util.DeleteRequest(ctx.Config.DaemonURL + "/app/" + project.Id)
err = util.DeleteRequest(ctx.Config.DaemonURL+"/app/"+project.Id, ctx.Logger)
if err != nil {
return fmt.Errorf("failed to delete project: %v", err)
}

View File

@@ -8,7 +8,7 @@ import (
)
func ListCommand(ctx CommandCtx, args []string) error {
apps, err := util.GetRequest[[]API.App](ctx.Config.DaemonURL + "/apps")
apps, err := util.GetRequest[[]API.App](ctx.Config.DaemonURL+"/apps", ctx.Logger)
if err != nil {
return fmt.Errorf("failed to get apps: %v", err)
}

View File

@@ -7,14 +7,14 @@ import (
)
func StartCommand(ctx CommandCtx, args []string) error {
projectName, err := util.GetProject("start", args, ctx.Config)
projectName, err := util.GetProject("start", args, ctx.Config, ctx.Logger)
if err != nil {
return err
}
// Put request to start the project, since the start endpoint is idempotent.
// If the project is already running, this will return a 304 Not Modified
err = util.PutRequest(ctx.Config.DaemonURL+"/app/"+projectName.Id+"/start", nil)
err = util.PutRequest(ctx.Config.DaemonURL+"/app/"+projectName.Id+"/start", nil, ctx.Logger)
if err != nil {
return fmt.Errorf("failed to start %s: %v", projectName.Name, err)
}

View File

@@ -7,12 +7,12 @@ import (
)
func StopCommand(ctx CommandCtx, args []string) error {
projectName, err := util.GetProject("stop", args, ctx.Config)
projectName, err := util.GetProject("stop", args, ctx.Config, ctx.Logger)
if err != nil {
return err
}
err = util.PutRequest(ctx.Config.DaemonURL+"/app/"+projectName.Id+"/stop", nil)
err = util.PutRequest(ctx.Config.DaemonURL+"/app/"+projectName.Id+"/stop", nil, ctx.Logger)
if err != nil {
return fmt.Errorf("failed to stop %s: %v", projectName.Name, err)
}