Skip to content

Commit c204c01

Browse files
committed
Added lib deps command
1 parent c4eb909 commit c204c01

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

Diff for: cli/lib/check_deps.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to [email protected].
16+
*/
17+
18+
package lib
19+
20+
import (
21+
"context"
22+
"os"
23+
24+
"github.com/arduino/arduino-cli/cli/errorcodes"
25+
"github.com/arduino/arduino-cli/cli/feedback"
26+
"github.com/arduino/arduino-cli/cli/globals"
27+
"github.com/arduino/arduino-cli/cli/instance"
28+
"github.com/arduino/arduino-cli/commands/lib"
29+
rpc "github.com/arduino/arduino-cli/rpc/commands"
30+
"github.com/fatih/color"
31+
"github.com/spf13/cobra"
32+
)
33+
34+
func initDepsCommand() *cobra.Command {
35+
depsCommand := &cobra.Command{
36+
Use: "deps LIBRARY[@VERSION_NUMBER](S)",
37+
Short: "Check dependencies status for the specified library.",
38+
Long: "Check dependencies status for the specified library.",
39+
Example: "" +
40+
" " + os.Args[0] + " lib deps AudioZero # for the latest version.\n" +
41+
" " + os.Args[0] + " lib deps [email protected] # for the specific version.",
42+
Args: cobra.ExactArgs(1),
43+
Run: runDepsCommand,
44+
}
45+
return depsCommand
46+
}
47+
48+
func runDepsCommand(cmd *cobra.Command, args []string) {
49+
libRef, err := globals.ParseLibraryReferenceArg(args[0])
50+
if err != nil {
51+
feedback.Errorf("Arguments error: %v", err)
52+
os.Exit(errorcodes.ErrBadArgument)
53+
}
54+
55+
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
56+
deps, err := lib.LibraryResolveDependencies(context.Background(), &rpc.LibraryResolveDependenciesReq{
57+
Instance: instance,
58+
Name: libRef.Name,
59+
Version: libRef.Version,
60+
})
61+
if err != nil {
62+
feedback.Errorf("Error resolving dependencies for %s: %s", libRef, err)
63+
}
64+
65+
if globals.OutputFormat == "json" {
66+
feedback.PrintJSON(deps)
67+
} else {
68+
outputDeps(deps)
69+
}
70+
}
71+
72+
func outputDeps(deps *rpc.LibraryResolveDependenciesResp) {
73+
for _, dep := range deps.GetDependencies() {
74+
outputDep(dep)
75+
}
76+
}
77+
78+
func outputDep(dep *rpc.LibraryDependencyStatus) {
79+
green := color.New(color.FgGreen)
80+
red := color.New(color.FgRed)
81+
yellow := color.New(color.FgYellow)
82+
if dep.GetVersionInstalled() == "" {
83+
feedback.Printf("%s must be installed.",
84+
red.Sprintf("✕ %s %s", dep.GetName(), dep.GetVersionRequired()))
85+
} else if dep.GetVersionInstalled() == dep.GetVersionRequired() {
86+
feedback.Printf("%s is already installed.",
87+
green.Sprintf("✓ %s %s", dep.GetName(), dep.GetVersionRequired()))
88+
} else {
89+
feedback.Printf("%s is required but %s is currently installed.",
90+
yellow.Sprintf("✕ %s %s", dep.GetName(), dep.GetVersionRequired()),
91+
yellow.Sprintf("%s", dep.GetVersionInstalled()))
92+
}
93+
}

Diff for: cli/lib/lib.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ func NewCommand() *cobra.Command {
4141
libCommand.AddCommand(initUninstallCommand())
4242
libCommand.AddCommand(initUpgradeCommand())
4343
libCommand.AddCommand(initUpdateIndexCommand())
44-
44+
libCommand.AddCommand(initDepsCommand())
4545
return libCommand
4646
}

0 commit comments

Comments
 (0)