Separating server and client for reasons ...
This commit is contained in:
85
isolated/simplecli/main.go
Normal file
85
isolated/simplecli/main.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.hrafn.xyz/aether/notes/client"
|
||||
)
|
||||
|
||||
func main() {
|
||||
list := flag.Bool("list", false, "List all notes in the database")
|
||||
create := flag.Bool("create", false, "Create a new note")
|
||||
update := flag.Bool("update", false, "Update an existing note")
|
||||
delete := flag.Bool("delete", false, "Delete a note from the database")
|
||||
get := flag.Bool("get", false, "Get a note by ID")
|
||||
|
||||
id := flag.Int("id", 0, "ID of the note to get, update, or delete (only used with -get, -update, or -delete)")
|
||||
content := flag.String("content", "", "Content of the note to create or update (only used with -create or -update)")
|
||||
|
||||
flag.Parse()
|
||||
modes := map[string]bool{
|
||||
"list": *list,
|
||||
"create": *create,
|
||||
"update": *update,
|
||||
"delete": *delete,
|
||||
"get": *get,
|
||||
}
|
||||
|
||||
enabledCount := 0
|
||||
for _, enabled := range modes {
|
||||
if enabled {
|
||||
enabledCount++
|
||||
}
|
||||
}
|
||||
if enabledCount == 0 {
|
||||
log.Fatal("No mode specified. Use -list, -create, -update, -delete, or -get.")
|
||||
os.Exit(1)
|
||||
}
|
||||
if enabledCount > 1 {
|
||||
log.Fatal("Multiple modes specified. Please specify only one mode at a time.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *list {
|
||||
client.ListNotes()
|
||||
}
|
||||
|
||||
if *create {
|
||||
if *content == "" {
|
||||
log.Fatal("Content must be provided with -create")
|
||||
os.Exit(1)
|
||||
}
|
||||
client.CreateNote(*content)
|
||||
}
|
||||
|
||||
if *get {
|
||||
if *id == 0 {
|
||||
log.Fatal("ID must be provided with -get")
|
||||
os.Exit(1)
|
||||
}
|
||||
client.GetNoteByID(*id)
|
||||
}
|
||||
|
||||
if *update {
|
||||
if *id == 0 {
|
||||
log.Fatal("ID must be provided with -update")
|
||||
os.Exit(1)
|
||||
}
|
||||
if *content == "" {
|
||||
log.Fatal("Content must be provided with -update")
|
||||
os.Exit(1)
|
||||
}
|
||||
client.UpdateNoteByID(*id, *content)
|
||||
}
|
||||
|
||||
if *delete {
|
||||
if *id == 0 {
|
||||
log.Fatal("ID must be provided with -delete")
|
||||
os.Exit(1)
|
||||
}
|
||||
client.DeleteNoteByID(*id)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user