mirror of https://github.com/docker/docs.git
pretty printing targets
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
parent
53626b6fe6
commit
0088d16bba
|
@ -3,13 +3,16 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -22,6 +25,7 @@ import (
|
||||||
notaryclient "github.com/docker/notary/client"
|
notaryclient "github.com/docker/notary/client"
|
||||||
"github.com/docker/notary/tuf/data"
|
"github.com/docker/notary/tuf/data"
|
||||||
"github.com/docker/notary/utils"
|
"github.com/docker/notary/utils"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -168,10 +172,7 @@ func tufList(cmd *cobra.Command, args []string) {
|
||||||
fatalf(err.Error())
|
fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print all the available targets
|
prettyPrintTargets(targetList, cmd.Out())
|
||||||
for _, t := range targetList {
|
|
||||||
cmd.Printf("%s %x %d\n", t.Name, t.Hashes["sha256"], t.Length)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func tufLookup(cmd *cobra.Command, args []string) {
|
func tufLookup(cmd *cobra.Command, args []string) {
|
||||||
|
@ -447,3 +448,38 @@ func getRemoteTrustServer() string {
|
||||||
}
|
}
|
||||||
return remoteTrustServer
|
return remoteTrustServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type targetsSorter []*notaryclient.Target
|
||||||
|
|
||||||
|
func (t targetsSorter) Len() int { return len(t) }
|
||||||
|
func (t targetsSorter) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
|
||||||
|
func (t targetsSorter) Less(i, j int) bool {
|
||||||
|
return t[i].Name < t[j].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a list of KeyStores in order of listing preference, pretty-prints the
|
||||||
|
// root keys and then the signing keys.
|
||||||
|
func prettyPrintTargets(ts []*notaryclient.Target, writer io.Writer) {
|
||||||
|
if len(ts) == 0 {
|
||||||
|
writer.Write([]byte("No targets present in this repository.\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Stable(targetsSorter(ts))
|
||||||
|
|
||||||
|
table := tablewriter.NewWriter(writer)
|
||||||
|
table.SetHeader([]string{"Name", "Digest", "Size (bytes)"})
|
||||||
|
table.SetBorder(false)
|
||||||
|
table.SetColumnSeparator(" ")
|
||||||
|
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
|
table.SetCenterSeparator("-")
|
||||||
|
table.SetAutoWrapText(false)
|
||||||
|
|
||||||
|
for _, t := range ts {
|
||||||
|
table.Append([]string{
|
||||||
|
t.Name,
|
||||||
|
hex.EncodeToString(t.Hashes["sha256"]),
|
||||||
|
fmt.Sprintf("%d", t.Length),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
table.Render()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue