imap-notes/cmd/root.go

52 lines
1.4 KiB
Go

package cmd
import (
"git.iamthefij.com/iamthefij/slog"
"github.com/spf13/cobra"
"git.iamthefij.com/iamthefij/imap-notes/lib"
)
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 Execute() {
cobra.OnInitialize(func() { lib.InitializeConfig(configFile) })
rootCmd.AddCommand(loginCmd)
rootCmd.AddCommand(tuiCmd)
addConfigCmd()
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")
}