@@ -9,13 +9,14 @@ package cmd
99import (
1010 "fmt"
1111 "os"
12+ "strings"
1213 "time"
1314
1415 "github.com/atotto/clipboard"
1516 "github.com/aws/aws-sdk-go-v2/aws"
17+ "github.com/joshdk/buildversion"
1618 "github.com/pkg/browser"
1719 "github.com/spf13/cobra"
18- "jdk.sh/meta"
1920
2021 "github.com/joshdk/aws-console/console"
2122 "github.com/joshdk/aws-console/credentials"
@@ -225,58 +226,17 @@ func Command() *cobra.Command { //nolint:cyclop,funlen
225226
226227 // Define -A/--user-agent flag.
227228 cmd .Flags ().StringVarP (& flags .userAgent , "user-agent" , "A" ,
228- versionFmt ("joshdk/aws-console" , " %s (%s)" , meta . Version (), meta . ShortSHA () ),
229+ buildversion . Template ("joshdk/aws-console {{ .Version }}{{- if .ShortRevision }} ({{ .ShortRevision }}){{ end }}" ),
229230 "user agent to use for http requests" )
230231
231- cmd .Example = ` Generate a login url for the default profile:
232- $ aws-console
233-
234- Generate a login url for the "production" profile:
235- $ aws-console production
236-
237- Generate a login url from the output of the aws cli:
238- $ aws sts assume-role … | aws-console -
239-
240- Open url with the default browser:
241- $ aws-console --browser
242-
243- Redirect to IAM service after logging in:
244- $ aws-console --location iam
245-
246- Display a QR code for the login url:
247- $ aws-console --qr
248-
249- Save QR code to a file:
250- $ aws-console --qr > qr.png`
232+ // Set a custom list of examples.
233+ cmd .Example = strings .TrimRight (exampleText , "\n " )
251234
252235 // Add a custom usage footer template.
253- cmd .SetUsageTemplate (cmd .UsageTemplate () + versionFmt (
254- "\n Info:\n " +
255- " https://github.com/joshdk/aws-console\n " ,
256- " %s (%s) built on %v\n " ,
257- meta .Version (), meta .ShortSHA (), meta .DateFormat (time .RFC3339 ),
258- ))
236+ cmd .SetUsageTemplate (cmd .UsageTemplate () + "\n " + buildversion .Template (usageTemplate ))
259237
260238 // Set a custom version template.
261- cmd .SetVersionTemplate (versionFmt (
262- "homepage: https://github.com/joshdk/aws-console\n " +
263- "author: Josh Komoroske\n " +
264- "license: MIT\n " ,
265- "version: %s\n " +
266- "sha: %s\n " +
267- "date: %s\n " ,
268- meta .Version (), meta .ShortSHA (), meta .DateFormat (time .RFC3339 ),
269- ))
239+ cmd .SetVersionTemplate (buildversion .Template (versionTemplate ))
270240
271241 return cmd
272242}
273-
274- // versionFmt returns the given literal, as well as a formatted string if
275- // version metadata is set.
276- func versionFmt (literal , format string , a ... any ) string {
277- if meta .Version () == "" {
278- return literal
279- }
280-
281- return literal + fmt .Sprintf (format , a ... )
282- }
0 commit comments