apps/jotts/main.go 955 B raw
1
package main
2
3
import (
4
	"fmt"
5
	"os"
6
7
	"github.com/stevedylandev/andromeda/apps/jotts/tui"
8
)
9
10
func main() {
11
	args := os.Args[1:]
12
	if len(args) == 0 {
13
		runTUI(nil)
14
		return
15
	}
16
17
	switch args[0] {
18
	case "server":
19
		runServer(args[1:])
20
	case "tui":
21
		runTUI(args[1:])
22
	case "auth":
23
		runAuth(args[1:])
24
	case "-h", "--help", "help":
25
		printUsage()
26
	default:
27
		if _, err := os.Stat(args[0]); err == nil {
28
			runUpload(args)
29
			return
30
		}
31
		runTUI(args)
32
	}
33
}
34
35
func runTUI(args []string) {
36
	if err := tui.Run(tui.ParseArgs(args)); err != nil {
37
		fmt.Fprintln(os.Stderr, "tui error:", err)
38
		os.Exit(1)
39
	}
40
}
41
42
func printUsage() {
43
	fmt.Println(`jotts — minimal markdown notes
44
45
usage:
46
  jotts                            launch TUI (default)
47
  jotts tui  [--remote URL --api-key KEY]
48
  jotts server                     run HTTP server
49
  jotts auth                       configure remote URL + API key
50
  jotts <file.md>                  upload file as a new note`)
51
}