This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscan.go
59 lines (47 loc) · 1.68 KB
/
scan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/tonglil/labeler/logs"
"github.com/tonglil/labeler/reader"
"github.com/tonglil/labeler/types"
"github.com/tonglil/labeler/utils"
)
// scanCmd represents the scan command
var scanCmd = &cobra.Command{
Use: "scan file",
Short: "Save a repository's labels into a YAML definition file",
Long: `Save remote labels into a file`,
Example: `$ labeler scan labels.yaml -r docker/docker -l 5
Scan the labels from the "docker/docker" repository into a
file called "labels.yaml", logging what happened.`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
fmt.Println(cmd.UsageString())
return fmt.Errorf("no file given")
}
file := args[0]
client, err := utils.GetClient(endpoint, token)
if err != nil {
return err
}
opt := &types.Options{
DryRun: cmd.Flag("dryrun").Changed,
Repo: cmd.Flag("repo").Value.String(),
Filename: file,
}
if opt.DryRun {
logs.V(0).Infof("Dry run enabled - changes will not be applied")
}
return reader.Run(client, opt)
},
}
func init() {
RootCmd.AddCommand(scanCmd)
scanCmd.PersistentFlags().BoolVarP(&dryrun, "dryrun", "d", false, "Show what would happen")
scanCmd.PersistentFlags().StringVarP(&repo, "repo", "r", "", "GitHub repository (default is read from the file)")
scanCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "The GithHub token [overrides GITHUB_TOKEN]")
scanCmd.PersistentFlags().StringVarP(&endpoint, "api", "a", utils.Api, "The GithHub API endpoint [overrides GITHUB_API]")
scanCmd.PersistentFlags().IntVarP(&logs.Threshold, "level", "l", 1, "The maximum level of logging to display")
}