mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-07-13 05:09:09 +00:00
add basic operational commands
This commit is contained in:
parent
64c878c9d5
commit
219c451098
12 changed files with 898 additions and 0 deletions
38
cmd/configure.go
Normal file
38
cmd/configure.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// configureCmd represents the configure command
|
||||
var configureCmd = &cobra.Command{
|
||||
Use: "configure",
|
||||
Short: "configure saves the provided global flags to the config file",
|
||||
Long: `configure saves the provided global flags to the config file.
|
||||
this makes using the cli easier as they don't have to be specifed all the time.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if viper.ConfigFileUsed() == "" {
|
||||
err := viper.SafeWriteConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Writing Config: %w", err)
|
||||
}
|
||||
} else {
|
||||
err := viper.WriteConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Writing Config: %w", err)
|
||||
}
|
||||
}
|
||||
if viper.GetBool("debug") {
|
||||
fmt.Printf("Saved: %+v\n", viper.AllSettings())
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(configureCmd)
|
||||
}
|
17
cmd/create.go
Normal file
17
cmd/create.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// createCmd represents the create command
|
||||
var createCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Creates a Passbolt Entity",
|
||||
Long: `Creates a Passbolt Entity`,
|
||||
Aliases: []string{"new"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(createCmd)
|
||||
}
|
19
cmd/delete.go
Normal file
19
cmd/delete.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// deleteCmd represents the delete command
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Deletes a Passbolt Entity",
|
||||
Long: `Deletes a Passbolt Entity`,
|
||||
Aliases: []string{"remove"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(deleteCmd)
|
||||
|
||||
deleteCmd.PersistentFlags().String("id", "", "ID of the Entity to Delete")
|
||||
}
|
18
cmd/get.go
Normal file
18
cmd/get.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// getCmd represents the get command
|
||||
var getCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "Gets a Passbolt Entity",
|
||||
Long: `Gets a Passbolt Entity`,
|
||||
Aliases: []string{"read"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(getCmd)
|
||||
|
||||
}
|
18
cmd/list.go
Normal file
18
cmd/list.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// listCmd represents the list command
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Lists Passbolt Entitys",
|
||||
Long: `Lists Passbolt Entitys`,
|
||||
Aliases: []string{"index", "ls", "filter", "search"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCmd)
|
||||
|
||||
}
|
15
cmd/move.go
Normal file
15
cmd/move.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// moveCmd represents the move command
|
||||
var moveCmd = &cobra.Command{
|
||||
Use: "move",
|
||||
Short: "Moves a Passbolt Entity",
|
||||
Long: `Moves a Passbolt Entity`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
74
cmd/root.go
Normal file
74
cmd/root.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var cfgFile string
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "go-passbolt-cli",
|
||||
Short: "A CLI tool to interact with Passbolt.",
|
||||
Long: `A CLI tool to interact with Passbolt.`,
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config File")
|
||||
|
||||
rootCmd.PersistentFlags().Bool("debug", false, "Enable Debug Logging")
|
||||
rootCmd.PersistentFlags().Duration("timeout", time.Minute, "Timeout for the Context")
|
||||
rootCmd.PersistentFlags().String("serverAddress", "", "Passbolt Server Address (https://passbolt.example.com)")
|
||||
rootCmd.PersistentFlags().String("userPrivateKey", "", "Passbolt User Private Key")
|
||||
rootCmd.PersistentFlags().String("userPassword", "", "Passbolt User Password")
|
||||
|
||||
viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
|
||||
viper.BindPFlag("timeout", rootCmd.PersistentFlags().Lookup("timeout"))
|
||||
viper.BindPFlag("serverAddress", rootCmd.PersistentFlags().Lookup("serverAddress"))
|
||||
viper.BindPFlag("userPrivateKey", rootCmd.PersistentFlags().Lookup("userPrivateKey"))
|
||||
viper.BindPFlag("userPassword", rootCmd.PersistentFlags().Lookup("userPassword"))
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
func initConfig() {
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
// Find config directory.
|
||||
confDir, err := os.UserConfigDir()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
confDir = filepath.Join(confDir, "go-passbolt-cli")
|
||||
_ = os.MkdirAll(confDir, 0755)
|
||||
|
||||
viper.AddConfigPath(confDir)
|
||||
viper.SetConfigType("toml")
|
||||
viper.SetConfigName("go-passbolt-cli")
|
||||
}
|
||||
|
||||
viper.AutomaticEnv() // read in environment variables that match
|
||||
|
||||
// If a config file is found, read it in.
|
||||
if err := viper.ReadInConfig(); err == nil && viper.GetBool("debug") {
|
||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||
}
|
||||
}
|
16
cmd/share.go
Normal file
16
cmd/share.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// shareCmd represents the share command
|
||||
var shareCmd = &cobra.Command{
|
||||
Use: "share",
|
||||
Short: "Shares a Passbolt Entity",
|
||||
Long: `Shares a Passbolt Entity`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(shareCmd)
|
||||
}
|
17
cmd/update.go
Normal file
17
cmd/update.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// updateCmd represents the update command
|
||||
var updateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Updates a Passbolt Entity",
|
||||
Long: `Updates a Passbolt Entity`,
|
||||
Aliases: []string{"change"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(updateCmd)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue