summaryrefslogtreecommitdiffstats
path: root/cmd/tuf/set_threshold.go
blob: 29149ff982815be28fb89ef3ddbcd584c990247e (plain)
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
package main

import (
	"fmt"
	"os"
	"strconv"

	"github.com/flynn/go-docopt"
	"github.com/theupdateframework/go-tuf"
)

func init() {
	register("set-threshold", cmdSetThreshold, `
usage: tuf set-threshold <role> <threshold>

Set the threshold for a role.  
`)
}

func cmdSetThreshold(args *docopt.Args, repo *tuf.Repo) error {
	role := args.String["<role>"]
	thresholdStr := args.String["<threshold>"]
	threshold, err := strconv.Atoi(thresholdStr)
	if err != nil {
		return err
	}

	if err := repo.SetThreshold(role, threshold); err != nil {
		return err
	}

	fmt.Fprintf(os.Stdout, "The threshold for %s role is now %d", role, threshold)
	return nil
}