Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde882e4

Browse files
committed
Added lib deps command
1 parent92db6f7 commitde882e4

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

‎cli/lib/check_deps.go‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 license@arduino.cc.
16+
*/
17+
18+
package lib
19+
20+
import (
21+
"context"
22+
"fmt"
23+
"os"
24+
25+
"github.com/arduino/arduino-cli/cli/errorcodes"
26+
"github.com/arduino/arduino-cli/cli/feedback"
27+
"github.com/arduino/arduino-cli/cli/globals"
28+
"github.com/arduino/arduino-cli/cli/instance"
29+
"github.com/arduino/arduino-cli/commands/lib"
30+
rpc"github.com/arduino/arduino-cli/rpc/commands"
31+
"github.com/fatih/color"
32+
"github.com/spf13/cobra"
33+
)
34+
35+
funcinitDepsCommand()*cobra.Command {
36+
depsCommand:=&cobra.Command{
37+
Use:"deps LIBRARY[@VERSION_NUMBER](S)",
38+
Short:"Check dependencies status for the specified library.",
39+
Long:"Check dependencies status for the specified library.",
40+
Example:""+
41+
" "+os.Args[0]+" lib deps AudioZero # for the latest version.\n"+
42+
" "+os.Args[0]+" lib deps AudioZero@1.0.0 # for the specific version.",
43+
Args:cobra.ExactArgs(1),
44+
Run:runDepsCommand,
45+
}
46+
returndepsCommand
47+
}
48+
49+
funcrunDepsCommand(cmd*cobra.Command,args []string) {
50+
libRef,err:=globals.ParseLibraryReferenceArg(args[0])
51+
iferr!=nil {
52+
feedback.Errorf("Arguments error: %v",err)
53+
os.Exit(errorcodes.ErrBadArgument)
54+
}
55+
56+
instance:=instance.CreateInstaceIgnorePlatformIndexErrors()
57+
deps,err:=lib.LibraryResolveDependencies(context.Background(),&rpc.LibraryResolveDependenciesReq{
58+
Instance:instance,
59+
Name:libRef.Name,
60+
Version:libRef.Version,
61+
})
62+
iferr!=nil {
63+
feedback.Errorf("Error resolving dependencies for %s: %s",libRef,err)
64+
}
65+
66+
feedback.PrintResult(&checkDepResult{deps:deps})
67+
}
68+
69+
// output from this command requires special formatting, let's create a dedicated
70+
// feedback.Result implementation
71+
typecheckDepResultstruct {
72+
deps*rpc.LibraryResolveDependenciesResp
73+
}
74+
75+
func (drcheckDepResult)Data()interface{} {
76+
returndr.deps
77+
}
78+
79+
func (drcheckDepResult)String()string {
80+
res:=""
81+
for_,dep:=rangedr.deps.GetDependencies() {
82+
res+=outputDep(dep)
83+
}
84+
returnres
85+
}
86+
87+
funcoutputDep(dep*rpc.LibraryDependencyStatus)string {
88+
res:=""
89+
green:=color.New(color.FgGreen)
90+
red:=color.New(color.FgRed)
91+
yellow:=color.New(color.FgYellow)
92+
ifdep.GetVersionInstalled()=="" {
93+
res+=fmt.Sprintf("%s must be installed.\n",
94+
red.Sprintf("✕ %s %s",dep.GetName(),dep.GetVersionRequired()))
95+
}elseifdep.GetVersionInstalled()==dep.GetVersionRequired() {
96+
res+=fmt.Sprintf("%s is already installed.\n",
97+
green.Sprintf("✓ %s %s",dep.GetName(),dep.GetVersionRequired()))
98+
}else {
99+
res+=fmt.Sprintf("%s is required but %s is currently installed.\n",
100+
yellow.Sprintf("✕ %s %s",dep.GetName(),dep.GetVersionRequired()),
101+
yellow.Sprintf("%s",dep.GetVersionInstalled()))
102+
}
103+
returnres
104+
}

‎cli/lib/lib.go‎

Lines changed: 1 addition & 1 deletion
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
returnlibCommand
4646
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp