1- // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
1+ // Licensed under the Apache License, Version 2.0 (the "License");
2+ // you may not use this file except in compliance with the License.
3+ // You may obtain a copy of the License at
24//
3- // Licensed under the Apache License, Version 2.0 (the "License"). You may
4- // not use this file except in compliance with the License. A copy of the
5- // License is located at
5+ // http://www.apache.org/licenses/LICENSE-2.0
66//
7- // http://aws.amazon.com/apache2.0/
8- //
9- // or in the "license" file accompanying this file. This file is distributed
10- // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11- // express or implied. See the License for the specific language governing
12- // permissions and limitations under the License.
7+ // Unless required by applicable law or agreed to in writing, software
8+ // distributed under the License is distributed on an "AS IS" BASIS,
9+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+ // See the License for the specific language governing permissions and
11+ // limitations under the License.
1312
1413package main
1514
@@ -24,18 +23,19 @@ import (
2423 "syscall"
2524 "time"
2625
27- commandline "github.com/aws/amazon-ec2-instance-selector/v3/pkg/cli"
28- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/env"
29- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/instancetypes"
30- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector"
31- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector/outputs"
32- "github.com/aws/amazon-ec2-instance-selector/v3/pkg/sorter"
3326 "github.com/aws/aws-sdk-go-v2/aws"
3427 "github.com/aws/aws-sdk-go-v2/config"
3528 ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
3629 tea "github.com/charmbracelet/bubbletea"
3730 "github.com/spf13/cobra"
3831 "go.uber.org/multierr"
32+
33+ commandline "github.com/aws/amazon-ec2-instance-selector/v3/pkg/cli"
34+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/env"
35+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/instancetypes"
36+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector"
37+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/selector/outputs"
38+ "github.com/aws/amazon-ec2-instance-selector/v3/pkg/sorter"
3939)
4040
4141const (
@@ -45,19 +45,19 @@ const (
4545 defaultProfile = "default"
4646 awsConfigFile = "~/.aws/config"
4747 // 0 means the last price
48- // increasing this results in a lot more API calls to EC2 which can slow things down
48+ // increasing this results in a lot more API calls to EC2 which can slow things down.
4949 spotPricingDaysBack = 0
5050
5151 tableOutput = "table"
5252 tableWideOutput = "table-wide"
5353 oneLine = "one-line"
5454 bubbleTeaOutput = "interactive"
5555
56- // Sort filter default
56+ // Sort filter default.
5757 instanceNamePath = ".InstanceType"
5858)
5959
60- // Filter Flag Constants
60+ // Filter Flag Constants.
6161const (
6262 vcpus = "vcpus"
6363 memory = "memory"
@@ -106,14 +106,14 @@ const (
106106 generation = "generation"
107107)
108108
109- // Aggregate Filter Flags
109+ // Aggregate Filter Flags.
110110const (
111111 instanceTypeBase = "base-instance-type"
112112 flexible = "flexible"
113113 service = "service"
114114)
115115
116- // Configuration Flag Constants
116+ // Configuration Flag Constants.
117117const (
118118 maxResults = "max-results"
119119 profile = "profile"
@@ -128,13 +128,10 @@ const (
128128 sortBy = "sort-by"
129129)
130130
131- var (
132- // versionID is overridden at compilation with the version based on the git tag
133- versionID = "dev"
134- )
131+ // versionID is overridden at compilation with the version based on the git tag
132+ var versionID = "dev"
135133
136134func main () {
137-
138135 log .SetOutput (os .Stderr )
139136 log .SetPrefix ("NOTE: " )
140137 log .SetFlags (log .Flags () &^ (log .Ldate | log .Ltime ))
@@ -276,7 +273,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
276273 cacheTTLDuration := time .Hour * time .Duration (* cli .IntMe (flags [cacheTTL ]))
277274 instanceSelector , err := selector .NewWithCache (ctx , cfg , cacheTTLDuration , * cli .StringMe (flags [cacheDir ]))
278275 if err != nil {
279- fmt .Printf ("An error occurred when initialising the ec2 selector: %v" , err )
276+ fmt .Printf ("An error occurred when initializing the ec2 selector: %v" , err )
280277 os .Exit (1 )
281278 }
282279 if flags [debug ] != nil {
@@ -477,7 +474,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
477474 var instanceTypes []string
478475 if outputFlag != nil && * outputFlag == bubbleTeaOutput {
479476 p := tea .NewProgram (outputs .NewBubbleTeaModel (instanceTypesDetails ), tea .WithMouseCellMotion ())
480- if err := p .Start (); err != nil {
477+ if _ , err := p .Run (); err != nil {
481478 fmt .Printf ("An error occurred when starting bubble tea: %v" , err )
482479 os .Exit (1 )
483480 }
@@ -516,7 +513,7 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
516513 defer waitGroup .Done ()
517514 if instanceSelector .EC2Pricing .OnDemandCacheCount () == 0 {
518515 if err := instanceSelector .EC2Pricing .RefreshOnDemandCache (ctx ); err != nil {
519- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the on-demand pricing cache: %w" , err ))
516+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the on-demand pricing cache: %w" , err ))
520517 }
521518 }
522519 return nil
@@ -525,7 +522,7 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
525522 defer waitGroup .Done ()
526523 if instanceSelector .EC2Pricing .SpotCacheCount () == 0 {
527524 if err := instanceSelector .EC2Pricing .RefreshSpotCache (ctx , spotPricingDaysBack ); err != nil {
528- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the spot pricing cache: %w" , err ))
525+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the spot pricing cache: %w" , err ))
529526 }
530527 }
531528 return nil
@@ -534,15 +531,19 @@ func hydrateCaches(ctx context.Context, instanceSelector selector.Selector) (err
534531 defer waitGroup .Done ()
535532 if instanceSelector .InstanceTypesProvider .CacheCount () == 0 {
536533 if _ , err := instanceSelector .InstanceTypesProvider .Get (ctx , nil ); err != nil {
537- return multierr .Append (errs , fmt .Errorf ("There was a problem refreshing the instance types cache: %w" , err ))
534+ return multierr .Append (errs , fmt .Errorf ("there was a problem refreshing the instance types cache: %w" , err ))
538535 }
539536 }
540537 return nil
541538 },
542539 }
543540 wg .Add (len (hydrateTasks ))
544541 for _ , task := range hydrateTasks {
545- go task (wg )
542+ go func () {
543+ if err := task (wg ); err != nil {
544+ log .Printf ("Hydrate task error: %v" , err )
545+ }
546+ }()
546547 }
547548 wg .Wait ()
548549 return errs
0 commit comments