Skip to content

Commit 01c0417

Browse files
authored
Refactor the list command (#2101)
## Summary Refactor the list command into its own file. Also update the description to be more accurate. ## How was it tested? 1. Verified the `list` command is updated with the new message in the `--help` command output 2. Verified the `list` command outputs the same list of packages before and after this change (compared my local `devbox` install output to the output in my `devbox shell` with these changes).
1 parent ff6826d commit 01c0417

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

internal/boxcli/global.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,6 @@ func addCommandAndHideConfigFlag(parent, child *cobra.Command) {
6060
_ = child.Flags().MarkHidden("config")
6161
}
6262

63-
type listCmdFlags struct {
64-
config configFlags
65-
}
66-
67-
func listCmd() *cobra.Command {
68-
flags := listCmdFlags{}
69-
cmd := &cobra.Command{
70-
Use: "list",
71-
Aliases: []string{"ls"},
72-
Short: "List global packages",
73-
PreRunE: ensureNixInstalled,
74-
RunE: func(cmd *cobra.Command, args []string) error {
75-
box, err := devbox.Open(&devopt.Opts{
76-
Dir: flags.config.path,
77-
Stderr: cmd.ErrOrStderr(),
78-
})
79-
if err != nil {
80-
return errors.WithStack(err)
81-
}
82-
for _, p := range box.AllPackageNamesIncludingRemovedTriggerPackages() {
83-
fmt.Fprintf(cmd.OutOrStdout(), "* %s\n", p)
84-
}
85-
return nil
86-
},
87-
}
88-
flags.config.register(cmd)
89-
return cmd
90-
}
91-
9263
var globalConfigPath string
9364

9465
func ensureGlobalConfig() (string, error) {

internal/boxcli/list.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
2+
// Use of this source code is governed by the license in the LICENSE file.
3+
4+
package boxcli
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/pkg/errors"
10+
"github.com/spf13/cobra"
11+
12+
"go.jetpack.io/devbox/internal/devbox"
13+
"go.jetpack.io/devbox/internal/devbox/devopt"
14+
)
15+
16+
type listCmdFlags struct {
17+
config configFlags
18+
}
19+
20+
func listCmd() *cobra.Command {
21+
flags := listCmdFlags{}
22+
cmd := &cobra.Command{
23+
Use: "list",
24+
Aliases: []string{"ls"},
25+
Short: "List installed packages",
26+
PreRunE: ensureNixInstalled,
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
box, err := devbox.Open(&devopt.Opts{
29+
Dir: flags.config.path,
30+
Stderr: cmd.ErrOrStderr(),
31+
})
32+
if err != nil {
33+
return errors.WithStack(err)
34+
}
35+
for _, p := range box.AllPackageNamesIncludingRemovedTriggerPackages() {
36+
fmt.Fprintf(cmd.OutOrStdout(), "* %s\n", p)
37+
}
38+
return nil
39+
},
40+
}
41+
flags.config.register(cmd)
42+
return cmd
43+
}

0 commit comments

Comments
 (0)