-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview_lib.go
50 lines (42 loc) · 1.38 KB
/
view_lib.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
package main
import (
"flag"
"fmt"
"strings"
"github.com/TuftsBCB/fragbag"
"github.com/TuftsBCB/tools/util"
)
var cmdViewLib = &command{
name: "view-lib",
positionalUsage: "frag-lib",
shortHelp: "view information about a fragment library",
help: `
View information (size, fragment size, type, etc.) about a fragment library.
The information shown is fairly straight-forward. Although, note that the tag
shown is the full tag, including all sub-libraries. Sub-tags are delineated
by the "/" character.
This command may also be used to check if a fragment library is valid. In
particular, if this command fails, then the file given is not in a format
understood by the fragbag package installed.
`,
flags: flag.NewFlagSet("view-lib", flag.ExitOnError),
run: viewLib,
addFlags: nil,
}
func viewLib(c *command) {
c.assertNArg(1)
lib := util.Library(c.flags.Arg(0))
fmt.Printf("Name: %s\n", lib.Name())
fmt.Printf("Tag: %s\n", strings.Join(libraryTag(lib), "/"))
fmt.Printf("Size: %d\n", lib.Size())
fmt.Printf("Fragment Size: %d\n", lib.FragmentSize())
fmt.Printf("IsStructure: %v\n", fragbag.IsStructure(lib))
fmt.Printf("IsSequence: %v\n", fragbag.IsSequence(lib))
}
func libraryTag(lib fragbag.Library) []string {
if sub := lib.SubLibrary(); sub == nil {
return []string{lib.Tag()}
} else {
return append([]string{lib.Tag()}, libraryTag(sub)...)
}
}