Initialize repository

This commit is contained in:
eikendev
2021-01-14 17:42:30 +01:00
commit 6cd1769c9d
21 changed files with 420 additions and 0 deletions

18
.editorconfig Normal file
View File

@@ -0,0 +1,18 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_style = space
[Makefile]
indent_style = tab

19
.gitignore vendored Normal file
View File

@@ -0,0 +1,19 @@
pbcli
### Go
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

35
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make build",
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"type": "shell",
"command": "make test",
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
ISC License (ISC)
Copyright 2021 eikendev
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

21
Makefile Normal file
View File

@@ -0,0 +1,21 @@
.PHONY: build
build:
go build -ldflags="-w -s" -o pbcli ./cmd
.PHONY: test
test:
stdout=$$(gofmt -l . 2>&1); \
if [ "$$stdout" ]; then \
exit 1; \
fi
gocyclo -over 10 $(shell find . -iname '*.go' -type f)
go test -v -cover ./...
stdout=$$(golint ./... 2>&1); \
if [ "$$stdout" ]; then \
exit 1; \
fi
.PHONY: setup
setup:
go get -u github.com/fzipp/gocyclo/cmd/gocyclo
go get -u golang.org/x/lint/golint

21
README.md Normal file
View File

@@ -0,0 +1,21 @@
![License](https://img.shields.io/github/license/pushbits/cli)
# PushBits CLI
## About
PushBits is a relay server for push notifications.
It enables your services to send notifications via a simple web API, and delivers them to you through [Matrix](https://matrix.org/).
This is similar to what [PushBullet](https://www.pushbullet.com/), [Pushover](https://pushover.net/), and [Gotify](https://gotify.net/) offer, but a lot less complex.
This command line tool enables users to create and modify applications.
Further, it can be used by administrators to administrate to add and remove users.
## Development
The source code is located on [GitHub](https://github.com/pushbits/cli).
You can retrieve it by checking out the repository as follows.
```bash
git clone https://github.com/pushbits/cli.git
```

22
cmd/application/create.go Normal file
View File

@@ -0,0 +1,22 @@
package application
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type createCommand struct {
Arguments struct {
Name string `positional-arg-name:"name" description:"The name of the application"`
} `required:"true" positional-args:"true"`
}
func (c *createCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *createCommand) Run(s settings.Settings) {
log.Printf("createCommand")
}

22
cmd/application/delete.go Normal file
View File

@@ -0,0 +1,22 @@
package application
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type deleteCommand struct {
Arguments struct {
ID uint `positional-arg-name:"id" description:"The ID of the application"`
} `required:"true" positional-args:"true"`
}
func (c *deleteCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *deleteCommand) Run(s settings.Settings) {
log.Printf("deleteCommand")
}

19
cmd/application/list.go Normal file
View File

@@ -0,0 +1,19 @@
package application
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type listCommand struct {
}
func (c *listCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *listCommand) Run(s settings.Settings) {
log.Printf("listCommand")
}

8
cmd/application/mod.go Normal file
View File

@@ -0,0 +1,8 @@
package application
type Command struct {
Create createCommand `command:"create" alias:"c" description:"Create a new application for a user"`
Delete deleteCommand `command:"delete" alias:"d" description:"Delete an existing application for a user"`
List listCommand `command:"list" alias:"l" description:"List all existing applications of the user"`
Show showCommand `command:"show" alias:"s" description:"Show details of an existing application of a user"`
}

22
cmd/application/show.go Normal file
View File

@@ -0,0 +1,22 @@
package application
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type showCommand struct {
Arguments struct {
ID uint `positional-arg-name:"id" description:"The ID of the application"`
} `required:"true" positional-args:"true"`
}
func (c *showCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *showCommand) Run(s settings.Settings) {
log.Printf("showCommand")
}

44
cmd/credentials.go Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
"flag"
"fmt"
"log"
"syscall"
"golang.org/x/crypto/ssh/terminal"
)
type Credentials struct {
Url string
Username string
Password string
}
func getCredentials(args []string) *Credentials {
credFlags := flag.NewFlagSet("cred", flag.ExitOnError)
url := credFlags.String("url", "", "The URL on which the server is listening")
username := credFlags.String("username", "", "The username to authenticate on the server")
credFlags.Parse(args)
if *url == "" {
log.Fatal("No URL was supplied.")
}
if *username == "" {
log.Fatal("No username was supplied.")
}
fmt.Print("Password: ")
password, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal("No password was supplied.")
}
return &Credentials{
Url: *url,
Username: *username,
Password: string(password),
}
}

36
cmd/pbcli.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"os"
"github.com/jessevdk/go-flags"
"github.com/pushbits/cli/cmd/application"
"github.com/pushbits/cli/cmd/settings"
"github.com/pushbits/cli/cmd/user"
)
type Commands struct {
settings.Settings
Application application.Command `command:"application" alias:"a" description:"Configure applications"`
User user.Command `command:"user" alias:"u" description:"Configure users"`
}
var (
commands Commands
parser = flags.NewParser(&commands, flags.Default)
)
func main() {
_, err := parser.Parse()
if err != nil {
os.Exit(1)
}
s := settings.Settings{
URL: commands.URL,
Username: commands.Username,
}
settings.Runner.Run(s)
}

12
cmd/settings/mod.go Normal file
View File

@@ -0,0 +1,12 @@
package settings
type Settings struct {
URL string `long:"url" description:"The URL where the server listens for requests" required:"true"`
Username string `long:"username" description:"The username for authenticating on the server" required:"true"`
}
type Runnable interface {
Run(Settings)
}
var Runner Runnable

23
cmd/user/create.go Normal file
View File

@@ -0,0 +1,23 @@
package user
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type createCommand struct {
Arguments struct {
Name string `positional-arg-name:"name" description:"The name of the user"`
MatrixID string `positional-arg-name:"matrixid" description:"The Matrix ID of the user"`
} `required:"true" positional-args:"true"`
}
func (c *createCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *createCommand) Run(s settings.Settings) {
log.Printf("createCommand")
}

22
cmd/user/delete.go Normal file
View File

@@ -0,0 +1,22 @@
package user
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type deleteCommand struct {
Arguments struct {
ID uint `positional-arg-name:"id" description:"The ID of the user"`
} `required:"true" positional-args:"true"`
}
func (c *deleteCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *deleteCommand) Run(s settings.Settings) {
log.Printf("deleteCommand")
}

19
cmd/user/list.go Normal file
View File

@@ -0,0 +1,19 @@
package user
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type listCommand struct {
}
func (c *listCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *listCommand) Run(s settings.Settings) {
log.Printf("listCommand")
}

8
cmd/user/mod.go Normal file
View File

@@ -0,0 +1,8 @@
package user
type Command struct {
Create createCommand `command:"create" alias:"c" description:"Create a new user"`
Delete deleteCommand `command:"delete" alias:"d" description:"Delete an existing user"`
List listCommand `command:"list" alias:"l" description:"List all existing users"`
Show showCommand `command:"show" alias:"s" description:"Show details of an existing user"`
}

22
cmd/user/show.go Normal file
View File

@@ -0,0 +1,22 @@
package user
import (
"log"
"github.com/pushbits/cli/cmd/settings"
)
type showCommand struct {
Arguments struct {
ID uint `positional-arg-name:"id" description:"The ID of the user"`
} `required:"true" positional-args:"true"`
}
func (c *showCommand) Execute(args []string) error {
settings.Runner = c
return nil
}
func (c *showCommand) Run(s settings.Settings) {
log.Printf("showCommand")
}

8
go.mod Normal file
View File

@@ -0,0 +1,8 @@
module github.com/pushbits/cli
go 1.14
require (
github.com/jessevdk/go-flags v1.4.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
)

12
go.sum Normal file
View File

@@ -0,0 +1,12 @@
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=