Skip to content

Commit a4bca58

Browse files
committed
feat: add option 'skip-checksum' to install subcommand. #172
1 parent 00c94c6 commit a4bca58

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

cli/commands.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ var (
7979
Aliases: []string{"n"},
8080
Usage: "Only install without using",
8181
},
82+
&cli.BoolFlag{
83+
Name: "skip-checksum",
84+
Usage: "Skip checksum verification",
85+
},
8286
},
8387
},
8488
{

cli/install.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,25 @@ func install(ctx *cli.Context) (err error) {
103103
pkg = pkgs[0]
104104
}
105105

106-
var checksumNotFound, skipChecksum bool
107-
if pkg.Checksum == "" && pkg.ChecksumURL == "" {
108-
checksumNotFound = true
109-
menu := wmenu.NewMenu("Checksum file not found, do you want to continue?")
110-
menu.IsYesNo(wmenu.DefN)
111-
menu.Action(func(opts []wmenu.Opt) error {
112-
skipChecksum = opts[0].Value.(string) == "yes"
113-
return nil
114-
})
115-
if err = menu.Run(); err != nil {
116-
return cli.Exit(errstring(err), 1)
106+
skipChecksum := ctx.Bool("skip-checksum")
107+
108+
if !skipChecksum {
109+
var checksumNotFound bool
110+
if pkg.Checksum == "" && pkg.ChecksumURL == "" {
111+
checksumNotFound = true
112+
menu := wmenu.NewMenu("Checksum file not found, do you want to continue?")
113+
menu.IsYesNo(wmenu.DefN)
114+
menu.Action(func(opts []wmenu.Opt) error {
115+
skipChecksum = opts[0].Value.(string) == "yes"
116+
return nil
117+
})
118+
if err = menu.Run(); err != nil {
119+
return cli.Exit(errstring(err), 1)
120+
}
121+
}
122+
if checksumNotFound && !skipChecksum {
123+
return
117124
}
118-
}
119-
if checksumNotFound && !skipChecksum {
120-
return
121125
}
122126

123127
var ext string

cli/mcp.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ func lsRemoteHandler(ctx context.Context, req *protocol.CallToolRequest) (*proto
236236
}
237237

238238
type InstallReq struct {
239-
Version string `json:"version" description:"Go sdk version number keywords. Keywords match the following patterns: \n1. Specific version (e.g. '1.21.4'); \n2. Latest version identifier 'latest'; \n3. Wildcards (e.g. '1.21.x', '1.x', '1.18.*'); \n4. Caret ranges for minor version compatibility (e.g. '^1', '^1.18', '^1.18.10'); \n5. Tilde ranges for patch version updates (e.g. '~1.18'); \n6. Greater than comparisons (e.g. '>1.18'); \n7. Less than comparisons (e.g. '<1.16'); \n8. Version ranges (e.g. '1.18-1.20');" required:"true"`
240-
Nouse bool `json:"nouse" description:"Don't use the version after installed." required:"false"`
239+
Version string `json:"version" description:"Go sdk version number keywords. Keywords match the following patterns: \n1. Specific version (e.g. '1.21.4'); \n2. Latest version identifier 'latest'; \n3. Wildcards (e.g. '1.21.x', '1.x', '1.18.*'); \n4. Caret ranges for minor version compatibility (e.g. '^1', '^1.18', '^1.18.10'); \n5. Tilde ranges for patch version updates (e.g. '~1.18'); \n6. Greater than comparisons (e.g. '>1.18'); \n7. Less than comparisons (e.g. '<1.16'); \n8. Version ranges (e.g. '1.18-1.20');" required:"true"`
240+
Nouse bool `json:"nouse" description:"Don't use the version after installed." required:"false"`
241+
SkipChecksum bool `json:"skip-checksum" description:"Skip checksum verification." required:"false"`
241242
}
242243

243244
func installHandler(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error) {
@@ -246,7 +247,7 @@ func installHandler(ctx context.Context, req *protocol.CallToolRequest) (*protoc
246247
return nil, err
247248
}
248249

249-
cmd := exec.CommandContext(ctx, "g", "install", fmt.Sprintf("--nouse=%t", installReq.Nouse), installReq.Version)
250+
cmd := exec.CommandContext(ctx, "g", "install", fmt.Sprintf("--nouse=%t", installReq.Nouse), fmt.Sprintf("--skip-checksum=%t", installReq.SkipChecksum), installReq.Version)
250251
output, err := cmd.CombinedOutput()
251252
if err != nil {
252253
return nil, errors.WithStack(err)

0 commit comments

Comments
 (0)