Skip to content

Commit

Permalink
Parse flags before accessing config
Browse files Browse the repository at this point in the history
Fixes #13.
  • Loading branch information
muesli committed Oct 6, 2020
1 parent d15fedd commit e57cb07
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ var (
Short: "mastotool offers a collection of tools to work with your Mastodon account",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := initClient(); err != nil {
return err
}

var err error
self, err = client.GetAccountCurrentUser(context.Background())
if err != nil {
return fmt.Errorf("Can't retrieve user: %s", err)
}

return nil
},
}
)

Expand Down Expand Up @@ -120,19 +133,8 @@ func initClient() error {
func main() {
RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "mastodon.json", "uses the specified config file")

if err := initClient(); err != nil {
fmt.Println(err)
os.Exit(1)
}
var err error
self, err = client.GetAccountCurrentUser(context.Background())
if err != nil {
fmt.Printf("Can't retrieve user: %s\n", err)
os.Exit(1)
}

if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
os.Exit(1)
}
}

0 comments on commit e57cb07

Please sign in to comment.