aboutsummaryrefslogtreecommitdiff
path: root/cmd/list.go
blob: 94c18b8a8cdaff5282a76f4d35ee7bac464cc933 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cmd

import (
	"fmt"
	"flag"
	"golang.flu0r1ne.net/zsu/snap"
)

func List(params []string) {
	flags := flag.NewFlagSet("list", flag.ExitOnError)

	var withPaths bool
	
	withName := aliasedBoolVar(
		flags,
		&withPaths,
		false,
		"print paths to the provided reference within the snapshot",
	)

	withName("paths")
	withName("p")

	flags.Parse(params);

	if(flags.NArg() == 0) {
		die.Fatal("Reference file is required")
	}

	if(flags.NArg() > 1) {
		die.Fatal("Too many arguments provided")
	}
	
	reference := flags.Arg(0)

	snaps := snap.GetTimeseries(reference)

	for _, s := range snaps {
		if s.Reference == "" {
			continue
		}

		fmt.Printf("%s", s.Name)

		if withPaths {
			fmt.Printf(", %s", s.Reference)
		}

		fmt.Println("")
	}
}