...
1 package main
2
3 import (
4 "encoding/json"
5
6 "github.com/flynn/go-docopt"
7 "github.com/theupdateframework/go-tuf"
8 )
9
10 func init() {
11 register("add", cmdAdd, `
12 usage: tuf add [--expires=<days>] [--custom=<data>] [<path>...]
13
14 Add target file(s).
15
16 Alternatively, passphrases can be set via environment variables in the
17 form of TUF_{{ROLE}}_PASSPHRASE
18
19 Options:
20 --expires=<days> Set the targets metadata file to expire <days> days from now.
21 --custom=<data> Set custom JSON data for the target(s).
22 `)
23 }
24
25 func cmdAdd(args *docopt.Args, repo *tuf.Repo) error {
26 var custom json.RawMessage
27 if c := args.String["--custom"]; c != "" {
28 custom = json.RawMessage(c)
29 }
30 paths := args.All["<path>"].([]string)
31 if arg := args.String["--expires"]; arg != "" {
32 expires, err := parseExpires(arg)
33 if err != nil {
34 return err
35 }
36 return repo.AddTargetsWithExpires(paths, custom, expires)
37 }
38 return repo.AddTargets(paths, custom)
39 }
40
View as plain text