Skip to content

Commit

Permalink
Merge pull request #43 from CircleCI-Public/help-args
Browse files Browse the repository at this point in the history
Document positional args in help text
  • Loading branch information
marcomorain authored Aug 7, 2018
2 parents ae7158b + 263746b commit 2469a8d
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 167 deletions.
59 changes: 29 additions & 30 deletions .circleci/deploy-gh-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,35 @@ remote=$(git config remote.origin.url)

# make a directory to put the gp-pages branch
mkdir gh-pages-branch
cd gh-pages-branch
# now lets setup a new repo so we can update the gh-pages branch
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
git config --global user.name "$GH_NAME" > /dev/null 2>&1
git init
git remote add --fetch origin "$remote"

# switch into the the gh-pages branch
if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
then
git checkout gh-pages
# delete any old site as we are going to replace it
# Note: this explodes if there aren't any, so moving it here for now
git rm -rf .
else
git checkout --orphan gh-pages
fi

# copy over or recompile the new site
cp -a "../out/." .

# stage any changes and new files
git add -A
# now commit, ignoring branch gh-pages doesn't seem to work, so trying skip
git commit --allow-empty -m "Deploy to GitHub pages [ci skip]"
# and push, but send any output to /dev/null to hide anything sensitive
git push --force --quiet origin gh-pages
# go back to where we started and remove the gh-pages git repo we made and used
# for deployment
cd ..
(
cd gh-pages-branch
# now lets setup a new repo so we can update the gh-pages branch
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
git config --global user.name "$GH_NAME" > /dev/null 2>&1
git init
git remote add --fetch origin "$remote"

# switch into the the gh-pages branch
if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
then
git checkout gh-pages
# delete any old site as we are going to replace it
# Note: this explodes if there aren't any, so moving it here for now
git rm -rf .
else
git checkout --orphan gh-pages
fi

# copy over or recompile the new site
cp -a "../out/." .

# stage any changes and new files
git add -A
# now commit, ignoring branch gh-pages doesn't seem to work, so trying skip
git commit --allow-empty -m "Deploy to GitHub pages [ci skip]"
# and push, but send any output to /dev/null to hide anything sensitive
git push --force --quiet origin gh-pages
)
rm -rf gh-pages-branch

echo "Finished Deployment!"
2 changes: 1 addition & 1 deletion .circleci/generate-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mkdir -p out

# pandoc markdown to html into out dir
for f in docs/*.md; do
pandoc "$f" -s -o "out/$(basename ${f%.md}.html)";
pandoc "$f" -s -o "out/$(basename "${f%.md}".html)";
done

# move index and update links
Expand Down
8 changes: 5 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func OrbQuery(ctx context.Context, logger *logger.Logger, configPath string) (*C

// OrbPublish publishes a new version of an orb
func OrbPublish(ctx context.Context, logger *logger.Logger,
name string, configPath string, orbVersion string) (*PublishOrbResponse, error) {
configPath string, namespace string, orb string, orbVersion string) (*PublishOrbResponse, error) {
name := namespace + "/" + orb
orbID, err := getOrbID(ctx, logger, name)
if err != nil {
return nil, err
Expand Down Expand Up @@ -387,7 +388,7 @@ func createOrbWithNsID(ctx context.Context, logger *logger.Logger, name string,
}

// CreateOrb creates (reserves) an orb within a namespace
func CreateOrb(ctx context.Context, logger *logger.Logger, name string, namespace string) (*CreateOrbResponse, error) {
func CreateOrb(ctx context.Context, logger *logger.Logger, namespace string, name string) (*CreateOrbResponse, error) {
namespaceID, err := getNamespace(ctx, logger, namespace)

if err != nil {
Expand All @@ -399,7 +400,8 @@ func CreateOrb(ctx context.Context, logger *logger.Logger, name string, namespac
}

// OrbSource gets the source or an orb
func OrbSource(ctx context.Context, logger *logger.Logger, name string) (string, error) {
func OrbSource(ctx context.Context, logger *logger.Logger, namespace string, orb string) (string, error) {
name := namespace + "/" + orb

var response struct {
Orb struct {
Expand Down
51 changes: 0 additions & 51 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"path"
"regexp"
"syscall"

"github.com/CircleCI-Public/circleci-cli/settings"
Expand All @@ -16,27 +15,16 @@ import (
)

func newBuildCommand() *cobra.Command {

updateCommand := &cobra.Command{
Use: "update",
Short: "Update the build agent to the latest version",
RunE: updateBuildAgentToLatest,
}

buildCommand := &cobra.Command{
Use: "build",
Short: "Run a build",
RunE: runBuild,
DisableFlagParsing: true,
}

buildCommand.AddCommand(updateCommand)

return buildCommand
}

var picardRepo = "circleci/picard"

func circleCiDir() string {
return path.Join(settings.UserHomeDir(), ".circleci")
}
Expand Down Expand Up @@ -69,45 +57,6 @@ func storeBuildAgentSha(sha256 string) error {
return errors.Wrap(err, "Failed to write build agent settings file")
}

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

latestSha256, err := findLatestPicardSha()

if err != nil {
return err
}

Logger.Infof("Latest build agent is version %s", latestSha256)

return nil
}

func findLatestPicardSha() (string, error) {

outputBytes, err := exec.Command("docker", "pull", picardRepo).CombinedOutput() // #nosec

if err != nil {
return "", errors.Wrap(err, "failed to pull latest docker image")
}

output := string(outputBytes)
sha256 := regexp.MustCompile("(?m)sha256.*$")
latest := sha256.FindString(output)

if latest == "" {
return "", fmt.Errorf("failed to parse sha256 from docker pull output")
}

err = storeBuildAgentSha(latest)

if err != nil {
return "", err
}

return latest, nil

}

func loadCurrentBuildAgentSha() string {
if _, err := os.Stat(buildAgentSettingsPath()); os.IsNotExist(err) {
return ""
Expand Down
45 changes: 27 additions & 18 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,41 @@ import (

const defaultConfigPath = ".circleci/config.yml"

// Path to the config.yml file to operate on.
// Used to for compatibility with `circleci config validate --path`
var configPath string

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

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

validateCommand := &cobra.Command{
Use: "validate [config.yml]",
Use: "validate PATH (use \"-\" for STDIN)",
Aliases: []string{"check"},
Short: "Check that the config file is well formed.",
RunE: validateConfig,
Args: cobra.MaximumNArgs(1),
}
validateCommand.PersistentFlags().StringVarP(&configPath, "config", "c", ".circleci/config.yml", "path to config file (default \".circleci/config.yml\")")
err := validateCommand.PersistentFlags().MarkHidden("config")
if err != nil {
panic(err)
}

expandCommand := &cobra.Command{
Use: "expand [config.yml]",
Use: "expand PATH (use \"-\" for STDIN)",
Short: "Expand the config.",
RunE: expandConfig,
Args: cobra.MaximumNArgs(1),
Args: cobra.ExactArgs(1),
}

configCmd.AddCommand(collapseCommand)
Expand All @@ -47,13 +56,21 @@ func newConfigCommand() *cobra.Command {
return configCmd
}

// The PATH arg is actually optional, in order to support compatibility with the --path flag.
func validateConfig(cmd *cobra.Command, args []string) error {
configPath := defaultConfigPath
path := defaultConfigPath
// First, set the path to configPath set by --path flag for compatibility
if configPath != "" {
path = configPath
}

// Then, if an arg is passed in, choose that instead
if len(args) == 1 {
configPath = args[0]
path = args[0]
}

ctx := context.Background()
response, err := api.ConfigQuery(ctx, Logger, configPath)
response, err := api.ConfigQuery(ctx, Logger, path)

if err != nil {
return err
Expand All @@ -63,17 +80,13 @@ func validateConfig(cmd *cobra.Command, args []string) error {
return response.ToError()
}

Logger.Infof("Config file at %s is valid", configPath)
Logger.Infof("Config file at %s is valid", path)
return nil
}

func expandConfig(cmd *cobra.Command, args []string) error {
ctx := context.Background()
configPath := defaultConfigPath
if len(args) == 1 {
configPath = args[0]
}
response, err := api.ConfigQuery(ctx, Logger, configPath)
response, err := api.ConfigQuery(ctx, Logger, args[0])

if err != nil {
return err
Expand All @@ -88,11 +101,7 @@ 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)
tree, err := filetree.NewTree(args[0])
if err != nil {
return errors.Wrap(err, "An error occurred trying to build the tree")
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ func newNamespaceCommand() *cobra.Command {
}

createCmd := &cobra.Command{
Use: "create [name] [vcs] [org-name]",
Short: "create an namespace",
RunE: createNamespace,
Args: cobra.ExactArgs(3),
Use: "create NAME VCS-TYPE ORG-NAME",
Short: "create a namespace",
RunE: createNamespace,
Args: cobra.ExactArgs(3),
Annotations: make(map[string]string),
}

createCmd.Annotations["VCS-TYPE"] = `Your VCS provider, can be either "github" or "bitbucket"`
createCmd.Annotations["ORG-NAME"] = `The name used for your organization`

// "org-name", "", "organization name (required)"
// "vcs", "github", "organization vcs, e.g. 'github', 'bitbucket'"

Expand Down
Loading

0 comments on commit 2469a8d

Please sign in to comment.