From 6c6e641afbefece0ea9130769776fe0f3ee6db2f Mon Sep 17 00:00:00 2001 From: Lennard Eijsackers Date: Thu, 26 Nov 2020 21:06:13 +0100 Subject: [PATCH] Extend the pull command with a policy flag to specify the download location of the policies Signed-off-by: Lennard Eijsackers --- README.md | 6 ++++++ internal/commands/pull.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a1442b..0f7e09c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ To download a policy, use the `pull` command: > policy-hub pull konstraint ``` +which will download the `konstraint` policies into a folder called `konstraint`. To overwrite the location where the policies will be downloaded too, you can specify the `--policy` flag, e.g. + +```bash +> policy-hub pull konstraint --policy policy +``` + ## Make your policies discoverable Do you have policies that the community could benefit from too? diff --git a/internal/commands/pull.go b/internal/commands/pull.go index 434970b..b41e0cc 100644 --- a/internal/commands/pull.go +++ b/internal/commands/pull.go @@ -22,12 +22,13 @@ func newPullCommand() *cobra.Command { } cmd.Flags().StringVarP(&c.Repository, "repository", "r", helpers.DefaultMetaDataFile(), "Location of the repository to search.") - + cmd.Flags().StringVarP(&c.PolicyDir, "policy", "p", "", "Folder where the policies will be downloaded too") return cmd } type pullConfig struct { Repository string + PolicyDir string } func (c *pullConfig) run(name string) error { @@ -47,7 +48,12 @@ func (c *pullConfig) run(name string) error { return fmt.Errorf("could not find a name match in given repository") } - err = downloader.Download(context.Background(), name, []string{urlPath}) + policyDir := name + if c.PolicyDir != "" { + policyDir = c.PolicyDir + } + + err = downloader.Download(context.Background(), policyDir, []string{urlPath}) return nil }