-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaho.awk
109 lines (96 loc) · 2.55 KB
/
aho.awk
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
@include "version.awk"
@include "utils.awk"
@include "path.awk"
@include "tree.awk"
@include "stat.awk"
@include "getopt.awk"
@include "refs.awk"
@include "reflog.awk"
@include "branches.awk"
@include "objects.awk"
@include "head.awk"
@include "index.awk"
@include "workingtree.awk"
@include "colors.awk"
# Commands
@include "config.awk"
@include "init.awk"
@include "add.awk"
@include "rm.awk"
@include "status.awk"
@include "commit.awk"
@include "catfile.awk"
@namespace "main"
BEGIN {
if (ARGC == 1) {
print_help()
exit 1
}
exit main()
}
function main( shortopts, longopts, c, command, exitcode)
{
getopt::Optind = 1 # start at first option
getopt::Opterr = 1 # print parse errors
shortopts = "h"
longopts = "version,help"
while ((c = getopt::getopt(ARGC, ARGV, shortopts, longopts)) != -1) {
if (c == "?") {
print_usage()
return 129
}
if (getopt::Optopt == "h" || getopt::Optopt == "help") {
print_help()
return 0
}
if (getopt::Optopt == "version") {
print_version()
return 0
}
}
command = ARGV[getopt::Optind++]
if (command != "init") {
path::assert_in_repo()
}
if (command == "init") {
exitcode = init::run_command()
} else if (command == "add") {
exitcode = add::run_command()
} else if (command == "rm") {
exitcode = rm::run_command()
} else if (command == "commit") {
exitcode = commit::run_command()
} else if (command == "cat-file") {
exitcode = catfile::run_command()
} else if (command == "status") {
exitcode = status::run_command()
} else if (command == "config") {
exitcode = config::run_command()
} else {
print "aho: " command " is not an aho command. See 'aho --help'\n" \
> "/dev/stderr"
print_usage()
exitcode = 1
}
return exitcode
}
function print_usage()
{
print "usage: aho [--version] [--help] <command> [<args>]"
}
function print_help()
{
print_usage()
print
print "Commands:"
print " init Create an empty repo"
print " add Add file contents to the index"
print " rm Remove files from the working tree and from the index"
print " config Read or modify " path::AhoDir "/config"
print " status Show the working tree status"
print " commit Record changes to the repository"
}
function print_version()
{
print "aho version " version::String
}