Skip to content

Commit

Permalink
config collapse command should use positional argument for path
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Jul 31, 2018
1 parent 57ad820 commit d99aa3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ import (

const defaultConfigPath = ".circleci/config.yml"

var root string

func newConfigCommand() *cobra.Command {
configCmd := &cobra.Command{
Use: "config",
Short: "Operate on build config files",
}

collapseCommand := &cobra.Command{
Use: "collapse",
Use: "collapse [path]",
Short: "Collapse your CircleCI configuration to a single file",
RunE: collapseConfig,
Args: cobra.MaximumNArgs(1),
}
collapseCommand.Flags().StringVarP(&root, "root", "r", ".", "path to your configuration (default is current path)")

validateCommand := &cobra.Command{
Use: "validate [config.yml]",
Expand All @@ -50,7 +48,6 @@ func newConfigCommand() *cobra.Command {
}

func validateConfig(cmd *cobra.Command, args []string) error {

configPath := defaultConfigPath
if len(args) == 1 {
configPath = args[0]
Expand Down Expand Up @@ -91,6 +88,10 @@ func expandConfig(cmd *cobra.Command, args []string) error {
}

func collapseConfig(cmd *cobra.Command, args []string) error {
root := "."
if len(args) > 0 {
root = args[0]
}
tree, err := filetree.NewTree(root)
if err != nil {
return errors.Wrap(err, "An error occurred trying to build the tree")
Expand Down
8 changes: 4 additions & 4 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ var _ = Describe("Config", func() {
Describe("a .circleci folder with config.yml and local orbs folder containing the hugo orb", func() {
BeforeEach(func() {
var err error
command = exec.Command(pathCLI, "config", "collapse", "-r", "testdata/hugo-collapse/.circleci")
command = exec.Command(pathCLI, "config", "collapse", "testdata/hugo-collapse/.circleci")
results, err = ioutil.ReadFile("testdata/hugo-collapse/result.yml")
Expect(err).ShouldNot(HaveOccurred())
})
Expand All @@ -236,7 +236,7 @@ var _ = Describe("Config", func() {
BeforeEach(func() {
var err error
var path string = "nested-orbs-and-local-commands-etc"
command = exec.Command(pathCLI, "config", "collapse", "-r", filepath.Join("testdata", path, "test"))
command = exec.Command(pathCLI, "config", "collapse", filepath.Join("testdata", path, "test"))
results, err = ioutil.ReadFile(filepath.Join("testdata", path, "result.yml"))
Expect(err).ShouldNot(HaveOccurred())
})
Expand All @@ -254,7 +254,7 @@ var _ = Describe("Config", func() {
Describe("an orb containing local executors and commands in folder", func() {
BeforeEach(func() {
var err error
command = exec.Command(pathCLI, "config", "collapse", "-r", "testdata/myorb/test")
command = exec.Command(pathCLI, "config", "collapse", "testdata/myorb/test")
results, err = ioutil.ReadFile("testdata/myorb/result.yml")
Expect(err).ShouldNot(HaveOccurred())
})
Expand All @@ -273,7 +273,7 @@ var _ = Describe("Config", func() {
BeforeEach(func() {
var err error
var path string = "test-with-large-nested-rails-orb"
command = exec.Command(pathCLI, "config", "collapse", "-r", filepath.Join("testdata", path, "test"))
command = exec.Command(pathCLI, "config", "collapse", filepath.Join("testdata", path, "test"))
results, err = ioutil.ReadFile(filepath.Join("testdata", path, "result.yml"))
Expect(err).ShouldNot(HaveOccurred())
})
Expand Down

0 comments on commit d99aa3d

Please sign in to comment.