Add --long flag

parent a29ea590
......@@ -14,7 +14,7 @@ install: bin/$(BIN)
cp bin/$(BIN) $(GOPATH)/bin/
test:
go test -v ./...
go test -v ./... -cover
.PHONY: clean
.PHONY: all
......
......@@ -3,7 +3,6 @@ package cmd
import (
"context"
"fmt"
"net/url"
"github.com/spf13/cobra"
"gitlab.com/zerok/container-inventory/pkg/registryclient"
......@@ -38,56 +37,15 @@ var reposListCmd = &cobra.Command{
logger.Fatal().Err(err).Msg("Failed to retrieve repository list")
}
for _, r := range repos {
fmt.Println(r)
}
},
}
type Repo struct {
Registry string
Name string
}
func parseRepository(rep string) (*Repo, error) {
u, err := url.Parse("https://" + rep)
if err != nil {
return nil, err
}
return &Repo{
Registry: u.Host,
Name: u.Path,
}, nil
}
var reposCopyCmd = &cobra.Command{
Use: "copy",
Aliases: []string{"cp"},
Run: func(cmd *cobra.Command, args []string) {
ctx := logger.WithContext(context.Background())
if len(args) < 2 {
logger.Fatal().Msg("You have to specify at least one source and one target repository")
}
src := args[0]
targets := args[1:]
srcRepo, err := parseRepository(src)
if err != nil {
logger.Fatal().Err(err).Msg("Failed to parse source repository")
}
for _, t := range targets {
if _, err := parseRepository(t); err != nil {
logger.Fatal().Err(err).Msgf("Failed to parse target repository '%s'", t)
if longNames {
r = fmt.Sprintf("%s/%s", registry, r)
}
fmt.Println(r)
}
srcReg := registryclient.NewClient(registryclient.WithHost(srcRepo.Registry))
srcReg.ListTags(ctx, srcRepo.Name)
},
}
func init() {
reposCmd.AddCommand(reposListCmd)
reposCmd.AddCommand(reposCopyCmd)
rootCmd.AddCommand(reposCmd)
}
......@@ -16,6 +16,7 @@ var registry string
var repository string
var verbose bool
var sessions *sessionfile.Manager
var longNames bool
func showSubcommandsList(cmd *cobra.Command) {
fmt.Println("Please use one of the following sub-commands:")
......@@ -48,6 +49,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&registry, "registry", "r", "", "Registry host")
rootCmd.PersistentFlags().StringVarP(&repository, "repository", "i", "", "Repository name")
rootCmd.PersistentFlags().StringVarP(&sessionName, "session", "s", "", "Session name")
rootCmd.PersistentFlags().BoolVarP(&longNames, "long", "l", false, "Display long names of tags and repositories including the registry path")
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Verbose logging")
}
......
......@@ -34,6 +34,9 @@ var listTagsCmd = &cobra.Command{
logger.Fatal().Err(err).Msgf("Failed to retrieve tags for %s", repository)
}
for _, tag := range tags {
if longNames {
tag = fmt.Sprintf("%s/%s:%s", registry, repository, tag)
}
if withDigest {
m, err := c.GetManifest(ctx, repository, tag)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment