-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (63 loc) · 1.56 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/UCLALibrary/pt-tools/cmd/ptcp"
"github.com/UCLALibrary/pt-tools/cmd/ptls"
"github.com/UCLALibrary/pt-tools/cmd/ptmv"
"github.com/UCLALibrary/pt-tools/cmd/ptnew"
"github.com/UCLALibrary/pt-tools/cmd/ptrm"
)
const help = `pt facilitates interactions with a Pairtree without the user needing to know about the Pairtree’s internal structure.
Please refer to the README(https://github.com/UCLALibrary/pt-tools) for more detailed instructions
Usage: pt [command] [options]
Commands:
ls List directories and files
rm Remove files or directories
cp Copy files or directories
mv Move files or directories
new Create a new pairtree object
For more information on a specific command, run 'pt [command] --help'.`
func main() {
// Basic command-line argument parsing
if len(os.Args) < 2 {
fmt.Println(help)
os.Exit(1)
}
command := os.Args[1]
// Pass in os.Args excluding the general and specifc program name
args := os.Args[2:]
// Use os.Stdout for standard output
writer := os.Stdout
switch command {
case "ls":
err := ptls.Run(args, writer)
if err != nil {
os.Exit(2)
}
case "rm":
err := ptrm.Run(args, writer)
if err != nil {
os.Exit(3)
}
case "cp":
err := ptcp.Run(args, writer)
if err != nil {
os.Exit(4)
}
case "mv":
err := ptmv.Run(args, writer)
if err != nil {
os.Exit(5)
}
case "new":
err := ptnew.Run(args, writer)
if err != nil {
os.Exit(6)
}
default:
fmt.Println(help)
log.Fatalf("Unknown command: %s", command)
}
}