diff --git a/README.md b/README.md index 583f1f1..886f120 100644 --- a/README.md +++ b/README.md @@ -6,34 +6,38 @@ A single executable to manage a Pigeon node. Don't use the Go version yet. If you want something stable, there is a [Ruby version that is feature complete](https://tildegit.org/PigeonProtocolConsortium/Pigeon-Ruby). +# Setup + +By default, data is stored in `~/.pigeon`. +You can override this value by specifying a `PIGEON_PATH` ENV var. + # TODO - - [ ] Finish http://go-database-sql.org/nulls.html - - [ ] Fix go module nonsense. Read a tut or sth https://thenewstack.io/understanding-golang-packages/ - [ ] Add a real testing lib to DRY things up. + - [ ] Figure out a system for where to place the default data storage directory - [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc.. - [ ] Finish all the things below: |Done?|Verb |Noun | Flag / arg 1 | Flag 2 | |-----|------------|--------|---------------|-----------| - | |show |peers | | | - | |show |peers | --blocked | | - | |unfollow |peer | | | - | |follow |peer | user mhash | | - | |unblock |peer | user mhash | | | |block |peer | user mhash | | - | |show |blob | | | | |create |blob | file path | | | |create |blob | pipe | | - | |create |draft | | | - | |update |draft | --key=? | --value=? | - | |show |draft | | | - | |publish |draft | | | | |create |bundle | | | + | |create |draft | | | + | |find |blob | | | | |find |message | --all | | | |find |message | --last | | + | |follow |peer | user mhash | | | |ingest |bundle | | | + | |publish |draft | | | + | |show |draft | | | | |show |message | message mhash | | + | |show |peers | | | + | |show |peers | --blocked | | + | |unblock |peer | user mhash | | + | |unfollow |peer | | | + | |update |draft | --key=? | --value=? | | X |show |identity| | | | X |create |identity| | | | X |help | | | | diff --git a/build.sh b/build.sh index 7a6f02d..1100aaf 100755 --- a/build.sh +++ b/build.sh @@ -3,3 +3,6 @@ cd project go build --o=../pigeon-cli cd - +PIGEON_PATH="." +./pigeon-cli version +./pigeon-cli show identity diff --git a/project/cli.go b/project/cli.go index 071109b..0a5b8f2 100644 --- a/project/cli.go +++ b/project/cli.go @@ -7,15 +7,18 @@ import ( "github.com/spf13/cobra" ) -// ======== LEVEL ZERO ===================================== +// CLI: `pigeon` var rootCmd = &cobra.Command{ Use: "pigeon", Short: "Pigeon is a peer-to-peer database for offline systems.", Long: `Pigeon is an off-grid, serverless, peer-to-peer database for building software that works on poor internet connections, or entirely offline.`, + Run: func(cmd *cobra.Command, args []string) { + }, } +// CLI: `pigeon version` var versionCmd = &cobra.Command{ Use: "version", Short: "Print the software version.", @@ -24,20 +27,21 @@ var versionCmd = &cobra.Command{ }, } -// ======== LEVEL ONE ====================================== +// CLI: `pigeon show [resource]` var showCmd = &cobra.Command{ Use: "show [resource]", Short: "Show various resources", Long: `Shows resources such as blobs, drafts, identities, messages, peers, etc..`, } +// CLI: `pigeon create [resource]` var createCmd = &cobra.Command{ Use: "create [resource]", Short: "Create various resources", Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`, } -// ======== LEVEL TWO ====================================== +// CLI: `pigeon create identity` var createIdentityCmd = &cobra.Command{ Use: "identity", Short: "Create a new identity.", @@ -47,6 +51,7 @@ var createIdentityCmd = &cobra.Command{ }, } +// CLI: `pigeon show identity` var showIdentityCmd = &cobra.Command{ Use: "identity", Short: "Show current user identity.", diff --git a/project/db.go b/project/db.go index 7eb0366..c041538 100644 --- a/project/db.go +++ b/project/db.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "log" + "path" "modernc.org/ql" ) @@ -26,8 +27,9 @@ var migrations = []migration{ func openDB() *sql.DB { ql.RegisterDriver() - - db, err0 := sql.Open("ql", "file://testdata/secret.db") + pigeonPath := maybeSetupPigeonDir() + dbPath := path.Join(pigeonPath, "db") + db, err0 := sql.Open("ql", dbPath) if err0 != nil { log.Fatalf("failed to open db: %s", err0) diff --git a/project/encoders.go b/project/encoders.go index a29e06b..8bc20a7 100644 --- a/project/encoders.go +++ b/project/encoders.go @@ -11,3 +11,7 @@ var encoder = base32.NewEncoding(alphabet).WithPadding(base32.NoPadding) func B32Encode(data []byte) string { return encoder.EncodeToString(data) } + +func encodeUserMhash(pubKey []byte) string { + return UserSigil + B32Encode(pubKey) +} diff --git a/project/filesystem.go b/project/filesystem.go new file mode 100644 index 0000000..a8f3afc --- /dev/null +++ b/project/filesystem.go @@ -0,0 +1,25 @@ +package main + +import ( + "log" + "os" + "path" + + "github.com/mitchellh/go-homedir" +) + +func maybeSetupPigeonDir() string { + var pigeonDataDir string + customPath, hasCustomPath := os.LookupEnv("PIGEON_PATH") + if hasCustomPath { + pigeonDataDir = customPath + } else { + home, err := homedir.Dir() + if err != nil { + log.Fatalf("Home directory resolution error %s", err) + } + pigeonDataDir = path.Join(home, ".pigeon") + } + os.MkdirAll(pigeonDataDir, 0700) + return pigeonDataDir +} diff --git a/project/util.go b/project/util.go index 9f95458..b96fe13 100644 --- a/project/util.go +++ b/project/util.go @@ -37,8 +37,3 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) { SetConfig("private_key", priv) return pub, priv } - -func encodeUserMhash(pubKey []byte) string { - sigil := "USER." - return sigil + B32Encode(pubKey) -}