-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
51 lines (47 loc) · 1.14 KB
/
lookup.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
//nolint:gochecknoglobals,gochecknoinits
package cmd
import (
"fmt"
"os"
"github.com/Defacto2/df2/pkg/database"
"github.com/spf13/cobra"
)
var lookupCmd = &cobra.Command{
Use: "lookup (ids|uuids)",
Short: "Lookup the file URL of a record's ID or UUID.",
Aliases: []string{"l"},
GroupID: "group3",
Example: ` id is a unique numeric identifier
uuid is a unique 35-character hexadecimal string representation of a 128-bit integer
uuid character groups are 8-4-4-16 (xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx)`,
Hidden: false,
Run: func(cmd *cobra.Command, args []string) {
db, err := database.Connect(confg)
if err != nil {
logr.Fatal(err)
}
defer db.Close()
if len(args) == 0 {
if err := cmd.Usage(); err != nil {
logr.Fatal(err)
}
return
}
for _, a := range args {
if err := database.CheckID(a); err != nil {
logr.Infof("%s: %s\n", ErrID, a)
continue
}
id, err := database.GetID(db, a)
if err != nil {
logr.Info(err)
continue
}
fmt.Fprintf(os.Stdout, "https://defacto2.net/f/%v\n",
database.ObfuscateParam(fmt.Sprint(id)))
}
},
}
func init() {
rootCmd.AddCommand(lookupCmd)
}