-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
85 lines (73 loc) · 1.42 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
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"fmt"
"io"
"os"
"sort"
"time"
"github.com/urfave/cli/v2"
)
const version = "v1.1.0"
// Cheap testing.
var writer io.Writer = os.Stdout
func main() {
runCli()
}
func runCli() {
cli := bootstrapCli()
err := cli.Run(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func bootstrapCli() *cli.App {
flag.Parse()
nc := nepcalCli{}
app := &cli.App{
Name: "nepcal",
Version: version,
Usage: "Calendar and conversion utilities for Nepali dates",
HideVersion: true,
HideHelpCommand: true,
Authors: []*cli.Author{
{
Name: "Srishan Bhattarai",
Email: "srishanbhattarai@gmail.com",
},
},
Commands: []*cli.Command{
{
Name: "cal",
Aliases: []string{"c"},
Usage: "Show calendar for the month",
Action: nc.showCalendar,
},
{
Name: "date",
Aliases: []string{"d"},
Usage: "Show today's date",
Action: nc.showDate(writer, time.Now()),
},
{
Name: "conv",
Usage: "Convert AD dates to BS and vice-versa",
Subcommands: []*cli.Command{
{
Name: "tobs",
Usage: "Convert AD date to BS date",
Action: nc.convADToBS,
},
{
Name: "toad",
Usage: "Convert BS date to AD date",
Action: nc.convBSToAD,
},
},
},
},
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
return app
}