Add examples and CLI readme
continuous-integration/woodpecker the build was successful Details

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main v0.1.1
jolheiser 2021-11-10 16:15:57 -06:00
parent 36c87f69dc
commit 153a69a95e
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
4 changed files with 62 additions and 12 deletions

View File

@ -17,9 +17,6 @@ pipeline:
commands:
- GOOS="windows" go build ./cmd/spectre
- GOOS="linux" go build ./cmd/spectre
when:
event: [ push, tag ]
branch: main
release-main:
image: jolheiser/drone-gitea-main:latest

View File

@ -0,0 +1,33 @@
# Spectre CLI
All flags can be supplied as environment variables starting with `SPECTRE_*`
e.g. `--username` -> `SPECTRE_USERNAME`
### Usage
```text
spectre [FLAGS] [site]
-counter int
counter (default 1)
-scope value
scope
-scoper string
scoper base (default "com.lyndir.masterpassword")
-secret string
secret
-template value
template
-username string
username
```
### Example
```shell
export SPECTRE_USERNAME="Robert Lee Mitchell"
export SPECTRE_SECRET="banana colored duckling"
spectre masterpasswordapp.com
# Jejr5[RepuSosp
```

View File

@ -11,9 +11,12 @@ import (
func main() {
fs := flag.NewFlagSet("spectre", flag.ExitOnError)
fs.Usage = func() {
fmt.Fprintln(fs.Output(), "spectre [FLAGS] [site]")
fs.PrintDefaults()
}
usernameFlag := fs.String("username", "", "username")
secretFlag := fs.String("secret", "", "secret")
siteFlag := fs.String("site", "", "site")
counterFlag := fs.Int("counter", 1, "counter")
scoperFlag := fs.String("scoper", "com.lyndir.masterpassword", "scoper base")
scopeFlag := spectre.Authentication
@ -38,7 +41,7 @@ func main() {
templateFlag = scopeFlag.DefaultTemplate()
}
if *usernameFlag == "" || *secretFlag == "" || *siteFlag == "" {
if *usernameFlag == "" || *secretFlag == "" || len(os.Args) < 2 {
panic("username, secret, and site are required")
}
@ -49,7 +52,7 @@ func main() {
panic(err)
}
pw := s.Site(*siteFlag,
pw := s.Site(os.Args[1],
spectre.WithScope(scopeFlag),
spectre.WithTemplate(templateFlag),
spectre.WithCounter(*counterFlag),

View File

@ -3,6 +3,7 @@ package spectre_test
import (
_ "embed"
"encoding/xml"
"fmt"
"strconv"
"testing"
@ -53,18 +54,34 @@ func TestSpectre(t *testing.T) {
}
// From the website sanity check
func TestSanity(t *testing.T) {
func Example() {
s, err := spectre.New("Robert Lee Mitchell", "banana colored duckling")
if err != nil {
t.Logf("failed sanity check: %v", err)
t.FailNow()
panic(err)
}
pw := s.Site("masterpasswordapp.com")
if pw != "Jejr5[RepuSosp" {
t.Log("failed sanity check")
t.FailNow()
fmt.Println(pw)
// Output: Jejr5[RepuSosp
}
// Example with options
func Example_second() {
scoper := spectre.SimpleScoper{
Key: "com.jojodev.jolheiser",
}
s, err := spectre.New("Robert Lee Mitchell", "banana colored duckling", spectre.WithScoper(scoper))
if err != nil {
panic(err)
}
pw := s.Site("jojodev.com",
spectre.WithScope(spectre.Identification),
spectre.WithTemplate(spectre.Maximum),
spectre.WithCounter(2), // Password was leaked, so increment counter (example)
)
fmt.Println(pw)
// Output: Ig^JIcxD!*)TbefJBi6-
}
//go:embed spectre_tests.xml