Skip to content

Commit

Permalink
Proxy in-build commands to old CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Aug 10, 2018
1 parent a78fed5 commit 86289a1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/CircleCI-Public/circleci-cli/api"
"github.com/CircleCI-Public/circleci-cli/filetree"
"github.com/CircleCI-Public/circleci-cli/proxy"
"github.com/pkg/errors"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -49,9 +50,19 @@ func newConfigCommand() *cobra.Command {
Args: cobra.ExactArgs(1),
}

migrateCommand := &cobra.Command{
Use: "migrate",
Short: "migrate configuration file to new format",
RunE: migrateConfig,
Hidden: true,
}
migrateCommand.PersistentFlags().StringP("config", "c", ".circleci/config.yml", "path to config file (default \".circleci/config.yml\")")
migrateCommand.PersistentFlags().BoolP("in-place", "i", false, "whether to update file in place. If false, emits to stdout")

configCmd.AddCommand(collapseCommand)
configCmd.AddCommand(validateCommand)
configCmd.AddCommand(expandCommand)
configCmd.AddCommand(migrateCommand)

return configCmd
}
Expand Down Expand Up @@ -113,3 +124,7 @@ func collapseConfig(cmd *cobra.Command, args []string) error {
Logger.Infof("%s\n", string(y))
return nil
}

func migrateConfig(cmd *cobra.Command, args []string) error {
return proxy.Exec("config migrate", args)
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func MakeCommands() *cobra.Command {
rootCmd.AddCommand(newUpdateCommand())
rootCmd.AddCommand(newNamespaceCommand())
rootCmd.AddCommand(newUsageCommand())
rootCmd.AddCommand(newStepCommand())
rootCmd.PersistentFlags().Bool("verbose", false, "Enable verbose logging.")
rootCmd.PersistentFlags().String("endpoint", defaultEndpoint, "the endpoint of your CircleCI GraphQL API")
rootCmd.PersistentFlags().String("token", "", "your token for using CircleCI")
Expand Down
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("Root", func() {

It("can create commands", func() {
commands := cmd.MakeCommands()
Expect(len(commands.Commands())).To(Equal(11))
Expect(len(commands.Commands())).To(Equal(12))
})

})
Expand Down
29 changes: 29 additions & 0 deletions cmd/step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/CircleCI-Public/circleci-cli/proxy"
"github.com/spf13/cobra"
)

func newStepCommand() *cobra.Command {
stepCmd := &cobra.Command{
Use: "step",
Short: "Execute steps",
Hidden: true,
}

haltCmd := &cobra.Command{
Use: "halt",
Short: "halt current task and treat as a successful",
RunE: haltRunE,
Hidden: true,
}

stepCmd.AddCommand(haltCmd)

return stepCmd
}

func haltRunE(cmd *cobra.Command, args []string) error {
return proxy.Exec("step halt", args)
}
19 changes: 19 additions & 0 deletions cmd/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"github.com/CircleCI-Public/circleci-cli/proxy"
"github.com/bmatcuk/doublestar"
"github.com/spf13/cobra"
)
Expand All @@ -22,7 +23,21 @@ func newTestsCommand() *cobra.Command {
Hidden: true,
}

splitCmd := &cobra.Command{
Use: "split",
Short: "return a split batch of provided files",
RunE: splitRunE,
Hidden: true,
}
splitCmd.Flags().Uint("index", 0, "index of node.")
splitCmd.Flags().Uint("total", 1, "number of nodes.")
splitCmd.Flags().String("split-by", "name", `how to weight the split, allowed values are "name", "filesize", and "timings".`)
splitCmd.Flags().String("timings-type", "filename", `lookup historical timing data by: "classname", "filename", or "testname".`)
splitCmd.Flags().Bool("show-counts", false, `print test file or test class counts to stderr (default false).`)
splitCmd.Flags().String("timings-file", "", "JSON file containing historical timing data.")

testsCmd.AddCommand(globCmd)
testsCmd.AddCommand(splitCmd)

return testsCmd
}
Expand Down Expand Up @@ -54,3 +69,7 @@ func globRun(cmd *cobra.Command, args []string) {
fmt.Println(filename)
}
}

func splitRunE(cmd *cobra.Command, args []string) error {
return proxy.Exec("tests split", args)
}
19 changes: 19 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package proxy

import (
"os"
"os/exec"
"syscall"

"github.com/pkg/errors"
)

func Exec(command string, args []string) error {
agent, err := exec.LookPath("picard")
if err != nil {
return errors.Wrap(err, "Could not find `picard` executable on $PATH; please ensure that build-agent is installed")
}

err = syscall.Exec(agent, args, os.Environ()) // #nosec
return errors.Wrap(err, "failed to execute picard command")
}

0 comments on commit 86289a1

Please sign in to comment.