| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
"text/tabwriter" |
| 7 |
|
| 8 |
"github.com/dustin/go-humanize" |
| 9 |
"github.com/flynn/go-docopt" |
| 10 |
tuf "github.com/theupdateframework/go-tuf/client" |
| 11 |
) |
| 12 |
|
| 13 |
func init() { |
| 14 |
register("list", cmdList, ` |
| 15 |
usage: tuf-client list [-s|--store=<path>] <url> |
| 16 |
|
| 17 |
Options: |
| 18 |
-s <path> The path to the local file store [default: tuf.db] |
| 19 |
|
| 20 |
List available target files. |
| 21 |
`) |
| 22 |
} |
| 23 |
|
| 24 |
func cmdList(args *docopt.Args, client *tuf.Client) error { |
| 25 |
if _, err := client.Update(); err != nil { |
| 26 |
return err |
| 27 |
} |
| 28 |
targets, err := client.Targets() |
| 29 |
if err != nil { |
| 30 |
return err |
| 31 |
} |
| 32 |
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0) |
| 33 |
defer w.Flush() |
| 34 |
fmt.Fprintln(w, "PATH\tSIZE") |
| 35 |
for path, meta := range targets { |
| 36 |
fmt.Fprintf(w, "%s\t%s\n", path, humanize.Bytes(uint64(meta.Length))) |
| 37 |
} |
| 38 |
return nil |
| 39 |
} |