mirror of https://github.com/docker/compose.git
Nicer subscription display. Cf https://github.com/docker/desktop-microsoft/issues/21
This commit is contained in:
parent
d6084e1b6e
commit
e99e3aefc5
|
@ -147,12 +147,12 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
|
|||
func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (string, error) {
|
||||
if len(subs) == 1 {
|
||||
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
|
||||
}
|
||||
var options []string
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -164,6 +164,10 @@ func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (strin
|
|||
return *subs[selected].SubscriptionID, nil
|
||||
}
|
||||
|
||||
func display(sub subscription.Model) string {
|
||||
return fmt.Sprintf("%s (%s)", *sub.DisplayName, *sub.SubscriptionID)
|
||||
}
|
||||
|
||||
type userSelector interface {
|
||||
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)
|
||||
|
||||
selectOptions := []string{"Subscription1(1234)", "Subscription2(5678)"}
|
||||
selectOptions := []string{"Subscription1 (1234)", "Subscription2 (5678)"}
|
||||
suite.mockUserSelector.On("userSelect", "Select a subscription ID", selectOptions).Return(1, nil)
|
||||
selectOptions = []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
|
||||
suite.mockUserSelector.On("userSelect", "Select a resource group", selectOptions).Return(2, nil)
|
||||
|
|
Loading…
Reference in New Issue