Documentation
¶
Overview ¶
Package cmd implements the Cobra commands for the charm CLI.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BackupKeysCmd = &cobra.Command{ Use: "backup-keys", Hidden: false, Short: "Backup your Charm account keys", Long: paragraph(fmt.Sprintf("%s your Charm account keys.", keyword("Backup"))), Args: cobra.NoArgs, DisableFlagsInUseLine: true, RunE: func(cmd *cobra.Command, args []string) error { const filename = "charm-keys-backup.tar" cwd, err := os.Getwd() if err != nil { return err } keyPath := path.Join(cwd, filename) if fileOrDirectoryExists(keyPath) { fmt.Printf("Not creating backup file: %s already exists.\n\n", code(filename)) os.Exit(1) } cfg, err := client.ConfigFromEnv() if err != nil { return err } dd, err := client.DataPath(cfg.Host) if err != nil { return err } if err := validateDirectory(dd); err != nil { return err } err = createTar(dd, filename) if err != nil { return err } fmt.Printf("Done! Saved keys to %s.\n\n", code(filename)) return nil }, }
BackupKeysCmd is the cobra.Command to back up a user's account SSH keys.
View Source
var BioCmd = &cobra.Command{ Use: "bio", Hidden: true, Short: "", Long: "", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cc := initCharmClient(animatedKeygen) u, err := cc.Bio() if err != nil { return err } fmt.Println(u) return nil }, }
BioCmd is the cobra.Command to return a user's bio JSON result.
View Source
var CompletionCmd = &cobra.Command{ Use: "completion [bash|zsh|fish|powershell]", Short: "Generate shell completion", Long: completionInstructions(), DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, Args: cobra.ExactValidArgs(1), Run: func(cmd *cobra.Command, args []string) { switch args[0] { case "bash": cmd.Root().GenBashCompletion(os.Stdout) case "zsh": cmd.Root().GenZshCompletion(os.Stdout) case "fish": cmd.Root().GenFishCompletion(os.Stdout, true) case "powershell": cmd.Root().GenPowerShellCompletion(os.Stdout) } }, }
CompletionCmd is the cobra.Command to generate shell completion.
View Source
var ( // CryptCmd is the cobra.Command to manage encryption and decryption for a user. CryptCmd = &cobra.Command{ Use: "crypt", Hidden: false, Short: "Use Charm encryption.", Long: styles.Paragraph.Render("Commands to encrypt and decrypt data with your Charm Cloud encryption keys."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return nil }, } )
View Source
var ( // FSCmd is the cobra.Command to use the Charm file system. FSCmd = &cobra.Command{ Use: "fs", Hidden: false, Short: "Use the Charm file system.", Long: paragraph(fmt.Sprintf("Commands to set, get and delete data from your Charm Cloud backed file system.")), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return nil }, } )
View Source
var IDCmd = &cobra.Command{ Use: "id", Short: "Print your Charm ID", Long: paragraph("Want to know your " + keyword("Charm ID") + "? You’re in luck, kiddo."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cc := initCharmClient(animatedKeygen) id, err := cc.ID() if err != nil { return err } fmt.Println(id) return nil }, }
IDCmd is the cobra.Command to print a user's Charm ID.
View Source
var ( // ImportKeysCmd is the cobra.Command to import a user's ssh key backup as creaed by `backup-keys`. ImportKeysCmd = &cobra.Command{ Use: "import-keys BACKUP.tar", Hidden: false, Short: "Import previously backed up Charm account keys.", Long: paragraph(fmt.Sprintf("%s previously backed up Charm account keys.", keyword("Backup"))), Args: cobra.ExactArgs(1), DisableFlagsInUseLine: false, RunE: func(cmd *cobra.Command, args []string) error { cfg, err := client.ConfigFromEnv() if err != nil { return err } dd, err := client.DataPath(cfg.Host) if err != nil { return err } if err := os.MkdirAll(dd, 0700); err != nil { return err } empty, err := isEmpty(dd) if err != nil { return err } if !empty && !forceImportOverwrite { if common.IsTTY() { return newImportConfirmationTUI(args[0], dd).Start() } return fmt.Errorf("not overwriting the existing keys in %s; to force, use -f", dd) } err = untar(args[0], dd) if err != nil { return err } paragraph(fmt.Sprintf("Done! Keys imported to %s", code(dd))) return nil }, } )
View Source
var JWTCmd = &cobra.Command{ Use: "jwt", Short: "Print a JWT", Long: paragraph(keyword("JSON Web Tokens") + " are a way to authenticate to different services that utilize your Charm account. Use " + code("jwt") + " to get one for your account."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cc := initCharmClient(animatedKeygen) jwt, err := cc.JWT() if err != nil { return err } fmt.Printf("%s\n", jwt) return nil }, }
JWTCmd is the cobra.Command that prints a user's JWT token.
View Source
var ( // KVCmd is the cobra.Command for a user to use the Charm key value store. KVCmd = &cobra.Command{ Use: "kv", Hidden: false, Short: "Use the Charm key value store.", Long: paragraph(fmt.Sprintf("Commands to set, get and delete data from your Charm Cloud backed key value store.")), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return nil }, } )
View Source
var KeySyncCmd = &cobra.Command{ Use: "sync-keys", Hidden: true, Short: "Re-encrypt encrypt keys for all linked public keys", Long: paragraph(fmt.Sprintf("%s encrypt keys for all linked public keys", keyword("Re-encrypt"))), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cc := initCharmClient(animatedKeygen) return cc.SyncEncryptKeys() }, }
KeySyncCmd is the cobra.Command to rencrypt and sync all encrypt keys for a user.
View Source
var ( // KeygenCmd is the cobra.Command to generate a new SSH keypair and user account. KeygenCmd = &cobra.Command{ Use: "keygen", Hidden: true, Short: "Generate SSH keys", Long: paragraph("Charm accounts are powered by " + keyword("SSH keys") + ". This command will create them for you."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { if common.IsTTY() && !simpleOutput { cfg := getCharmConfig() if cfg.Logfile != "" { f, err := tea.LogToFile(cfg.Logfile, "charm") if err != nil { return err } defer f.Close() } return keygen.NewProgram(cfg.Host, true).Start() } return nil }, } )
View Source
var KeysCmd = &cobra.Command{ Use: "keys", Short: "Browse or print linked SSH keys", Long: paragraph("Charm accounts are powered by " + keyword("SSH keys") + ". This command prints all of the keys linked to your account. To remove keys use the main " + code("charm") + " interface."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { if common.IsTTY() && !simpleOutput && !randomart { cfg := getCharmConfig() if cfg.Logfile != "" { f, err := tea.LogToFile(cfg.Logfile, "charm") if err != nil { return err } defer f.Close() } return keys.NewProgram(cfg).Start() } cc := initCharmClient(animatedKeygen) k, err := cc.AuthorizedKeysWithMetadata() if err != nil { return err } keys := k.Keys for i := 0; i < len(keys); i++ { if !randomart { fmt.Println(keys[i].Key) continue } fp, err := client.FingerprintSHA256(*keys[i]) if err != nil { fp.Value = fmt.Sprintf("Could not generate fingerprint for key %s: %v\n\n", keys[i].Key, err) } board, err := client.RandomArt(*keys[i]) if err != nil { board = fmt.Sprintf("Could not generate randomart for key %s: %v\n\n", keys[i].Key, err) } cr := "\n\n" if i == len(keys)-1 { cr = "\n" } fmt.Printf("%s\n%s%s", fp, board, cr) } return nil }, }
KeysCmd is the cobra.Command for a user to browser and print their linked SSH keys.
View Source
var NameCmd = &cobra.Command{ Use: "name [username]", Short: "Username stuff", Long: paragraph("Print or set your " + keyword("username") + ". If the name is already taken, just run it again with a different, cooler name. Basic latin letters and numbers only, 50 characters max."), Args: cobra.RangeArgs(0, 1), Example: indent.String("charm name\ncharm name beatrix", 2), RunE: func(cmd *cobra.Command, args []string) error { cc := initCharmClient(animatedKeygen) switch len(args) { case 0: u, err := cc.Bio() if err != nil { return err } fmt.Println(u.Name) return nil default: n := args[0] if !client.ValidateName(n) { msg := fmt.Sprintf("%s is invalid.\n\nUsernames must be basic latin letters, numerals, and no more than 50 characters. And no emojis, kid.\n", code(n)) fmt.Println(paragraph(msg)) os.Exit(1) } u, err := cc.SetName(n) if err == charm.ErrNameTaken { paragraph(fmt.Sprintf("User name %s is already taken. Try a different, cooler name.\n", code(n))) os.Exit(1) } if err != nil { paragraph(fmt.Sprintf("Welp, there’s been an error. %s", subtle(err.Error()))) return err } paragraph(fmt.Sprintf("OK! Your new username is %s", code(u.Name))) return nil } }, }
NameCmd is the cobra.Command to print or set a username.
View Source
var ( //PostNewsCmd is the cobra.Command to self-host the Charm Cloud. PostNewsCmd = &cobra.Command{ Use: "post-news", Hidden: true, Short: "Post news to the self-hosted Charm server.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cfg := server.DefaultConfig() if serverDataDir != "" { cfg.DataDir = serverDataDir } sp := fmt.Sprintf("%s/.ssh", cfg.DataDir) kp, err := keygen.NewWithWrite(sp, "charm_server", []byte(""), keygen.RSA) if err != nil { return err } cfg = cfg.WithKeys(kp.PublicKey, kp.PrivateKeyPEM) s, err := server.NewServer(cfg) if err != nil { return err } if newsSubject == "" { newsSubject = args[0] } ts := strings.Split(newsTagList, ",") d, err := os.ReadFile(args[0]) if err != nil { return err } err = s.Config.DB.PostNews(newsSubject, string(d), ts) if err != nil { return err } return nil }, } )
View Source
var ( //ServeCmd is the cobra.Command to self-host the Charm Cloud. ServeCmd = &cobra.Command{ Use: "serve", Aliases: []string{"server"}, Hidden: false, Short: "Start a self-hosted Charm Cloud server.", Long: paragraph("Start the SSH and HTTP servers needed to power a SQLite-backed Charm Cloud."), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cfg := server.DefaultConfig() if serverHTTPPort != 0 { cfg.HTTPPort = serverHTTPPort } if serverSSHPort != 0 { cfg.SSHPort = serverSSHPort } if serverDataDir != "" { cfg.DataDir = serverDataDir } sp := fmt.Sprintf("%s/.ssh", cfg.DataDir) kp, err := keygen.NewWithWrite(sp, "charm_server", []byte(""), keygen.RSA) if err != nil { return err } cfg = cfg.WithKeys(kp.PublicKey, kp.PrivateKeyPEM) s, err := server.NewServer(cfg) if err != nil { return err } s.Start() return nil }, } )
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.