NewFileCmd returns a new instance of the 'file' command.
()
| 38 | |
| 39 | // NewFileCmd returns a new instance of the 'file' command. |
| 40 | func NewFileCmd() *cobra.Command { |
| 41 | cmd := &cobra.Command{ |
| 42 | Use: "file [hash]...", |
| 43 | Short: "Get information about files", |
| 44 | Long: fileCmdHelp, |
| 45 | Example: fileCmdExample, |
| 46 | Args: cobra.MinimumNArgs(1), |
| 47 | |
| 48 | RunE: func(cmd *cobra.Command, args []string) error { |
| 49 | re, _ := regexp.Compile("[[:xdigit:]]{64}|[[:xdigit:]]{40}|[[:xdigit:]]{32}") |
| 50 | p, err := NewPrinter(cmd) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | if viper.GetBool("private") { |
| 55 | return p.GetAndPrintObjectsWithFallback( |
| 56 | []string{"files/%s", "private/files/%s"}, |
| 57 | utils.StringReaderFromCmdArgs(args), |
| 58 | re) |
| 59 | } else { |
| 60 | return p.GetAndPrintObjects( |
| 61 | "files/%s", |
| 62 | utils.StringReaderFromCmdArgs(args), |
| 63 | re) |
| 64 | } |
| 65 | }, |
| 66 | } |
| 67 | |
| 68 | addRelationshipCmds(cmd, "files", "file", "[hash]", true) |
| 69 | |
| 70 | addThreadsFlag(cmd.Flags()) |
| 71 | addIncludeExcludeFlags(cmd.Flags()) |
| 72 | addIDOnlyFlag(cmd.Flags()) |
| 73 | addPrivateFlag(cmd.Flags()) |
| 74 | |
| 75 | return cmd |
| 76 | } |
no test coverage detected