Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,44 @@ import (

var (
// Global BookWorm
Bw *internal.BookWorm
tagFilter string
Bw *internal.BookWorm
tagFilter string
verboseMode bool
)

var rootCmd = &cobra.Command{
Use: "bookworm",
Short: "Bookworm can manage your bookmarks from the command line.",
PreRunE: prGetCfg,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
m := TeaModel()
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
if verboseMode {
fmt.Println("Failed to run bubbletea!")
}
return err
}
return nil
},
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&verboseMode, "verbose", "v", false, "Enable verbose output")
rootCmd.SilenceErrors = true
if verboseMode {
rootCmd.SilenceUsage = true
}
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println("Something Horrible Happened!", err)
fmt.Println("Failed to execute the root command!")
if !verboseMode {
fmt.Println("Use the --verbose flag for more information ")
}
if verboseMode {
fmt.Println(err)
}
}
}
16 changes: 12 additions & 4 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ func prGetCfg(_ *cobra.Command, _ []string) error {
var err error
Bw, err = internal.Get()
if err != nil {
fmt.Println("Couldn't get Config, please run bookworm init!")
os.Exit(2)
fmt.Println("Couldn't get config!")
fmt.Println("Run bookworm init to initialize the config.")
if !verboseMode {
fmt.Println("Use the --verbose flag for more information")
os.Exit(2)
}
return err
}
return nil
}

func prInitCfg(cmd *cobra.Command, args []string) error {
var err error
if verboseMode {
fmt.Println("Initing config...")
}
Bw, err = internal.Init()
if err != nil {
fmt.Println("Failed to create config!")
os.Exit(2)
if verboseMode {
fmt.Println("Recieved error during init config:", err)
}
return err
}
return nil
Expand Down