Skip to content

Commit 9b4218b

Browse files
committed
Align graph inputs with update subcmd
1 parent bd44999 commit 9b4218b

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

cmd/dependabot/internal/cmd/graph.go

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package cmd
33
import (
44
"context"
55
"errors"
6+
"fmt"
7+
"io"
68
"log"
9+
"os"
710

811
"github.com/MakeNowJust/heredoc"
912
"github.com/dependabot/cli/internal/infra"
@@ -20,21 +23,35 @@ func NewGraphCommand() *cobra.Command {
2023
var flags UpdateFlags
2124

2225
cmd := &cobra.Command{
23-
Use: "graph [<package_manager> <repo>] [flags]",
26+
Use: "graph [<package_manager> <repo> | -f <input.yml>] [flags]",
2427
Short: "List the dependencies of a manifest/lockfile",
2528
Example: heredoc.Doc(`
26-
$ dependabot graph go_modules rsc/quote
27-
$ dependabot graph go_modules --local .
29+
$ dependabot graph bundler dependabot/dependabot-core
30+
$ dependabot graph bundler --local .
31+
$ dependabot graph -f input.yml
2832
`),
2933
RunE: func(cmd *cobra.Command, args []string) error {
30-
input, err := readArguments(cmd, &flags)
34+
var outFile *os.File
35+
if flags.output != "" {
36+
var err error
37+
outFile, err = os.Create(flags.output)
38+
if err != nil {
39+
return fmt.Errorf("failed to create output file: %w", err)
40+
}
41+
defer outFile.Close()
42+
}
43+
44+
input, err := extractInput(cmd, &flags)
3145
if err != nil {
3246
return err
3347
}
3448

3549
processInput(input, &flags)
3650

37-
input.Job.Source.Provider = "github" // TODO why isn't this being set?
51+
var writer io.Writer
52+
if !flags.debugging {
53+
writer = os.Stdout
54+
}
3855

3956
if err := infra.Run(infra.RunParams{
4057
Command: infra.UpdateGraphCommand,
@@ -44,7 +61,7 @@ func NewGraphCommand() *cobra.Command {
4461
Creds: input.Credentials,
4562
Debug: flags.debugging,
4663
Flamegraph: flags.flamegraph,
47-
Expected: nil, // update subcommand doesn't use expectations
64+
Expected: nil, // graph subcommand doesn't use expectations
4865
ExtraHosts: flags.extraHosts,
4966
InputName: flags.file,
5067
Job: &input.Job,
@@ -56,22 +73,22 @@ func NewGraphCommand() *cobra.Command {
5673
Timeout: flags.timeout,
5774
UpdaterImage: updaterImage,
5875
Volumes: flags.volumes,
59-
Writer: nil, // prevent outputting all API responses to stdout, we only want dependencies
76+
Writer: writer,
77+
ApiUrl: flags.apiUrl,
6078
}); err != nil {
6179
if errors.Is(err, context.DeadlineExceeded) {
6280
log.Fatalf("update timed out after %s", flags.timeout)
6381
}
64-
// HACK: we cancel context to stop the containers, so we don't know if there was a failure.
65-
// A correct solution would involve changes with dependabot-core, which is good, but
66-
// I am just hacking this together right now.
67-
// log.Fatalf("updater failure: %v", err)
68-
return nil
82+
log.Fatalf("updater failure: %v", err)
6983
}
7084

7185
return nil
7286
},
7387
}
7488

89+
cmd.Flags().StringVarP(&flags.file, "file", "f", "", "path to input file")
90+
91+
cmd.Flags().StringVarP(&flags.provider, "provider", "p", "github", "provider of the repository")
7592
cmd.Flags().StringVarP(&flags.branch, "branch", "b", "", "target branch to update")
7693
cmd.Flags().StringVarP(&flags.directory, "directory", "d", "/", "directory to update")
7794
cmd.Flags().StringVarP(&flags.commit, "commit", "", "", "commit to update")
@@ -87,6 +104,8 @@ func NewGraphCommand() *cobra.Command {
87104
cmd.Flags().StringArrayVarP(&flags.volumes, "volume", "v", nil, "mount volumes in Docker")
88105
cmd.Flags().StringArrayVar(&flags.extraHosts, "extra-hosts", nil, "Docker extra hosts setting on the proxy")
89106
cmd.Flags().DurationVarP(&flags.timeout, "timeout", "t", 0, "max time to run an update")
107+
cmd.Flags().IntVar(&flags.inputServerPort, "input-port", 0, "port to use for securely passing input to the updater")
108+
cmd.Flags().StringVarP(&flags.apiUrl, "api-url", "a", "", "the api dependabot should connect to.")
90109

91110
return cmd
92111
}

0 commit comments

Comments
 (0)