@@ -30,12 +30,10 @@ func main() {
3030 Run : func (cmd * cobra.Command , args []string ) {
3131 rootLogger := logex .StandardLogger ()
3232
33- if err := runBackup (
33+ exitIfError ( runBackup (
3434 ossignal .InterruptOrTerminateBackgroundCtx (logex .Prefix ("main" , rootLogger )),
3535 rootLogger ,
36- ); err != nil {
37- panic (err )
38- }
36+ ))
3937 },
4038 })
4139
@@ -47,10 +45,7 @@ func main() {
4745 app .AddCommand (decryptionKeyGenerateEntry ())
4846 app .AddCommand (decryptionKeyToEncryptionKeyEntry ())
4947
50- if err := app .Execute (); err != nil {
51- fmt .Fprintln (os .Stderr , err )
52- os .Exit (1 )
53- }
48+ exitIfError (app .Execute ())
5449}
5550
5651func manualEntry () * cobra.Command {
@@ -84,11 +79,12 @@ func manualEntry() *cobra.Command {
8479 Run : func (cmd * cobra.Command , args []string ) {
8580 rootLogger := logex .StandardLogger ()
8681
87- ctx := ossignal .InterruptOrTerminateBackgroundCtx (logex .Prefix ("main" , rootLogger ))
88-
89- if err := manual (ctx , args [0 ], args [1 ], os .Stdin , rootLogger ); err != nil {
90- panic (err )
91- }
82+ exitIfError (manual (
83+ ossignal .InterruptOrTerminateBackgroundCtx (rootLogger ),
84+ args [0 ],
85+ args [1 ],
86+ os .Stdin ,
87+ rootLogger ))
9288 },
9389 }
9490}
@@ -112,9 +108,7 @@ func configValidateEntry() *cobra.Command {
112108 Short : "Validates your config file (from stdin)" ,
113109 Args : cobra .NoArgs ,
114110 Run : func (cmd * cobra.Command , args []string ) {
115- if err := jsonfile .Unmarshal (os .Stdin , & ubconfig.Config {}, true ); err != nil {
116- panic (err )
117- }
111+ exitIfError (jsonfile .Unmarshal (os .Stdin , & ubconfig.Config {}, true ))
118112 },
119113 }
120114}
@@ -128,9 +122,7 @@ func configExampleEntry() *cobra.Command {
128122 Short : "Shows you an example config file" ,
129123 Args : cobra .NoArgs ,
130124 Run : func (cmd * cobra.Command , args []string ) {
131- if err := jsonfile .Marshal (os .Stdout , ubconfig .DefaultConfig (pubkeyFilePath , kitchenSink )); err != nil {
132- panic (err )
133- }
125+ exitIfError (jsonfile .Marshal (os .Stdout , ubconfig .DefaultConfig (pubkeyFilePath , kitchenSink )))
134126 },
135127 }
136128
@@ -139,3 +131,9 @@ func configExampleEntry() *cobra.Command {
139131
140132 return cmd
141133}
134+
135+ func exitIfError (err error ) {
136+ if err != nil {
137+ fmt .Fprintln (os .Stderr , err )
138+ }
139+ }
0 commit comments