-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlegalmarkdown.go
140 lines (118 loc) · 3.42 KB
/
legalmarkdown.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// The LegalMarkdown package contains the parser functions to automate and simplify contracting.
// You can easily transform your contracting by using the functionality of how programmers work
// into your legal practice. By integrating such programming concepts as partials, templates,
// boolean triggers, and the like (which sound fancy but are very simple to explain), your
// transactional practice will be greatly simplified.
package main
import (
"github.com/codegangsta/cli"
"github.com/eris-ltd/legalmarkdown/lmd"
"log"
"os"
)
// main parses the command line inputs and routes the commands to the appropriate wrapper
// functions.
func main() {
legalmd := cli.NewApp()
legalmd.Name = "legalmarkdown"
legalmd.Usage = "Automate your contracting."
legalmd.Version = "0.9.0"
legalmd.Author = "Eris Industries, Ltd."
legalmd.Email = "[email protected]"
legalmd.Commands = []cli.Command{
{
Name: "assemble",
ShortName: "a",
Usage: "create yaml frontmatter",
Flags: []cli.Flag{
cli.StringFlag{
Name: "t, template",
Usage: "template file to be parsed",
},
cli.StringFlag{
Name: "p, parameters",
Usage: "parameters file to be parsed",
},
cli.StringFlag{
Name: "o, output",
Usage: "output file to be written",
},
},
Action: cliMakeYAMLFrontMatter,
},
{
Name: "parse",
ShortName: "p",
Usage: "parse to markdown",
Flags: []cli.Flag{
cli.StringFlag{
Name: "t, template",
Usage: "template file to be parsed",
},
cli.StringFlag{
Name: "p, parameters",
Usage: "parameters file to be parsed",
},
cli.StringFlag{
Name: "o, output",
Usage: "output file to be written",
},
},
Action: cliLegalToMarkdown,
},
{
Name: "render",
ShortName: "r",
Usage: "render from lmd to pdf or markdown to pdf",
Flags: []cli.Flag{
cli.StringFlag{
Name: "t, template",
Usage: "template file to be parsed",
},
cli.StringFlag{
Name: "p, parameters",
Usage: "parameters file to be parsed",
},
cli.StringFlag{
Name: "o, output",
Usage: "output file to be written",
},
},
Action: cliMarkdownToPDF,
},
}
legalmd.Run(os.Args)
}
func cliMakeYAMLFrontMatter(c *cli.Context) {
if c.String("template") == "" {
log.Fatal("Please specify a template file to parse with the --template or -t flag.")
}
contents := c.String("template")
parameters := c.String("parameters")
output := c.String("output")
lmd.MakeYAMLFrontMatter(contents, parameters, output)
}
func cliLegalToMarkdown(c *cli.Context) {
if c.String("template") == "" {
log.Fatal("Please specify a template file to parse with the --template or -t flag.")
}
if c.String("output") == "" {
log.Fatal("Please specify an output file to write to with the --output or -o flag.")
}
contents := c.String("template")
parameters := c.String("parameters")
output := c.String("output")
lmd.LegalToMarkdown(contents, parameters, output)
}
func cliMarkdownToPDF(c *cli.Context) {
if c.String("template") == "" {
log.Fatal("Please specify a template file to parse with the --template or -t flag.")
}
if c.String("output") == "" {
log.Fatal("Please specify an output file to write to with the --output or -o flag.")
}
contents := c.String("template")
parameters := c.String("parameters")
output := c.String("output")
lmd.MarkdownToPDF(contents, parameters, output)
}