@@ -11,8 +11,7 @@ import (
11
11
)
12
12
13
13
const (
14
- VERSION = "0.1"
15
- DefaultGistName = "a"
14
+ VERSION = "0.1"
16
15
)
17
16
18
17
var config = NewConfig ()
@@ -34,32 +33,37 @@ func main() {
34
33
// -t EXT --type=EXT Sets the file extension and syntax type.
35
34
// -p --private Indicates whether the gist is private.
36
35
// -d DESC --description=DESC Adds a description to your gist.
37
- // -s --shorten * Shorten the gist URL using git.io.
36
+ // -s --shorten Shorten the gist URL using git.io.
38
37
// -u URL --update=URL Update an existing gist.
39
38
// -a --anonymous Create an anonymous gist.
40
39
// -c --copy Copy the resulting URL to the clipboard.
41
- // -e --embed * Copy the embed code for the gist to the clipboard.
42
- // -o --open * Open the resulting URL in a browser.
40
+ // -e --embed Copy the embed code for the gist to the clipboard.
41
+ // -o --open Open the resulting URL in a browser.
43
42
// -P --paste Paste from the clipboard to gist.
44
- // -R --raw * Display raw URL of the new gist.
43
+ // -R --raw Display raw URL of the new gist.
45
44
// -l USER --list=USER Lists all gists for a user.
46
45
// -h --help Show this help message and exit.
47
46
// --version Show version and exit.`
48
47
//
49
48
// arguments, err := docopt.Parse(usage, nil, true, "go-gist "+VERSION, false)
50
49
// fmt.Println(arguments)
51
50
52
- anonymousFlag := flag .Bool ("a" , false , "Create an anonymous gist." )
53
- copyFlag := flag .Bool ("c" , false , "Copy the resulting URL to the clipboard." )
54
- listFlag := flag .Bool ("l" , false , "List gists." )
55
51
loginFlag := flag .Bool ("login" , false , "Authenticate gist on this computer." )
56
- pasteFlag := flag .Bool ("P" , false , "Paste from the clipboard to gist." )
57
- privateFlag := flag .Bool ("p" , false , "Indicates whether the gist is private." )
58
-
59
- desc := flag .String ("d" , "" , "A description of the gist." )
60
52
filename := flag .String ("f" , "" , "Sets the filename and syntax type." )
61
53
filetype := flag .String ("t" , "" , "Sets the file extension and syntax type." )
54
+ privateFlag := flag .Bool ("p" , false , "Indicates whether the gist is private." )
55
+ desc := flag .String ("d" , "" , "A description of the gist." )
56
+ shortenFlag := flag .Bool ("-s" , false , "Shorten the gist URL using git.io." )
62
57
uid := flag .String ("u" , "" , "Update an existing gist. Takes ID as an argument." )
58
+ anonymousFlag := flag .Bool ("a" , false , "Create an anonymous gist." )
59
+ copyFlag := flag .Bool ("c" , false , "Copy the resulting URL to the clipboard." )
60
+ // -e --embed Copy the embed code for the gist to the clipboard.
61
+ // -o --open Open the resulting URL in a browser.
62
+ pasteFlag := flag .Bool ("P" , false , "Paste from the clipboard to gist." )
63
+ rawFlag := flag .Bool ("R" , false , "Display a raw URL of the new gist." )
64
+ listFlag := flag .Bool ("l" , false , "List gists." )
65
+
66
+ versionFlag := flag .Bool ("version" , false , "Show version and exit." )
63
67
64
68
flag .Parse ()
65
69
@@ -69,8 +73,10 @@ func main() {
69
73
err = login ()
70
74
} else if * listFlag {
71
75
err = list ()
76
+ } else if * versionFlag {
77
+ fmt .Println ("go-gist " + VERSION )
72
78
} else {
73
- err = gist (* uid , * desc , * filetype , * filename , ! * privateFlag , * anonymousFlag , * copyFlag , * pasteFlag )
79
+ err = gist (* uid , * desc , * filetype , * filename , ! * privateFlag , * anonymousFlag , * copyFlag , * pasteFlag , * rawFlag , * shortenFlag )
74
80
}
75
81
76
82
if err != nil {
@@ -106,7 +112,7 @@ func list() error {
106
112
return nil
107
113
}
108
114
109
- func gist (uid , desc , filetype , filename string , public , anonymous , copyFlag , pasteFlag bool ) error {
115
+ func gist (uid , desc , filetype , filename string , public , anonymous , copyFlag , pasteFlag , rawFlag , shortenFlag bool ) error {
110
116
var err error
111
117
var clipboard * Clipboard
112
118
@@ -125,7 +131,9 @@ func gist(uid, desc, filetype, filename string, public, anonymous, copyFlag, pas
125
131
return err
126
132
}
127
133
128
- if filetype != "" {
134
+ if filename != "" {
135
+ name = filename
136
+ } else if filetype != "" {
129
137
name += "." + filetype
130
138
}
131
139
@@ -137,7 +145,7 @@ func gist(uid, desc, filetype, filename string, public, anonymous, copyFlag, pas
137
145
138
146
if filename != "" {
139
147
name = filename
140
- } else if filename == "" && filetype != "" {
148
+ } else if filetype != "" {
141
149
name = DefaultGistName + "." + filetype
142
150
} else {
143
151
name = DefaultGistName
@@ -148,6 +156,7 @@ func gist(uid, desc, filetype, filename string, public, anonymous, copyFlag, pas
148
156
return err
149
157
}
150
158
} else {
159
+ fmt .Println ("(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" )
151
160
if content , err = ioutil .ReadAll (os .Stdin ); err != nil {
152
161
return err
153
162
}
@@ -168,6 +177,18 @@ func gist(uid, desc, filetype, filename string, public, anonymous, copyFlag, pas
168
177
return err
169
178
}
170
179
180
+ if rawFlag {
181
+ if url , err = gist .Rawify (); err != nil {
182
+ return err
183
+ }
184
+ }
185
+
186
+ if shortenFlag {
187
+ if url , err = Shorten (url ); err != nil {
188
+ return err
189
+ }
190
+ }
191
+
171
192
if copyFlag {
172
193
if err := clipboard .Copy (url ); err != nil {
173
194
return err
0 commit comments