2022-08-08 21:50:12 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-17 10:51:59 +00:00
|
|
|
"os"
|
2022-08-08 21:50:12 +00:00
|
|
|
)
|
|
|
|
|
2022-10-05 05:05:23 +00:00
|
|
|
func recoverErr(i any) error {
|
2022-08-08 21:50:12 +00:00
|
|
|
switch v := i.(type) {
|
|
|
|
case nil:
|
|
|
|
return nil
|
|
|
|
case string:
|
|
|
|
return fmt.Errorf("recovered panic: %s", v)
|
|
|
|
case error:
|
|
|
|
return fmt.Errorf("recovered panic: %w", v)
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("recovered panic with unknown type: %v", v)
|
|
|
|
}
|
|
|
|
}
|
2022-10-17 10:51:59 +00:00
|
|
|
|
|
|
|
func configFilterExisting(configs []string) (finalConfigs []string) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
for _, c := range configs {
|
|
|
|
if _, err = os.Stat(c); err == nil || !os.IsNotExist(err) {
|
|
|
|
finalConfigs = append(finalConfigs, c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return finalConfigs
|
|
|
|
}
|