File tree Expand file tree Collapse file tree 2 files changed +32
-16
lines changed
Expand file tree Collapse file tree 2 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 11![ version] ( https://img.shields.io/github/v/release/CodeReaper/lane )
22![ tests] ( https://github.com/CodeReaper/lane/actions/workflows/tests.yaml/badge.svg )
3+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/codereaper/lane )] ( https://goreportcard.com/report/github.com/codereaper/lane )
34![ license] ( https://img.shields.io/github/license/CodeReaper/lane.svg )
45
56# lane
Original file line number Diff line number Diff line change @@ -18,29 +18,50 @@ type Flags struct {
1818}
1919
2020func (f * Flags ) validate () error {
21+ if err := f .checkRequiredFields (); err != nil {
22+ return err
23+ }
24+
25+ isIOS := strings .ToLower (f .Kind ) == "ios"
26+
27+ if err := f .checkRequiredFiles (isIOS ); err != nil {
28+ return err
29+ }
30+
31+ if isIOS || f .FillIn {
32+ if f .DefaultValueIndex <= 0 {
33+ return fmt .Errorf ("main index not provided" )
34+ }
35+ }
36+
37+ return nil
38+ }
39+
40+ func (f * Flags ) checkRequiredFields () error {
2141 if len (f .Input ) == 0 {
2242 return fmt .Errorf ("input not provided" )
2343 }
24- if len (f .Kind ) == 0 {
25- return fmt .Errorf ("kind not provided" )
26- }
2744 if f .KeyIndex <= 0 {
2845 return fmt .Errorf ("index not provided" )
2946 }
47+ if len (f .Kind ) == 0 {
48+ return fmt .Errorf ("kind not provided" )
49+ }
3050
31- isIOS := false
32-
33- validKind := false
51+ valid := false
3452 for _ , v := range validKinds {
35- if ! validKind && v == strings .ToLower (f .Kind ) {
36- validKind = true
53+ if v == strings .ToLower (f .Kind ) {
54+ valid = true
3755 }
38- isIOS = isIOS || strings .ToLower (f .Kind ) == "ios"
3956 }
40- if ! validKind {
57+ if ! valid {
4158 return fmt .Errorf ("invalid kind: %s. Valid kinds are %v" , f .Kind , validKinds )
4259 }
4360
61+ return nil
62+ }
63+
64+ func (f * Flags ) checkRequiredFiles (isIOS bool ) error {
4465 if _ , err := os .Stat (f .Input ); err != nil {
4566 return err
4667 }
@@ -60,11 +81,5 @@ func (f *Flags) validate() error {
6081 }
6182 }
6283
63- if isIOS || f .FillIn {
64- if f .DefaultValueIndex <= 0 {
65- return fmt .Errorf ("main index not provided" )
66- }
67- }
68-
6984 return nil
7085}
You can’t perform that action at this time.
0 commit comments