mirror of
https://github.com/docker/compose.git
synced 2025-07-26 15:14:04 +02:00
Merge pull request #245 from docker/subscription_display
Nicer subscription display.
This commit is contained in:
commit
c20587d0ac
@ -147,12 +147,12 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
|
|||||||
func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (string, error) {
|
func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (string, error) {
|
||||||
if len(subs) == 1 {
|
if len(subs) == 1 {
|
||||||
sub := subs[0]
|
sub := subs[0]
|
||||||
fmt.Println("Using only available subscription : " + *sub.DisplayName + "(" + *sub.SubscriptionID + ")")
|
fmt.Println("Using only available subscription : " + display(sub))
|
||||||
return *sub.SubscriptionID, nil
|
return *sub.SubscriptionID, nil
|
||||||
}
|
}
|
||||||
var options []string
|
var options []string
|
||||||
for _, sub := range subs {
|
for _, sub := range subs {
|
||||||
options = append(options, *sub.DisplayName+"("+*sub.SubscriptionID+")")
|
options = append(options, display(sub))
|
||||||
}
|
}
|
||||||
selected, err := helper.selector.userSelect("Select a subscription ID", options)
|
selected, err := helper.selector.userSelect("Select a subscription ID", options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -164,6 +164,10 @@ func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (strin
|
|||||||
return *subs[selected].SubscriptionID, nil
|
return *subs[selected].SubscriptionID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func display(sub subscription.Model) string {
|
||||||
|
return fmt.Sprintf("%s (%s)", *sub.DisplayName, *sub.SubscriptionID)
|
||||||
|
}
|
||||||
|
|
||||||
type userSelector interface {
|
type userSelector interface {
|
||||||
userSelect(message string, options []string) (int, error)
|
userSelect(message string, options []string) (int, error)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ func (suite *ContextSuiteTest) TestSelectSubscriptionIdAndExistingResourceGroup(
|
|||||||
|
|
||||||
suite.mockResourceGroupHeper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{sub1, sub2}, nil)
|
suite.mockResourceGroupHeper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{sub1, sub2}, nil)
|
||||||
|
|
||||||
selectOptions := []string{"Subscription1(1234)", "Subscription2(5678)"}
|
selectOptions := []string{"Subscription1 (1234)", "Subscription2 (5678)"}
|
||||||
suite.mockUserSelector.On("userSelect", "Select a subscription ID", selectOptions).Return(1, nil)
|
suite.mockUserSelector.On("userSelect", "Select a subscription ID", selectOptions).Return(1, nil)
|
||||||
selectOptions = []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
|
selectOptions = []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
|
||||||
suite.mockUserSelector.On("userSelect", "Select a resource group", selectOptions).Return(2, nil)
|
suite.mockUserSelector.On("userSelect", "Select a resource group", selectOptions).Return(2, nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user