This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfo.go
88 lines (78 loc) · 2.16 KB
/
info.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"strings"
"github.com/go2c/optparse"
"github.com/onodera-punpun/prt/ports"
)
// infoCommand prints port information.
func infoCommand(input []string) error {
// Enable all arguments if the user hasn't specified any.
var b bool
if len(input) == 0 {
b = true
}
// Define valid arguments.
o := optparse.New()
argd := o.Bool("description", 'd', b)
argu := o.Bool("url", 'u', b)
argm := o.Bool("maintainer", 'm', b)
arge := o.Bool("depends", 'e', b)
argo := o.Bool("optional", 'o', b)
argv := o.Bool("version", 'v', b)
argr := o.Bool("release", 'r', b)
args := o.Bool("source", 's', b)
argh := o.Bool("help", 'h', false)
// Parse arguments.
_, err := o.Parse(input)
if err != nil {
return fmt.Errorf("invaild argument, use `-h` for a list of arguments")
}
// Print help.
if *argh {
fmt.Println("Usage: prt info [arguments]")
fmt.Println("")
fmt.Println("arguments:")
fmt.Println(" -d, --description print description")
fmt.Println(" -u, --url print url")
fmt.Println(" -m, --maintainer print maintainer")
fmt.Println(" -e, --depends print dependencies")
fmt.Println(" -o, --optional print optional dependencies")
fmt.Println(" -v, --version print version")
fmt.Println(" -r, --release print release")
fmt.Println(" -s, --source print sources")
fmt.Println(" -h, --help print help and exit")
return nil
}
// Read out Pkgfile.
p := ports.New(".")
if err := p.Pkgfile.Parse(true); err != nil {
return err
}
// Print info from Pkgfile.
if *argd {
fmt.Println("Description: " + p.Pkgfile.Description)
}
if *argu {
fmt.Println("URL: " + p.Pkgfile.URL)
}
if *argm {
fmt.Println("Maintainer: " + p.Pkgfile.Maintainer)
}
if *arge {
fmt.Println("Depends on: " + strings.Join(p.Pkgfile.Depends, ", "))
}
if *argo {
fmt.Println("Nice to have: " + strings.Join(p.Pkgfile.Optional, ", "))
}
if *argv {
fmt.Println("Version: " + p.Pkgfile.Version)
}
if *argr {
fmt.Println("Release: " + p.Pkgfile.Release)
}
if *args {
fmt.Println("Source: " + strings.Join(p.Pkgfile.Source, ", "))
}
return nil
}