forked from louisun/HeySpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (101 loc) · 2.51 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
package main
import (
"log"
"os"
"time"
"github.com/louisun/heyspace/clipboard"
"github.com/louisun/heyspace/config"
"github.com/louisun/heyspace/file"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "HeySpace",
Usage: "在中英文之间添加空格",
Version: "v0.0.1",
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "Renzo",
Email: "[email protected]",
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "in",
Aliases: []string{"i"},
Usage: "输入文件路径",
DefaultText: "默认剪贴板输入",
},
&cli.StringFlag{
Name: "out",
Aliases: []string{"o"},
Usage: "输出文件路径",
DefaultText: "默认剪贴板输出",
},
&cli.StringFlag{
Name: "backup",
Aliases: []string{"b"},
Usage: "备份目录路径",
},
&cli.BoolFlag{
Name: "server",
Aliases: []string{"s"},
Usage: "服务器监听模式",
Value: false,
DefaultText: "关闭",
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "不输出具体文件日志",
Value: false,
DefaultText: "关闭",
},
&cli.BoolFlag{
Name: "markdown",
Aliases: []string{"m"},
Usage: "Markdown 模式",
Value: true,
DefaultText: "开启",
},
&cli.BoolFlag{
Name: "pdf",
Aliases: []string{"p"},
Usage: "PDF 模式",
Value: true,
DefaultText: "开启",
},
},
Action: func(c *cli.Context) error {
config.GlobalConfig.MarkdownMode = c.Bool("markdown")
config.GlobalConfig.ServerMode = c.Bool("server")
config.GlobalConfig.PDFMode = c.Bool("pdf") // TODO
config.GlobalConfig.QuietMode = c.Bool("quiet")
if c.String("in") == "" {
if !config.GlobalConfig.ServerMode {
if err := clipboard.HandleClipboardInput(); err != nil {
log.Fatal(err)
}
log.Println("已成功处理并发送至剪贴板,请复制查看")
} else {
startServe()
}
} else {
// 若从文件输入,输出也会被设定为文件输出
if err := file.HandlePathInput(c.String("in"), c.String("out"), c.String("backup")); err != nil {
log.Fatal(err)
}
log.Println("已成功处理所有文件,请查看")
}
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
// 服务模式:定时监听剪贴板,实时输出到剪贴板 TODO
func startServe() {
}