From a744f85187dba4dab3de22bfb34c8ee445506a5e Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Tue, 8 Mar 2022 15:07:21 -0300 Subject: [PATCH] feat: man pages and completions Signed-off-by: Carlos A Becker --- cmd/melt/main.go | 28 +++++++++++++++++++++++++--- go.mod | 4 ++++ go.sum | 8 ++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cmd/melt/main.go b/cmd/melt/main.go index b222ee8..c253999 100644 --- a/cmd/melt/main.go +++ b/cmd/melt/main.go @@ -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" ) @@ -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", @@ -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") diff --git a/go.mod b/go.mod index 5db8bfa..ddb772d 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index d047608..14bab9d 100644 --- a/go.sum +++ b/go.sum @@ -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=