This change adds two new (hidden) CLI commands: * `gen-bash-completion`: This command generates a bash completion script for the CLI, storing it in the file specified by the 1st arg. This fixes pulumi/pulumi#1172. * `gen-markdown`: This command generates a directory of Markdown files, one per command, documenting the CLI commands and their usage. I originally did these as separate scripts that we can use in our build processes, but it was actually even easier to make `pulumi` able to generate them for itself. The nice part about this is that we don't even need to bundle additional assets in order to distribute e.g. the bash completion scripts, we can simply tell people to run $ pulumi gen-bash-completion /etc/bash_completion.d/pulumi This can also be used in our upcoming Brew installer.
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/pulumi/pulumi/pkg/util/archive"
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
// newArchiveCommand creates a command which just builds the archive we would ship to Pulumi.com to
|
|
// do a deployment.
|
|
func newArchiveCommand() *cobra.Command {
|
|
var forceNoDefaultIgnores bool
|
|
var forceDefaultIgnores bool
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "archive <path-to-archive>",
|
|
Short: "create an archive suitable for deployment",
|
|
Args: cmdutil.SpecificArgs([]string{"path-to-archive"}),
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
|
if forceDefaultIgnores && forceNoDefaultIgnores {
|
|
return errors.New("can't specify --no-default-ignores and --default-ignores at the same time")
|
|
}
|
|
|
|
proj, path, err := workspace.DetectProjectAndPath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
useDeafultIgnores := proj.UseDefaultIgnores()
|
|
|
|
if forceDefaultIgnores {
|
|
useDeafultIgnores = true
|
|
} else if forceNoDefaultIgnores {
|
|
useDeafultIgnores = false
|
|
}
|
|
|
|
// path is the path to the Pulumi.yaml file. Need its parent directory.
|
|
dir := filepath.Dir(path)
|
|
archiveContents, err := archive.Process(dir, useDeafultIgnores)
|
|
if err != nil {
|
|
return errors.Wrap(err, "creating archive")
|
|
}
|
|
|
|
return ioutil.WriteFile(args[0], archiveContents.Bytes(), 0644)
|
|
}),
|
|
}
|
|
cmd.PersistentFlags().BoolVar(
|
|
&forceNoDefaultIgnores, "--no-default-ignores", false,
|
|
"Do not use default ignores, regardless of Pulumi.yaml")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&forceDefaultIgnores, "--default-ignores", false,
|
|
"Use default ignores, regardless of Pulumi.yaml")
|
|
|
|
return cmd
|
|
}
|