Skip to content

Commit

Permalink
feat: man pages and completions
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Mar 8, 2022
1 parent 22c1f13 commit a744f85
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
28 changes: 25 additions & 3 deletions cmd/melt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/charmbracelet/melt"
"github.com/mattn/go-isatty"
"github.com/muesli/coral"
mcoral "github.com/muesli/mango-coral"
"github.com/muesli/roff"
"golang.org/x/crypto/ssh"
"golang.org/x/term"
)
Expand All @@ -23,9 +25,29 @@ var (
restoreStyle = lipgloss.NewStyle().Bold(true).Margin(1)

rootCmd = &coral.Command{
Use: "melt",
Short: "Backup and restore SSH keys using a mnemonic",
Use: "melt",
Short: "Backup and restore SSH keys using a mnemonic",
Long: `melt uses bip39 to create a mnemonic set of words that represents your SSH keys.
You can then use those words to restore your private key at any time.`,
SilenceUsage: true,
}
manCmd = &coral.Command{
Use: "man",
Args: coral.NoArgs,
Short: "generate man pages",
Hidden: true,
SilenceUsage: true,
RunE: func(cmd *coral.Command, args []string) error {
manPage, err := mcoral.NewManPage(1, rootCmd)
if err != nil {
return err
}
manPage = manPage.WithSection("Copyright", "(C) 2022 Charmbracelet, Inc.\n"+
"Released under MIT license.")
fmt.Println(manPage.Build(roff.NewDocument()))
return nil
},
}
backupCmd = &coral.Command{
Use: "backup",
Expand Down Expand Up @@ -68,7 +90,7 @@ Store them somewhere safe, print or memorize them.`))
)

func init() {
rootCmd.AddCommand(backupCmd, restoreCmd)
rootCmd.AddCommand(backupCmd, restoreCmd, manCmd)

restoreCmd.PersistentFlags().StringVarP(&mnemonic, "mnemonic", "m", "-", "Mnemonic set of words given by the backup command")
_ = restoreCmd.MarkFlagRequired("mnemonic")
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require (
github.com/matryer/is v1.4.0
github.com/mattn/go-isatty v0.0.14
github.com/muesli/coral v1.0.0
github.com/muesli/mango-coral v1.0.1
github.com/muesli/roff v0.1.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
Expand All @@ -17,6 +19,8 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/coral v1.0.0 h1:odyqkoEg4aJAINOzvnjN4tUsdp+Zleccs7tRIAkkYzU=
github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8=
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-coral v1.0.1 h1:W3nGbUC/q5vLscQ6GPzteHZrJI1Msjw5Hns82o0xRkI=
github.com/muesli/mango-coral v1.0.1/go.mod h1:EPSlYH67AtcxQrxssNw6r/lMFxHTjuDoGfq9Uxxevhg=
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down

0 comments on commit a744f85

Please sign in to comment.