-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
85 lines (71 loc) · 1.66 KB
/
main.go
File metadata and controls
85 lines (71 loc) · 1.66 KB
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
package main
import (
"fmt"
"log"
"os"
"slices"
"github.com/alecthomas/kong"
"github.com/gnojus/keyring"
)
const description = `
nec is a command line tool for file sharing on Nextcloud.
It parses the existing configuration of the official desktop client
and operates on the folders of local filesystem,
while actually sharing the files that are synced with the server.
`
func main() {
if len(os.Args) == 1 {
os.Args = append(os.Args, "--help")
}
err := run()
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
}
func run() error {
debug = slices.Contains(os.Args, "--debug")
keyring.Debug = debug
var cli cli
k, err := kong.New(&cli,
kong.ConfigureHelp(kong.HelpOptions{
FlagsLast: true,
Compact: true,
NoExpandSubcommands: false,
WrapUpperBound: 80,
}),
kong.Description(description),
)
if err != nil {
panic(err)
}
for _, n := range k.Model.Children {
if n.Name == "update" {
n.Hidden = version == "" || repo == ""
}
for _, f := range n.Flags {
if f.Name == "help" {
f.Hidden = true
}
}
}
k.Model.HelpFlag.Hidden = true
ctx, err := k.Parse(os.Args[1:])
if err != nil {
return err
}
return ctx.Run()
}
var debug = false
func debugf(format string, args ...any) {
if debug {
log.Printf("[nec] "+format, args...)
}
}
type cli struct {
Share share `kong:"cmd,aliases=s,help='share a local file'"`
Unshare unshare `kong:"cmd,aliases=us,help='unshare a local file'"`
List list `kong:"cmd,aliases=ls,help='list shares of local files'"`
Update update `kong:"cmd,help='update nec using github releases if new version available'"`
Debug bool `kong:"hidden"`
}