forked from Francesco149/sharenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
118 lines (95 loc) · 3.09 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
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
/*
Copyright 2014 Franc[e]sco ([email protected])
This file is part of sharenix.
sharenix is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sharenix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with sharenix. If not, see <http://www.gnu.org/licenses/>.
*/
package main
// NOTE: to compile this, you need gtk 2.0 and >=go-1.3.1
import (
"errors"
"flag"
"fmt"
"github.com/Francesco149/sharenix/sharenixlib"
)
func handleCLI() (err error) {
cfg, err := sharenixlib.LoadConfig()
if err != nil {
return
}
// command line flags
pmode := flag.String("m", "f",
"Upload mode - f/file: upload file, fs/fullscreen: screenshot entire "+
"screen and upload, s/section: select screen region and upload, "+
"c/clipboard: upload clipboard contents, r/record: record screen "+
"region and upload, u/url: shorten url")
psite := flag.String("s", "default",
"Target site name (default = default site for the selected mode)")
psilent := flag.Bool("q", false,
"Quiet mode - disables all terminal output except errors")
pnotification := flag.Bool("n", false,
"Notification - displays a GTK notification for the upload")
popen := flag.Bool("o", false, "Open url - automatically opens the "+
"uploaded file's url in the default browser")
pclip := flag.Bool("c", true, "Copy url to clipboard - copies the "+
"uploaded file's url to the clipboard (not guaranteed to work properly"+
"on all window managers, tested on Unity + X11)")
phistory := flag.Bool("history", false, "Show upload history (grep-able)")
pversion := flag.Bool("v", false, "Shows the program version")
pdebug := flag.Bool("g", false, "Show verbose debug information "+
"(output can include sensitive info such as API keys)")
pupload := flag.Bool("upload", true, "If false, the file will be "+
"archived but not uploaded")
flag.Parse()
if !flag.Parsed() {
panic(errors.New("Unexpected flag error"))
}
if *pversion {
fmt.Println(sharenixlib.ShareNixVersion)
return
}
if *phistory {
var csv [][]string
csv, err = sharenixlib.GetUploadHistory()
if err != nil {
return
}
if len(csv) == 0 {
fmt.Println("Empty!")
return
}
for _, record := range csv {
if len(record) < 4 {
err = errors.New("Invalid csv")
return
}
fmt.Println("*", record[3], "- URL:", record[0], "Thumbnail URL:",
record[1], "Deletion URL:", record[2])
fmt.Println()
}
return
}
sharenixlib.ShareNixDebug = *pdebug
// perform upload
_, _, _, err = sharenixlib.ShareNix(
cfg, *pmode, *psite, *psilent, *pnotification, *popen, *pclip,
*pupload)
if err != nil {
return
}
return
}
func main() {
err := handleCLI()
if err != nil {
fmt.Println(err)
}
}