-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed cmd dependency tree and made start readable
- Loading branch information
Showing
7 changed files
with
106 additions
and
17 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,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
yey "github.com/silphid/yey/src/internal" | ||
) | ||
|
||
func PromptContext(contexts yey.Contexts) (string, error) { | ||
// Get context names | ||
names := contexts.GetNames() | ||
if len(names) == 0 { | ||
return "", fmt.Errorf("no context defined") | ||
} | ||
|
||
// Only one context defined, no need to prompt | ||
if len(names) == 1 { | ||
return names[0], nil | ||
} | ||
|
||
// Show selection prompt | ||
prompt := &survey.Select{ | ||
Message: "Select context:", | ||
Options: names, | ||
} | ||
|
||
selectedIndex := 0 | ||
if err := survey.AskOne(prompt, &selectedIndex); err != nil { | ||
return "", err | ||
} | ||
|
||
return names[selectedIndex], 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
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
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,18 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
var imageNameRegex = regexp.MustCompile(`(.*/)?(.+?)(:.*)?$`) | ||
|
||
// GetShortImageName returns short image name without any registry | ||
// prefix or tag suffix, to be used as part of container name. | ||
func GetShortImageName(imageName string) (string, error) { | ||
submatches := imageNameRegex.FindStringSubmatch(imageName) | ||
if len(submatches) < 4 { | ||
return "", fmt.Errorf("malformed image name %q", imageName) | ||
} | ||
return submatches[2], 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