-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
90 lines (78 loc) · 1.63 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
package main
import (
"log"
"os"
"time"
"github.com/urfave/cli/v2"
)
const (
paramIn = "in"
paramOut = "out"
paramBackup = "backup"
paramQuiet = "quiet"
)
type mode struct {
MarkdownMode bool // 兼容 Markdown 格式
QuietMode bool // 不输出具体文件日志
}
var globalConfig = &mode{
QuietMode: false,
}
func main() {
app := &cli.App{
Name: "HeySpace",
Usage: "在中英文之间添加空格",
Version: "v0.0.2",
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "Renzo",
Email: "[email protected]",
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: paramIn,
Aliases: []string{"i"},
Usage: "输入文件路径",
DefaultText: "默认剪贴板输入",
},
&cli.StringFlag{
Name: paramOut,
Aliases: []string{"o"},
Usage: "输出文件路径",
DefaultText: "默认剪贴板输出",
},
&cli.StringFlag{
Name: paramBackup,
Aliases: []string{"b"},
Usage: "备份目录路径",
},
&cli.BoolFlag{
Name: paramQuiet,
Aliases: []string{"q"},
Usage: "不输出具体文件日志",
Value: false,
DefaultText: "关闭",
},
},
Action: runApp,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func runApp(c *cli.Context) error {
globalConfig.QuietMode = c.Bool(paramQuiet)
if len(c.String("in")) == 0 {
if err := handleClipboard(); err != nil {
log.Fatal(err)
}
return nil
}
if err := handlePathInput(c.String(paramIn), c.String(paramOut), c.String(paramBackup)); err != nil {
log.Fatal(err)
}
return nil
}