Shareable Git-powered notebooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

94 lines
1.7 KiB

package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"time"
"github.com/pkg/errors"
)
const usage = `stick - Shareable Git-powered notebooks
Usage:
%s [<options...>] <command>
Commands:
help Print help information
init Create a notebook
resolve Resolve merge conflicts
serve Serve shared notebooks
version Print version information
Global options:
`
var (
stick *server
)
func main() {
configPath := ""
debug := false
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage, os.Args[0])
flag.PrintDefaults()
}
flag.BoolVar(&debug, "debug", false, "run in debug mode")
flag.StringVar(&configPath, "config", "~/.config/stick/stick.yml", "path to configuration file")
flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
command := flag.Arg(0)
switch command {
case "init":
initialize(configPath, debug)
path := flag.Arg(1)
if path == "" {
fmt.Println("USAGE: stick init <path> [cloneurl]")
return
}
cloneURL := flag.Arg(2)
_, err := initializeRepository(path, cloneURL)
if err != nil {
panic(errors.Wrap(err, "failed to initialize notebook"))
}
fmt.Println("notebook initialized")
case "resolve":
initialize(configPath, debug)
path := flag.Arg(1)
if path == "" {
fmt.Println("USAGE: stick resolve <path>")
return
}
// TODO: initialize editor to resolve conflict
case "serve":
initialize(configPath, debug)
address := flag.Arg(1)
if stick.Config.Serve == "" && address == "" {
fmt.Println("USAGE: stick serve <[address]:[port]>")
return
} else if address != "" {
stick.Config.Serve = address
}
registerSignalHandlers()
log.Printf("serving shared notebooks on %s", stick.Config.Serve)
serveWeb()
default:
flag.Usage()
}
}