imap-notes/cmd/root.go

58 lines
1.6 KiB
Go

package cmd
import (
"git.iamthefij.com/iamthefij/slog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var rootCmd = &cobra.Command{
Use: "imap-notes",
Short: "IMAP-Notes an editor for notes stored in an IMAP folder",
Long: `A notes editor that uses an IMAP folder as it's backend. It allows
you to edit in markdown and store in HTML for viewing in Apple Notes`,
Run: func(cmd *cobra.Command, args []string) {
slog.Infof("Running root cobra command!")
},
}
var configFile string
func bindFlag(flagname string) {
slog.OnErrFatalf(viper.BindPFlag(
flagname,
rootCmd.PersistentFlags().Lookup(flagname),
), "failed binding flag: "+flagname)
}
func Execute() {
cobra.OnInitialize(initializeConfig)
rootCmd.AddCommand(loginCmd)
rootCmd.AddCommand(configCmd)
addConfigSubcommands()
addFoldersCmd()
addNotesCmd()
rootCmd.PersistentFlags().BoolVarP(&slog.DebugLevel, "debug", "v", false, "set debug logging level")
rootCmd.PersistentFlags().StringVarP(
&configFile,
"config",
"c",
"",
"config file (default to .config/imap-notes/config.toml or ~/.imap-notes.toml",
)
rootCmd.PersistentFlags().StringP("hostname", "s", "", "IMAP server hostname and port (requires SSL. eg :993)")
rootCmd.PersistentFlags().StringP("username", "u", "", "IMAP username")
rootCmd.PersistentFlags().StringP(
"password",
"p",
"",
"IMAP password (For savety, set a variable with `read` and then reference on your command line)",
)
bindFlag("hostname")
bindFlag("username")
bindFlag("password")
slog.OnErrFatalf(rootCmd.Execute(), "failed to execute root command")
}