Remove dependencies cli and testify

This commit is contained in:
Trevor Slocum 2020-05-13 09:42:23 -07:00
parent ad7ddd5a24
commit ac396c0d13
6 changed files with 120 additions and 124 deletions

View File

@ -1,3 +1,6 @@
0.1.4:
- Remove dependencies cli and testify
0.1.3:
- Allow notebooks to be served publicly

View File

@ -17,9 +17,9 @@ Note options are specified with the **options directive** on the first line:
* [ ] Whole wheat loaf
```
**Note:** When viewing this documentation in a rendered format, the directive
will not be visible above (it is a Markdown comment). It is reproduced with an
added space between the `]` and `:` characters below:
**Note:** The directive may not be visible when viewing this documentation in a
rendered format, as it is a Markdown comment. It is reproduced with an added
space between the `]` and `:` characters below:
```
[//] : # (list,sort)

View File

@ -1,15 +1,14 @@
package main
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfig(t *testing.T) {
t.Parallel()
var configData = []byte(`
configData := []byte(`
salt: 'xXxN4CLxXx'
authors:
@ -35,15 +34,42 @@ notebooks:
t.Errorf("failed to load config data: %+v", err)
}
assert.Equal(t, false, c.Debug)
assert.Equal(t, "xXxN4CLxXx", c.Salt)
assert.ElementsMatch(t, []*AuthorConfig{
if c.Debug != false {
t.Errorf("failed to read config option Debug: expected %t, got %t", false, c.Debug)
}
if c.Salt != "xXxN4CLxXx" {
t.Errorf("failed to read config option Salt: expected %s, got %s", "xXxN4CLxXx", c.Salt)
}
expectedAuthors := []*AuthorConfig{
{Email: "read@stick.rocketnine.space", Name: "Read Access"},
{Email: "check@stick.rocketnine.space", Name: "Check Access"},
{Email: "write@stick.rocketnine.space", Name: "Write Access"}},
c.Authors)
assert.ElementsMatch(t, []*NotebookConfig{
{Email: "write@stick.rocketnine.space", Name: "Write Access"}}
for _, expectedAuthor := range expectedAuthors {
found := 0
for _, author := range c.Authors {
if author.Email == expectedAuthor.Email && author.Name == expectedAuthor.Name {
found++
}
}
if found != 1 {
t.Errorf("failed to read config option Author: expected 1 %v, got %d", expectedAuthor, found)
}
}
expectedNotebooks := []*NotebookConfig{
{Label: "Test Notebook A", Repo: "/home/stick/repo/a", Serve: map[string]int{"read@stick.rocketnine.space": AuthorAccessRead, "write@stick.rocketnine.space": AuthorAccessWrite}},
{Label: "Test Notebook B", Repo: "/home/stick/repo/b", Serve: map[string]int{"check@stick.rocketnine.space": AuthorAccessCheck, "read@stick.rocketnine.space": AuthorAccessRead}}},
c.Notebooks)
{Label: "Test Notebook B", Repo: "/home/stick/repo/b", Serve: map[string]int{"check@stick.rocketnine.space": AuthorAccessCheck, "read@stick.rocketnine.space": AuthorAccessRead}}}
for _, expectedNotebook := range expectedNotebooks {
found := 0
for _, notebook := range c.Notebooks {
if notebook.Label == expectedNotebook.Label && reflect.DeepEqual(notebook.Serve, expectedNotebook.Serve) && notebook.Repo == expectedNotebook.Repo {
found++
}
}
if found != 1 {
t.Errorf("failed to read config option Notebook: expected 1 %v, got %d", expectedNotebook, found)
}
}
}

13
go.mod
View File

@ -1,17 +1,16 @@
module gitlab.com/tslocum/stick
go 1.12
go 1.14
require (
github.com/GeertJohan/go.rice v1.0.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/go-git/go-git/v5 v5.0.0
github.com/gorilla/mux v1.7.4
github.com/gorilla/websocket v1.4.1
github.com/gorilla/websocket v1.4.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.5.1
github.com/urfave/cli v1.22.3
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 // indirect
gopkg.in/yaml.v2 v2.2.8
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f // indirect
golang.org/x/sys v0.0.0-20200513112337-417ce2331b5c // indirect
gopkg.in/yaml.v2 v2.3.0
)

30
go.sum
View File

@ -1,4 +1,3 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
@ -9,10 +8,6 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
@ -39,8 +34,8 @@ github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@ -61,19 +56,11 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
@ -82,16 +69,21 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 h1:QmwruyY+bKbDDL0BaglrbZABEali68eoMFhTZpCjYVA=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f h1:QBjCr1Fz5kw158VqdE9JfI9cJnl/ymnJWAdMuinqL7Y=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200513112337-417ce2331b5c h1:kISX68E8gSkNYAFRFiDU8rl5RIn1sJYKYb/r2vMLDrU=
golang.org/x/sys v0.0.0-20200513112337-417ce2331b5c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@ -104,5 +96,5 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

144
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"math/rand"
@ -8,111 +9,86 @@ import (
"time"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
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 *Stick
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
app := cli.NewApp()
app.Name = "stick"
app.Usage = "Shareable Git-backed Markdown-formatted notes"
app.Version = ""
app.HideVersion = true
configPath := ""
debug := false
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: "configuration file",
EnvVar: "STICK_CONFIG",
Value: "~/.config/stick/stick.yml",
Destination: &configPath,
},
cli.BoolFlag{
Name: "debug",
Usage: "run in debug mode",
EnvVar: "STICK_DEBUG",
Destination: &debug,
},
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()
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i"},
Usage: "create a notebook",
Action: func(c *cli.Context) error {
Initialize(configPath, debug)
rand.Seed(time.Now().UTC().UnixNano())
path := c.Args().First()
if path == "" {
fmt.Println("USAGE: stick init <path> [cloneurl]")
return nil
}
command := flag.Arg(0)
switch command {
case "init":
Initialize(configPath, debug)
cloneURL := c.Args().Get(1)
path := flag.Arg(1)
if path == "" {
fmt.Println("USAGE: stick init <path> [cloneurl]")
return
}
_, err := InitializeRepository(path, cloneURL)
if err != nil {
panic(errors.Wrap(err, "failed to initialize notebook"))
}
cloneURL := flag.Arg(2)
fmt.Println("notebook initialized")
return nil
},
},
{
Name: "resolve",
Aliases: []string{"r"},
Usage: "resolve a merge conflict",
Action: func(c *cli.Context) error {
Initialize(configPath, debug)
_, err := InitializeRepository(path, cloneURL)
if err != nil {
panic(errors.Wrap(err, "failed to initialize notebook"))
}
path := c.Args().First()
if path == "" {
fmt.Println("USAGE: stick resolve <path>")
return nil
}
fmt.Println("notebook initialized")
case "resolve":
Initialize(configPath, debug)
// TODO: initialize editor to resolve conflict
path := flag.Arg(1)
if path == "" {
fmt.Println("USAGE: stick resolve <path>")
return
}
return nil
},
},
{
Name: "serve",
Aliases: []string{"s"},
Usage: "serve shared notebooks",
Action: func(c *cli.Context) error {
Initialize(configPath, debug)
// TODO: initialize editor to resolve conflict
case "serve":
Initialize(configPath, debug)
address := c.Args().First()
if stick.Config.Serve == "" && address == "" {
fmt.Println("USAGE: stick serve <[address]:[port]>")
return nil
} else if address != "" {
stick.Config.Serve = address
}
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()
registerSignalHandlers()
log.Printf("serving shared notebooks on %s", stick.Config.Serve)
serveWeb()
return nil
},
},
log.Printf("serving shared notebooks on %s", stick.Config.Serve)
serveWeb()
default:
flag.Usage()
}
err := app.Run(os.Args)
CheckError(err)
}