Skip to content

Commit dfb9796

Browse files
committed
rearrange cli commands
1 parent aa21da5 commit dfb9796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+711
-536
lines changed

Diff for: cli/board/attach.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"context"
2222
"os"
2323

24-
"github.com/arduino/arduino-cli/cli"
24+
"github.com/arduino/arduino-cli/cli/errorcodes"
25+
"github.com/arduino/arduino-cli/cli/instance"
26+
"github.com/arduino/arduino-cli/cli/output"
2527
"github.com/arduino/arduino-cli/commands/board"
2628
"github.com/arduino/arduino-cli/common/formatter"
2729
rpc "github.com/arduino/arduino-cli/rpc/commands"
@@ -33,9 +35,9 @@ func initAttachCommand() *cobra.Command {
3335
Use: "attach <port>|<FQBN> [sketchPath]",
3436
Short: "Attaches a sketch to a board.",
3537
Long: "Attaches a sketch to a board.",
36-
Example: " " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0\n" +
37-
" " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 HelloWorld\n" +
38-
" " + cli.VersionInfo.Application + " board attach arduino:samd:mkr1000",
38+
Example: " " + os.Args[0] + " board attach serial:///dev/tty/ACM0\n" +
39+
" " + os.Args[0] + " board attach serial:///dev/tty/ACM0 HelloWorld\n" +
40+
" " + os.Args[0] + " board attach arduino:samd:mkr1000",
3941
Args: cobra.RangeArgs(1, 2),
4042
Run: runAttachCommand,
4143
}
@@ -49,7 +51,7 @@ var attachFlags struct {
4951
}
5052

5153
func runAttachCommand(cmd *cobra.Command, args []string) {
52-
instance := cli.CreateInstance()
54+
instance := instance.CreateInstance()
5355
var path string
5456
if len(args) > 0 {
5557
path = args[1]
@@ -59,9 +61,9 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
5961
BoardUri: args[0],
6062
SketchPath: path,
6163
SearchTimeout: attachFlags.searchTimeout,
62-
}, cli.OutputTaskProgress())
64+
}, output.OutputTaskProgress())
6365
if err != nil {
6466
formatter.PrintError(err, "attach board error")
65-
os.Exit(cli.ErrGeneric)
67+
os.Exit(errorcodes.ErrGeneric)
6668
}
6769
}

Diff for: cli/board/board.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@
1818
package board
1919

2020
import (
21-
"github.com/arduino/arduino-cli/cli"
21+
"os"
22+
2223
"github.com/spf13/cobra"
2324
)
2425

25-
// InitCommand prepares the command.
26-
func InitCommand() *cobra.Command {
26+
// NewCommand created a new `board` command
27+
func NewCommand() *cobra.Command {
2728
boardCommand := &cobra.Command{
2829
Use: "board",
2930
Short: "Arduino board commands.",
3031
Long: "Arduino board commands.",
3132
Example: " # Lists all connected boards.\n" +
32-
" " + cli.VersionInfo.Application + " board list\n\n" +
33+
" " + os.Args[0] + " board list\n\n" +
3334
" # Attaches a sketch to a board.\n" +
34-
" " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 mySketch",
35+
" " + os.Args[0] + " board attach serial:///dev/tty/ACM0 mySketch",
3536
}
37+
3638
boardCommand.AddCommand(initAttachCommand())
37-
boardCommand.AddCommand(initDetailsCommand())
39+
boardCommand.AddCommand(detailsCommand)
3840
boardCommand.AddCommand(initListCommand())
39-
boardCommand.AddCommand(initListAllCommand())
41+
boardCommand.AddCommand(listAllCommand)
42+
4043
return boardCommand
4144
}

Diff for: cli/board/details.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,35 @@ import (
2222
"fmt"
2323
"os"
2424

25-
"github.com/arduino/arduino-cli/cli"
25+
"github.com/arduino/arduino-cli/cli/errorcodes"
26+
"github.com/arduino/arduino-cli/cli/instance"
27+
"github.com/arduino/arduino-cli/cli/output"
2628
"github.com/arduino/arduino-cli/commands/board"
2729
"github.com/arduino/arduino-cli/common/formatter"
28-
"github.com/arduino/arduino-cli/output"
2930
rpc "github.com/arduino/arduino-cli/rpc/commands"
3031
"github.com/spf13/cobra"
3132
)
3233

33-
func initDetailsCommand() *cobra.Command {
34-
detailsCommand := &cobra.Command{
35-
Use: "details <FQBN>",
36-
Short: "Print details about a board.",
37-
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
38-
Example: " " + cli.VersionInfo.Application + " board details arduino:avr:nano",
39-
Args: cobra.ExactArgs(1),
40-
Run: runDetailsCommand,
41-
}
42-
return detailsCommand
34+
var detailsCommand = &cobra.Command{
35+
Use: "details <FQBN>",
36+
Short: "Print details about a board.",
37+
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
38+
Example: " " + os.Args[0] + " board details arduino:avr:nano",
39+
Args: cobra.ExactArgs(1),
40+
Run: runDetailsCommand,
4341
}
4442

4543
func runDetailsCommand(cmd *cobra.Command, args []string) {
46-
instance := cli.CreateInstance()
47-
4844
res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{
49-
Instance: instance,
45+
Instance: instance.CreateInstance(),
5046
Fqbn: args[0],
5147
})
5248

5349
if err != nil {
5450
formatter.PrintError(err, "Error getting board details")
55-
os.Exit(cli.ErrGeneric)
51+
os.Exit(errorcodes.ErrGeneric)
5652
}
57-
if cli.OutputJSONOrElse(res) {
53+
if output.OutputJSONOrElse(res) {
5854
outputDetailsResp(res)
5955
}
6056
}

Diff for: cli/board/list.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424
"sort"
2525
"time"
2626

27-
"github.com/arduino/arduino-cli/cli"
27+
"github.com/arduino/arduino-cli/cli/errorcodes"
28+
"github.com/arduino/arduino-cli/cli/instance"
29+
"github.com/arduino/arduino-cli/cli/output"
2830
"github.com/arduino/arduino-cli/commands/board"
2931
"github.com/arduino/arduino-cli/common/formatter"
30-
"github.com/arduino/arduino-cli/output"
3132
rpc "github.com/arduino/arduino-cli/rpc/commands"
3233
"github.com/spf13/cobra"
3334
)
@@ -37,7 +38,7 @@ func initListCommand() *cobra.Command {
3738
Use: "list",
3839
Short: "List connected boards.",
3940
Long: "Detects and displays a list of connected boards to the current computer.",
40-
Example: " " + cli.VersionInfo.Application + " board list --timeout 10s",
41+
Example: " " + os.Args[0] + " board list --timeout 10s",
4142
Args: cobra.NoArgs,
4243
Run: runListCommand,
4344
}
@@ -53,22 +54,20 @@ var listFlags struct {
5354

5455
// runListCommand detects and lists the connected arduino boards
5556
func runListCommand(cmd *cobra.Command, args []string) {
56-
instance := cli.CreateInstance()
57-
5857
if timeout, err := time.ParseDuration(listFlags.timeout); err != nil {
5958
formatter.PrintError(err, "Invalid timeout.")
60-
os.Exit(cli.ErrBadArgument)
59+
os.Exit(errorcodes.ErrBadArgument)
6160
} else {
6261
time.Sleep(timeout)
6362
}
6463

65-
resp, err := board.List(context.Background(), &rpc.BoardListReq{Instance: instance})
64+
resp, err := board.List(context.Background(), &rpc.BoardListReq{Instance: instance.CreateInstance()})
6665
if err != nil {
6766
formatter.PrintError(err, "Error detecting boards")
68-
os.Exit(cli.ErrNetwork)
67+
os.Exit(errorcodes.ErrNetwork)
6968
}
7069

71-
if cli.OutputJSONOrElse(resp) {
70+
if output.OutputJSONOrElse(resp) {
7271
outputListResp(resp)
7372
}
7473
}

Diff for: cli/board/listall.go

+18-19
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,42 @@ import (
2323
"os"
2424
"sort"
2525

26-
"github.com/arduino/arduino-cli/cli"
26+
"github.com/arduino/arduino-cli/cli/errorcodes"
27+
"github.com/arduino/arduino-cli/cli/instance"
28+
"github.com/arduino/arduino-cli/cli/output"
2729
"github.com/arduino/arduino-cli/commands/board"
2830
"github.com/arduino/arduino-cli/common/formatter"
29-
"github.com/arduino/arduino-cli/output"
3031
rpc "github.com/arduino/arduino-cli/rpc/commands"
3132
"github.com/spf13/cobra"
3233
)
3334

34-
func initListAllCommand() *cobra.Command {
35-
listAllCommand := &cobra.Command{
36-
Use: "listall [boardname]",
37-
Short: "List all known boards and their corresponding FQBN.",
38-
Long: "" +
39-
"List all boards that have the support platform installed. You can search\n" +
40-
"for a specific board if you specify the board name",
41-
Example: "" +
42-
" " + cli.VersionInfo.Application + " board listall\n" +
43-
" " + cli.VersionInfo.Application + " board listall zero",
44-
Args: cobra.ArbitraryArgs,
45-
Run: runListAllCommand,
46-
}
47-
return listAllCommand
35+
var listAllCommand = &cobra.Command{
36+
Use: "listall [boardname]",
37+
Short: "List all known boards and their corresponding FQBN.",
38+
Long: "" +
39+
"List all boards that have the support platform installed. You can search\n" +
40+
"for a specific board if you specify the board name",
41+
Example: "" +
42+
" " + os.Args[0] + " board listall\n" +
43+
" " + os.Args[0] + " board listall zero",
44+
Args: cobra.ArbitraryArgs,
45+
Run: runListAllCommand,
4846
}
4947

5048
// runListAllCommand list all installed boards
5149
func runListAllCommand(cmd *cobra.Command, args []string) {
52-
instance := cli.CreateInstance()
50+
instance := instance.CreateInstance()
5351

5452
list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{
5553
Instance: instance,
5654
SearchArgs: args,
5755
})
5856
if err != nil {
5957
formatter.PrintError(err, "Error listing boards")
60-
os.Exit(cli.ErrGeneric)
58+
os.Exit(errorcodes.ErrGeneric)
6159
}
62-
if cli.OutputJSONOrElse(list) {
60+
61+
if output.OutputJSONOrElse(list) {
6362
outputBoardListAll(list)
6463
}
6564
}

0 commit comments

Comments
 (0)