Skip to content

Commit

Permalink
added path variable to content pull, content push and content clean c…
Browse files Browse the repository at this point in the history
…ommand
  • Loading branch information
dominik-przybyl-wttech committed Mar 21, 2024
1 parent 4ae2f94 commit f835b34
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cmd/aem/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/wttech/aemc/pkg"
"github.com/wttech/aemc/pkg/common/pathx"
"github.com/wttech/aemc/pkg/content"
"strings"
)
Expand Down Expand Up @@ -55,7 +56,8 @@ func (c *CLI) contentCleanCmd() *cobra.Command {
}
cmd.Flags().StringP("dir", "d", "", "JCR root path")
cmd.Flags().StringP("file", "f", "", "Local file path")
cmd.MarkFlagsOneRequired("dir", "file")
cmd.Flags().String("path", "", "JCR root path or local file path")
cmd.MarkFlagsOneRequired("dir", "file", "path")
return cmd
}

Expand Down Expand Up @@ -144,7 +146,8 @@ func (c *CLI) contentPullCmd() *cobra.Command {
}
cmd.Flags().StringP("dir", "d", "", "JCR root path")
cmd.Flags().String("file", "", "Local file path")
cmd.MarkFlagsMutuallyExclusive("dir", "file")
cmd.Flags().String("path", "", "JCR root path or local file path")
cmd.MarkFlagsMutuallyExclusive("dir", "file", "path")
cmd.Flags().StringSliceP("filter-roots", "r", []string{}, "Vault filter root paths")
cmd.Flags().StringP("filter-file", "f", "", "Vault filter file path")
cmd.MarkFlagsMutuallyExclusive("filter-roots", "filter-file")
Expand Down Expand Up @@ -199,7 +202,8 @@ func (c *CLI) contentPushCmd() *cobra.Command {
}
cmd.Flags().StringP("dir", "d", "", "JCR root path")
cmd.Flags().StringP("file", "f", "", "Local file path")
cmd.MarkFlagsOneRequired("dir", "file")
cmd.Flags().String("path", "", "JCR root path or local file path")
cmd.MarkFlagsOneRequired("dir", "file", "path")
cmd.Flags().Bool("clean", false, "Normalize content while pushing")
return cmd
}
Expand Down Expand Up @@ -264,6 +268,16 @@ func determineContentDir(cmd *cobra.Command) (string, error) {
if dir != "" && !strings.Contains(dir, content.JCRRoot) {
return "", fmt.Errorf("content dir '%s' does not contain '%s'", dir, content.JCRRoot)
}
path, _ := cmd.Flags().GetString("path")
if path != "" && !strings.Contains(path, content.JCRRoot) {
return "", fmt.Errorf("content path '%s' does not contain '%s'", path, content.JCRRoot)
}
if path != "" && !pathx.Exists(path) {
return "", fmt.Errorf("content path does not exist: %s", path)
}
if path != "" && pathx.IsDir(path) {
return path, nil
}
return dir, nil
}

Expand All @@ -272,5 +286,15 @@ func determineContentFile(cmd *cobra.Command) (string, error) {
if file != "" && !strings.Contains(file, content.JCRRoot) {
return "", fmt.Errorf("content file '%s' does not contain '%s'", file, content.JCRRoot)
}
path, _ := cmd.Flags().GetString("path")
if path != "" && !strings.Contains(path, content.JCRRoot) {
return "", fmt.Errorf("content path '%s' does not contain '%s'", path, content.JCRRoot)
}
if path != "" && !pathx.Exists(path) {
return "", fmt.Errorf("content path does not exist: %s", path)
}
if path != "" && pathx.IsFile(path) {
return path, nil
}
return file, nil
}

0 comments on commit f835b34

Please sign in to comment.