зеркало из https://github.com/docker/hub-tool.git
Fix token create --format json
It will now output the token in json format Fixes #63 Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
This commit is contained in:
Родитель
dec3d97f45
Коммит
57a99cefbb
|
@ -109,11 +109,12 @@ func runList(streams command.Streams, hubClient *hub.Client, opts listOptions, a
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.Print(streams.Out(), &helper{repositories, total}, printRepositories)
|
return opts.Print(streams.Out(), repositories, printRepositories(total))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printRepositories(out io.Writer, values interface{}) error {
|
func printRepositories(total int) format.PrettyPrinter {
|
||||||
h := values.(*helper)
|
return func(out io.Writer, values interface{}) error {
|
||||||
|
repositories := values.([]hub.Repository)
|
||||||
tw := tabwriter.New(out, " ")
|
tw := tabwriter.New(out, " ")
|
||||||
|
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
|
@ -122,7 +123,7 @@ func printRepositories(out io.Writer, values interface{}) error {
|
||||||
|
|
||||||
tw.Line()
|
tw.Line()
|
||||||
|
|
||||||
for _, repository := range h.repositories {
|
for _, repository := range repositories {
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
value, width := column.value(repository)
|
value, width := column.value(repository)
|
||||||
tw.Column(value, width)
|
tw.Column(value, width)
|
||||||
|
@ -133,13 +134,9 @@ func printRepositories(out io.Writer, values interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(h.repositories) < h.total {
|
if len(repositories) < total {
|
||||||
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(h.repositories), h.total)))
|
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(repositories), total)))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type helper struct {
|
|
||||||
repositories []hub.Repository
|
|
||||||
total int
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,11 +170,12 @@ func runList(streams command.Streams, hubClient *hub.Client, opts listOptions, r
|
||||||
defaultColumns = append(defaultColumns, platformColumn)
|
defaultColumns = append(defaultColumns, platformColumn)
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.Print(streams.Out(), &helper{tags, total}, printTags)
|
return opts.Print(streams.Out(), tags, printTags(total))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTags(out io.Writer, values interface{}) error {
|
func printTags(total int) format.PrettyPrinter {
|
||||||
h := values.(*helper)
|
return func(out io.Writer, values interface{}) error {
|
||||||
|
tags := values.([]hub.Tag)
|
||||||
tw := tabwriter.New(out, " ")
|
tw := tabwriter.New(out, " ")
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
tw.Column(ansi.Header(column.header), len(column.header))
|
tw.Column(ansi.Header(column.header), len(column.header))
|
||||||
|
@ -182,7 +183,7 @@ func printTags(out io.Writer, values interface{}) error {
|
||||||
|
|
||||||
tw.Line()
|
tw.Line()
|
||||||
|
|
||||||
for _, tag := range h.tags {
|
for _, tag := range tags {
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
value, width := column.value(tag)
|
value, width := column.value(tag)
|
||||||
tw.Column(value, width)
|
tw.Column(value, width)
|
||||||
|
@ -193,12 +194,13 @@ func printTags(out io.Writer, values interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(h.tags) < h.total {
|
if len(tags) < total {
|
||||||
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(h.tags), h.total)))
|
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(tags), total)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sortAsc = "asc"
|
sortAsc = "asc"
|
||||||
|
@ -253,8 +255,3 @@ func promptCallToAction(out io.Writer, client accountInfo) error {
|
||||||
_, err = fmt.Fprint(out, ansi.Info(callToAction))
|
_, err = fmt.Fprint(out, ansi.Info(callToAction))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type helper struct {
|
|
||||||
tags []hub.Tag
|
|
||||||
total int
|
|
||||||
}
|
|
||||||
|
|
|
@ -65,15 +65,16 @@ func runCreate(streams command.Streams, hubClient *hub.Client, opts createOption
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return opts.Print(streams.Out(), &printHelper{hubClient.AuthConfig.Username, token, opts.quiet}, printCreatedToken)
|
if opts.quiet {
|
||||||
}
|
fmt.Fprintln(streams.Out(), token.Token)
|
||||||
|
|
||||||
func printCreatedToken(out io.Writer, value interface{}) error {
|
|
||||||
helper := value.(*printHelper)
|
|
||||||
if helper.quiet {
|
|
||||||
fmt.Fprintln(out, helper.token.Token)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return opts.Print(streams.Out(), token, printCreatedToken(hubClient))
|
||||||
|
}
|
||||||
|
|
||||||
|
func printCreatedToken(hubClient *hub.Client) format.PrettyPrinter {
|
||||||
|
return func(out io.Writer, value interface{}) error {
|
||||||
|
helper := value.(*hub.Token)
|
||||||
fmt.Fprintf(out, ansi.Emphasise("Personal Access Token successfully created!")+`
|
fmt.Fprintf(out, ansi.Emphasise("Personal Access Token successfully created!")+`
|
||||||
|
|
||||||
When logging in from your Docker CLI client, use this token as a password.
|
When logging in from your Docker CLI client, use this token as a password.
|
||||||
|
@ -88,14 +89,9 @@ To use the access token from your Docker CLI client:
|
||||||
`+ansi.Warn(`WARNING: This access token will only be displayed once.
|
`+ansi.Warn(`WARNING: This access token will only be displayed once.
|
||||||
It will not be stored and cannot be retrieved. Please be sure to save it now.
|
It will not be stored and cannot be retrieved. Please be sure to save it now.
|
||||||
`),
|
`),
|
||||||
helper.token.Description,
|
helper.Description,
|
||||||
helper.userName,
|
hubClient.AuthConfig.Username,
|
||||||
ansi.Emphasise(helper.token.Token))
|
ansi.Emphasise(helper.Token))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type printHelper struct {
|
|
||||||
userName string
|
|
||||||
token *hub.Token
|
|
||||||
quiet bool
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,18 +98,19 @@ func runList(streams command.Streams, hubClient *hub.Client, opts listOptions) e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return opts.Print(streams.Out(), &helper{tokens, total}, printTokens)
|
return opts.Print(streams.Out(), tokens, printTokens(total))
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTokens(out io.Writer, values interface{}) error {
|
func printTokens(total int) format.PrettyPrinter {
|
||||||
h := values.(*helper)
|
return func(out io.Writer, values interface{}) error {
|
||||||
|
tokens := values.([]hub.Token)
|
||||||
tw := tabwriter.New(out, " ")
|
tw := tabwriter.New(out, " ")
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
tw.Column(ansi.Header(column.header), len(column.header))
|
tw.Column(ansi.Header(column.header), len(column.header))
|
||||||
}
|
}
|
||||||
|
|
||||||
tw.Line()
|
tw.Line()
|
||||||
for _, token := range h.tokens {
|
for _, token := range tokens {
|
||||||
for _, column := range defaultColumns {
|
for _, column := range defaultColumns {
|
||||||
value, width := column.value(token)
|
value, width := column.value(token)
|
||||||
tw.Column(value, width)
|
tw.Column(value, width)
|
||||||
|
@ -120,13 +121,9 @@ func printTokens(out io.Writer, values interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(h.tokens) < h.total {
|
if len(tokens) < total {
|
||||||
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(h.tokens), h.total)))
|
fmt.Fprintln(out, ansi.Info(fmt.Sprintf("%v/%v listed, use --all flag to show all", len(tokens), total)))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type helper struct {
|
|
||||||
tokens []hub.Token
|
|
||||||
total int
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче