-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from CircleCI-Public/proxy
Proxy in-build commands to old CLI
- Loading branch information
Showing
6 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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, | ||
DisableFlagParsing: true, | ||
} | ||
|
||
haltCmd := &cobra.Command{ | ||
Use: "halt", | ||
Short: "Halt the current job and treat it as successful", | ||
RunE: haltRunE, | ||
Hidden: true, | ||
DisableFlagParsing: true, | ||
} | ||
|
||
stepCmd.AddCommand(haltCmd) | ||
|
||
return stepCmd | ||
} | ||
|
||
func haltRunE(cmd *cobra.Command, args []string) error { | ||
return proxy.Exec([]string{"step", "halt"}, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package proxy | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// Exec will invoke the given command and proxy any arguments for backwards compatibility. | ||
func Exec(command []string, args []string) error { | ||
agent, err := exec.LookPath("circleci-agent") | ||
if err != nil { | ||
return errors.Wrap(err, "Please ensure that circleci-agent is installed, expected this to be called inside a job") | ||
} | ||
|
||
arguments := append([]string{agent}, command...) | ||
arguments = append(arguments, args...) | ||
|
||
err = syscall.Exec(agent, arguments, os.Environ()) // #nosec | ||
return errors.Wrapf(err, "failed to proxy command %s, expected this to be called inside a job", command) | ||
} |