-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.go
More file actions
194 lines (166 loc) · 6.06 KB
/
Copy pathhelp.go
File metadata and controls
194 lines (166 loc) · 6.06 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package main
import (
"fmt"
"os"
"runtime"
"strconv"
)
// validFlags lists every command-line flag the application accepts.
// Keep this in sync with ShowHelp and the Determine*/CheckFor* functions.
var validFlags = map[string]bool{
"--help": true,
"-h": true,
"--init": true,
"--go-sqlite": true,
"--cgo-sqlite": true,
"--editor": true,
"--open": true, // takes a value: --open <id>; requires --editor
"--render-html": true, // takes a value: --render-html <id>; headless, prints HTML and exits
"--gdrive-auth": true, // sign in to Google Drive (create/refresh token.json) and exit
}
// ValidateArgs checks that every argument in args[1:] is a recognized flag.
// On the first unknown argument it prints an error and the help text to
// stderr, then exits with status 2.
func ValidateArgs(args []string) {
rest := args[1:]
skipNext := false
for i, arg := range rest {
if skipNext {
skipNext = false
continue
}
if arg == "--open" || arg == "--render-html" {
if i+1 >= len(rest) {
fmt.Fprintf(os.Stderr, "Error: %s requires a note id\n\n", arg)
ShowHelp()
os.Exit(2)
}
if _, err := strconv.Atoi(rest[i+1]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s requires a numeric note id, got %q\n\n", arg, rest[i+1])
ShowHelp()
os.Exit(2)
}
skipNext = true
continue
}
if !validFlags[arg] {
fmt.Fprintf(os.Stderr, "Error: unrecognized command-line argument %q\n\n", arg)
ShowHelp()
os.Exit(2)
}
}
if editorOnly, openId := DetermineEditorBoot(args); openId != -1 && !editorOnly {
fmt.Fprintf(os.Stderr, "Error: --open requires --editor\n\n")
ShowHelp()
os.Exit(2)
}
}
// DetermineEditorBoot reports whether --editor was given and the note id
// passed to --open (-1 if absent). ValidateArgs has already guaranteed the
// --open value is present and numeric.
func DetermineEditorBoot(args []string) (editorOnly bool, openId int) {
openId = -1
for i, arg := range args {
switch arg {
case "--editor":
editorOnly = true
case "--open":
if i+1 < len(args) {
if id, err := strconv.Atoi(args[i+1]); err == nil {
openId = id
}
}
}
}
return editorOnly, openId
}
const version = "0.1.0"
// ShowHelp displays the help message for vimango
func ShowHelp() {
helpText := `vimango - A vim-based note-taking application with SQLite storage
USAGE:
vimango [OPTIONS]
DESCRIPTION:
vimango is a terminal-based note-taking application that combines vim editing
capabilities with SQLite database storage. It supports full-text search, markdown
formatting, and an organizer interface for managing notes, contexts, folders, and
keywords.
OPTIONS:
--help, -h
Display this help message and exit
--init
Run first-time setup. Creates config.json with default settings and
initializes the SQLite databases (vimango.db and fts5_vimango.db).
Use this when running vimango for the first time after cloning.
--go-sqlite
Use the pure Go SQLite driver (modernc.org/sqlite).
Default: This is already the default driver.
Note: Works on all platforms including Windows.
--cgo-sqlite
Use the CGO-based SQLite driver (github.com/mattn/go-sqlite3).
Requirements: Only available on Linux/Unix with CGO-enabled builds.
Note: Silently ignored on Windows or in pure Go builds.
--editor
Boot directly into the editor, full-width; the organizer is never
rendered. Intended for host applications embedding vimango as an
editor pane, but works in any terminal. Use :open <id> to switch
notes; :q quits the application.
--open <id>
With --editor, load the note with the given database id into the
boot editor window. Without --open, the most recently modified
note in the configured startup view is opened. Requires --editor.
--render-html <id>
Render the note with the given database id as a standalone HTML
document on stdout and exit. Headless (no terminal UI); intended
for host applications embedding a preview pane. Google Drive
images are inlined as data URIs when Drive is configured.
--gdrive-auth
Sign in to Google Drive and exit: runs the OAuth flow (prints a
URL to open in a browser, accepts the code) and saves token.json
next to the binary. Verifies an existing token with a live API
call and re-runs the flow if it no longer works. Google Drive
images (gdrive:) need this; requires go_credentials.json (see
README.md, Google Drive Setup).
EXAMPLES:
# First-time setup (creates config.json and databases)
./vimango --init
# Run with default settings (pure Go SQLite, libvim)
./vimango
# Run with CGO SQLite driver
./vimango --cgo-sqlite
# Editor-only mode (e.g. embedded in a host app), opening note 5
./vimango --editor --open 5
# Print note 5 as HTML (e.g. for a host app's preview pane)
./vimango --render-html 5
# Sign in to Google Drive (creates/refreshes token.json)
./vimango --gdrive-auth
BUILD INFORMATION:
Platform: %s
Architecture: %s
Go Version: %s
Build (CGO is required — vim editing is libvim; Windows is unsupported):
CGO_ENABLED=1 go build --tags="fts5,cgo"
FEATURES:
- Vim-based text editing with normal and insert modes
- SQLite database for note storage with FTS5 full-text search
- Organizer mode for browsing and managing notes
- Markdown support with preview and PDF export
- Context, folder, and keyword organization
- AI-powered deep research with web search and fetch
- WebView integration for in-app web browsing
- Spell checking (CGO builds only)
For more information, see the readme file in the project directory.
`
fmt.Printf(helpText, runtime.GOOS, runtime.GOARCH, runtime.Version())
}
// CheckForHelp checks if --help or -h flag is present in arguments
// Returns true if help was requested
func CheckForHelp(args []string) bool {
for _, arg := range args {
if arg == "--help" || arg == "-h" {
ShowHelp()
return true
}
}
return false
}