-
Notifications
You must be signed in to change notification settings - Fork 7
[CLI] Add a destroy app command #129
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
9da6e0b
f17e499
7ebf7f2
1c30eba
ef16820
2d1c36b
5a59ffa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // This file is part of arduino-app-cli. | ||
| // | ||
| // Copyright 2025 ARDUINO SA (http://www.arduino.cc/) | ||
| // | ||
| // This software is released under the GNU General Public License version 3, | ||
| // which covers the main part of arduino-app-cli. | ||
| // The terms of this license can be found at: | ||
| // https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| // | ||
| // You can be released from the requirements of the above licenses by purchasing | ||
| // a commercial license. Buying such a license is mandatory if you want to | ||
| // modify or otherwise use the software for commercial activities involving the | ||
| // Arduino software without disclosing the source code of your own applications. | ||
| // To purchase a commercial license, send an email to license@arduino.cc. | ||
|
|
||
| package app | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/arduino/arduino-app-cli/cmd/arduino-app-cli/completion" | ||
| "github.com/arduino/arduino-app-cli/cmd/feedback" | ||
| "github.com/arduino/arduino-app-cli/internal/orchestrator" | ||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/app" | ||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/config" | ||
| ) | ||
|
|
||
| func newDestroyCmd(cfg config.Configuration) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "destroy app_path", | ||
| Short: "Destroy an Arduino App", | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) == 0 { | ||
| return cmd.Help() | ||
| } | ||
| app, err := Load(args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return destroyHandler(cmd.Context(), app) | ||
| }, | ||
| ValidArgsFunction: completion.ApplicationNamesWithFilterFunc(cfg, func(apps orchestrator.AppInfo) bool { | ||
| return apps.Status != orchestrator.StatusUninitialized | ||
| }), | ||
| } | ||
| } | ||
|
|
||
| func destroyHandler(ctx context.Context, app app.ArduinoApp) error { | ||
| out, _, getResult := feedback.OutputStreams() | ||
|
|
||
| for message := range orchestrator.DestroyAndCleanApp(ctx, app) { | ||
| switch message.GetType() { | ||
| case orchestrator.ProgressType: | ||
| fmt.Fprintf(out, "Progress[%s]: %.0f%%\n", message.GetProgress().Name, message.GetProgress().Progress) | ||
| case orchestrator.InfoType: | ||
| fmt.Fprintln(out, "[INFO]", message.GetData()) | ||
| case orchestrator.ErrorType: | ||
| feedback.Fatal(message.GetError().Error(), feedback.ErrGeneric) | ||
| return nil | ||
| } | ||
| } | ||
| outputResult := getResult() | ||
|
|
||
| feedback.PrintResult(destroyAppResult{ | ||
| AppName: app.Name, | ||
| Status: "uninitialized", | ||
| Output: outputResult, | ||
| }) | ||
| return nil | ||
| } | ||
|
|
||
| type destroyAppResult struct { | ||
| AppName string `json:"appName"` | ||
| Status string `json:"status"` | ||
| Output *feedback.OutputStreamsResult `json:"output,omitempty"` | ||
| } | ||
|
|
||
| func (r destroyAppResult) String() string { | ||
| return fmt.Sprintf("✓ App '%q destroyed successfully.", r.AppName) | ||
| } | ||
|
|
||
| func (r destroyAppResult) Data() interface{} { | ||
| return r | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,7 +150,10 @@ func getAppStatusByPath( | |
| return nil, fmt.Errorf("failed to list containers: %w", err) | ||
| } | ||
| if len(containers) == 0 { | ||
| return nil, nil | ||
| return &AppStatusInfo{ | ||
| AppPath: paths.New(pathLabel), | ||
| Status: StatusUninitialized, | ||
| }, nil | ||
|
Comment on lines
+153
to
+156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that this is a valid app? Maybe we still need to return nil nil here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to have a valid app without containers. But, to be sure we also need to perform an app validation within the filesystem or something like that. So for now, it is better to keep the nil nil and maybe handle this use case in a different PR if we decide it is needed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess it would be better to move the whole part about introducing a new 'uninitialized' app status(valid app with no containers) to a dedicated PR, and focus this one just on implementing the destroy command.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I would keep it, maybe we can add this check to be sure we always return the status of an existing app diff --git a/internal/orchestrator/helpers.go b/internal/orchestrator/helpers.go
index 3c1564e..b762418 100644
--- a/internal/orchestrator/helpers.go
+++ b/internal/orchestrator/helpers.go
@@ -150,10 +150,14 @@ func getAppStatusByPath(
return nil, fmt.Errorf("failed to list containers: %w", err)
}
if len(containers) == 0 {
- return &AppStatusInfo{
- AppPath: paths.New(pathLabel),
- Status: StatusUninitialized,
- }, nil
+ path := paths.New(pathLabel)
+ if _, err := app.Load(path); err == nil {
+ return &AppStatusInfo{
+ AppPath: path,
+ Status: StatusUninitialized,
+ }, nil
+ }
+ return nil, nil
}
app := parseAppStatus(containers) |
||
| } | ||
|
|
||
| app := parseAppStatus(containers) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.