Skip to content

Commit 82c627a

Browse files
committed
Moved args into their correct place
1 parent 08708b9 commit 82c627a

File tree

6 files changed

+21
-35
lines changed

6 files changed

+21
-35
lines changed

internal/cli/profile/profile.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ package profile
1818
import (
1919
"os"
2020

21-
"github.com/arduino/arduino-cli/internal/cli/arguments"
2221
"github.com/arduino/arduino-cli/internal/i18n"
2322
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2423
"github.com/spf13/cobra"
2524
)
2625

27-
var (
28-
fqbnArg arguments.Fqbn // Fully Qualified Board Name, e.g.: arduino:avr:uno.
29-
profileArg arguments.Profile // Name of the profile to add to the project
30-
)
31-
3226
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3327
profileCommand := &cobra.Command{
3428
Use: "profile",
@@ -40,7 +34,5 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4034
profileCommand.AddCommand(initProfileCreateCommand(srv))
4135
profileCommand.AddCommand(initProfileLibCommand(srv))
4236
profileCommand.AddCommand(initProfileSetDefaultCommand(srv))
43-
// profileCommand.AddCommand(initDumpCommand(srv))
44-
4537
return profileCommand
4638
}

internal/cli/profile/profile_init.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929
)
3030

3131
func initProfileCreateCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
32-
var defaultProfile bool
32+
var setAsDefault bool
33+
var fqbnArg arguments.Fqbn
34+
var profileArg arguments.Profile
3335
initCommand := &cobra.Command{
3436
Use: "init",
3537
Short: i18n.Tr("Create or update the sketch project file."),
@@ -40,16 +42,16 @@ func initProfileCreateCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4042
" " + os.Args[0] + " profile init --profile uno_profile -b arduino:avr:uno",
4143
Args: cobra.MaximumNArgs(1),
4244
Run: func(cmd *cobra.Command, args []string) {
43-
runInitCommand(cmd.Context(), args, srv, defaultProfile)
45+
runInitCommand(cmd.Context(), args, srv, profileArg.Get(), fqbnArg.String(), setAsDefault)
4446
},
4547
}
4648
fqbnArg.AddToCommand(initCommand, srv)
4749
profileArg.AddToCommand(initCommand, srv)
48-
initCommand.Flags().BoolVar(&defaultProfile, "default", false, i18n.Tr("Set the profile as the default one."))
50+
initCommand.Flags().BoolVar(&setAsDefault, "set-default", false, i18n.Tr("Set the profile as the default one."))
4951
return initCommand
5052
}
5153

52-
func runInitCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer, defaultProfile bool) {
54+
func runInitCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer, profile, fqbn string, setAsDefault bool) {
5355
path := ""
5456
if len(args) > 0 {
5557
path = args[0]
@@ -62,9 +64,9 @@ func runInitCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServi
6264
_, err := srv.ProfileCreate(ctx, &rpc.ProfileCreateRequest{
6365
Instance: inst,
6466
SketchPath: sketchPath.String(),
65-
ProfileName: profileArg.Get(),
66-
Fqbn: fqbnArg.String(),
67-
DefaultProfile: defaultProfile})
67+
ProfileName: profile,
68+
Fqbn: fqbn,
69+
DefaultProfile: setAsDefault})
6870
if err != nil {
6971
feedback.Fatal(i18n.Tr("Error initializing the project file: %v", err), feedback.ErrGeneric)
7072
}
@@ -75,7 +77,7 @@ type profileResult struct {
7577
ProjectFilePath *paths.Path `json:"project_path"`
7678
}
7779

78-
func (ir profileResult) Data() interface{} {
80+
func (ir profileResult) Data() any {
7981
return ir
8082
}
8183

internal/cli/profile/profile_lib.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ func initProfileLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3131
" " + os.Args[0] + " profile lib add AudioZero -m my_profile\n" +
3232
" " + os.Args[0] + " profile lib remove Arduino_JSON --profile my_profile\n",
3333
}
34-
3534
libCommand.AddCommand(initLibAddCommand(srv))
3635
libCommand.AddCommand(initLibRemoveCommand(srv))
37-
3836
return libCommand
3937
}

internal/cli/profile/profile_lib_add.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3535
var destDir string
3636
var noDeps bool
3737
var noOverwrite bool
38+
var profileArg arguments.Profile
3839
addCommand := &cobra.Command{
3940
Use: fmt.Sprintf("add %s[@%s]...", i18n.Tr("LIBRARY"), i18n.Tr("VERSION_NUMBER")),
4041
Short: i18n.Tr("Adds a library to a sketch profile."),
@@ -43,23 +44,20 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4344
" " + os.Args[0] + " profile lib add [email protected] --profile my_profile\n",
4445
Args: cobra.MinimumNArgs(1),
4546
Run: func(cmd *cobra.Command, args []string) {
46-
runLibAddCommand(cmd.Context(), args, srv, destDir, noDeps, noOverwrite)
47+
runLibAddCommand(cmd.Context(), args, srv, profileArg.Get(), destDir, noDeps, noOverwrite)
4748
},
4849
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
4950
return arguments.GetInstallableLibs(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
5051
},
5152
}
52-
53+
profileArg.AddToCommand(addCommand, srv)
5354
addCommand.Flags().StringVar(&destDir, "dest-dir", "", i18n.Tr("Location of the sketch project file."))
5455
addCommand.Flags().BoolVar(&noDeps, "no-deps", false, i18n.Tr("Do not add dependencies."))
5556
addCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, i18n.Tr("Do not overwrite already added libraries."))
56-
57-
profileArg.AddToCommand(addCommand, srv)
58-
5957
return addCommand
6058
}
6159

62-
func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer, destDir string, noAddDeps, noOverwrite bool) {
60+
func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer, profile, destDir string, noAddDeps, noOverwrite bool) {
6361
sketchPath := arguments.InitSketchPath(destDir)
6462

6563
instance := instance.CreateAndInit(ctx, srv)
@@ -72,7 +70,7 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
7270
resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{
7371
Instance: instance,
7472
SketchPath: sketchPath.String(),
75-
ProfileName: profileArg.Get(),
73+
ProfileName: profile,
7674
Library: &rpc.ProfileLibraryReference{
7775
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
7876
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{
@@ -85,7 +83,7 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
8583
NoOverwrite: &noOverwrite,
8684
})
8785
if err != nil {
88-
feedback.Fatal(i18n.Tr("Error adding %s to the profile %s: %v", lib.Name, profileArg.Get(), err), feedback.ErrGeneric)
86+
feedback.Fatal(i18n.Tr("Error adding %s to the profile %s: %v", lib.Name, profile, err), feedback.ErrGeneric)
8987
}
9088
feedback.PrintResult(libAddResult{
9189
AddedLibraries: f.Map(resp.GetAddedLibraries(), result.NewProfileLibraryReference),

internal/cli/profile/profile_lib_remove.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
func initLibRemoveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3535
var destDir string
36-
36+
var profileArg arguments.Profile
3737
removeCommand := &cobra.Command{
3838
Use: fmt.Sprintf("remove %s[@%s]...", i18n.Tr("LIBRARY"), i18n.Tr("VERSION_NUMBER")),
3939
Short: i18n.Tr("Removes a library from a sketch profile."),
@@ -42,20 +42,18 @@ func initLibRemoveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4242
" " + os.Args[0] + " profile lib remove [email protected] --profile my_profile\n",
4343
Args: cobra.MinimumNArgs(1),
4444
Run: func(cmd *cobra.Command, args []string) {
45-
runLibRemoveCommand(cmd.Context(), args, srv, destDir)
45+
runLibRemoveCommand(cmd.Context(), srv, args, profileArg.Get(), destDir)
4646
},
4747
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
4848
return arguments.GetInstallableLibs(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
4949
},
5050
}
51-
52-
removeCommand.Flags().StringVar(&destDir, "dest-dir", "", i18n.Tr("Location of the sketch project file."))
5351
profileArg.AddToCommand(removeCommand, srv)
54-
52+
removeCommand.Flags().StringVar(&destDir, "dest-dir", "", i18n.Tr("Location of the sketch project file."))
5553
return removeCommand
5654
}
5755

58-
func runLibRemoveCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer, destDir string) {
56+
func runLibRemoveCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, profile, destDir string) {
5957
sketchPath := arguments.InitSketchPath(destDir)
6058

6159
instance := instance.CreateAndInit(ctx, srv)
@@ -66,7 +64,7 @@ func runLibRemoveCommand(ctx context.Context, args []string, srv rpc.ArduinoCore
6664
for _, lib := range libRefs {
6765
resp, err := srv.ProfileLibRemove(ctx, &rpc.ProfileLibRemoveRequest{
6866
SketchPath: sketchPath.String(),
69-
ProfileName: profileArg.Get(),
67+
ProfileName: profile,
7068
Library: &rpc.ProfileLibraryReference{
7169
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
7270
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{

internal/cli/profile/profile_set-default.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ func initProfileSetDefaultCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Comma
3939
runSetDefaultCommand(cmd.Context(), args, srv, destDir)
4040
},
4141
}
42-
4342
setDefaultCommand.Flags().StringVar(&destDir, "dest-dir", "", i18n.Tr("Location of the sketch project file."))
44-
4543
return setDefaultCommand
4644
}
4745

0 commit comments

Comments
 (0)