-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cscli refact: extract packages ask, clientinfo (#3197)
* cscli: extrack package 'crowdsec-cli/ask' * cscli: extract package 'crowdsec-cli/clientinfo'
- Loading branch information
Showing
4 changed files
with
76 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ask | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
) | ||
|
||
func YesNo(message string, defaultAnswer bool) (bool, error) { | ||
var answer bool | ||
|
||
prompt := &survey.Confirm{ | ||
Message: message, | ||
Default: defaultAnswer, | ||
} | ||
|
||
if err := survey.AskOne(prompt, &answer); err != nil { | ||
return defaultAnswer, err | ||
} | ||
|
||
return answer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package clientinfo | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type featureflagProvider interface { | ||
GetFeatureflags() string | ||
} | ||
|
||
type osProvider interface { | ||
GetOsname() string | ||
GetOsversion() string | ||
} | ||
|
||
func GetOSNameAndVersion(o osProvider) string { | ||
ret := o.GetOsname() | ||
if o.GetOsversion() != "" { | ||
if ret != "" { | ||
ret += "/" | ||
} | ||
|
||
ret += o.GetOsversion() | ||
} | ||
|
||
if ret == "" { | ||
return "?" | ||
} | ||
|
||
return ret | ||
} | ||
|
||
func GetFeatureFlagList(o featureflagProvider) []string { | ||
if o.GetFeatureflags() == "" { | ||
return nil | ||
} | ||
|
||
return strings.Split(o.GetFeatureflags(), ",") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters