experimental-cli/project/cli.go

86 lines
2.2 KiB
Go
Raw Normal View History

2020-09-10 12:33:41 +00:00
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
2020-09-11 12:12:51 +00:00
// CLI: `pigeon`
2020-09-10 12:33:41 +00:00
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.`,
2020-09-11 12:12:51 +00:00
Run: func(cmd *cobra.Command, args []string) {
},
2020-09-10 12:33:41 +00:00
}
2020-09-11 12:12:51 +00:00
// CLI: `pigeon version`
2020-09-10 12:33:41 +00:00
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the software version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Pigeon CLI Client (Golang), version %s\n", Version)
},
}
2020-09-11 12:12:51 +00:00
// CLI: `pigeon show [resource]`
2020-09-10 12:33:41 +00:00
var showCmd = &cobra.Command{
Use: "show [resource]",
Short: "Show various resources",
Long: `Shows resources such as blobs, drafts, identities, messages, peers, etc..`,
}
// CLI: `pigeon follow [resource]`
var followCmd = &cobra.Command{
Use: "follow [resource]",
Short: "follow various resources",
Long: `Follows resources such as blobs, drafts, identities, messages, peers, etc..`,
}
2020-09-11 12:12:51 +00:00
// CLI: `pigeon create [resource]`
2020-09-10 12:33:41 +00:00
var createCmd = &cobra.Command{
Use: "create [resource]",
Short: "Create various resources",
Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`,
}
2020-09-11 12:12:51 +00:00
// CLI: `pigeon create identity`
2020-09-10 12:33:41 +00:00
var createIdentityCmd = &cobra.Command{
Use: "identity",
Short: "Create a new identity.",
Long: `Creates a new identity.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(createOrShowIdentity())
},
}
2020-09-11 12:12:51 +00:00
// CLI: `pigeon show identity`
2020-09-10 12:33:41 +00:00
var showIdentityCmd = &cobra.Command{
Use: "identity",
Short: "Show current user identity.",
Long: `Prints the current Pigeon identity to screen. Prints 'NONE' if
not found.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(showIdentity())
},
}
// BootstrapCLI wires up all the relevant commands.
func BootstrapCLI() {
createCmd.AddCommand(createIdentityCmd)
showCmd.AddCommand(showIdentityCmd)
followCmd.AddCommand()
2020-09-10 12:33:41 +00:00
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(followCmd)
2020-09-10 12:33:41 +00:00
rootCmd.AddCommand(showCmd)
rootCmd.AddCommand(versionCmd)
2020-09-10 12:33:41 +00:00
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}