Skip to content

Commit

Permalink
Replace Command with Cmd in internal structure names
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 28, 2019
1 parent 4dee096 commit 13f5d47
Show file tree
Hide file tree
Showing 35 changed files with 192 additions and 192 deletions.
12 changes: 6 additions & 6 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var addCommand = &cobra.Command{
var addCmd = &cobra.Command{
Use: "add targets...",
Args: cobra.MinimumNArgs(1),
Short: "Add an existing file, directory, or symlink to the source state",
RunE: makeRunE(config.runAddCommand),
RunE: makeRunE(config.runAddCmd),
}

type addCommandConfig struct {
type addCmdConfig struct {
recursive bool
prompt bool
options chezmoi.AddOptions
}

func init() {
rootCommand.AddCommand(addCommand)
rootCmd.AddCommand(addCmd)

persistentFlags := addCommand.PersistentFlags()
persistentFlags := addCmd.PersistentFlags()
persistentFlags.BoolVarP(&config.add.options.Empty, "empty", "e", false, "add empty files")
persistentFlags.BoolVarP(&config.add.options.Exact, "exact", "x", false, "add directories exactly")
persistentFlags.BoolVarP(&config.add.prompt, "prompt", "p", false, "prompt before adding")
persistentFlags.BoolVarP(&config.add.recursive, "recursive", "r", false, "recurse in to subdirectories")
persistentFlags.BoolVarP(&config.add.options.Template, "template", "T", false, "add files as templates")
}

func (c *Config) runAddCommand(fs vfs.FS, args []string) (err error) {
func (c *Config) runAddCmd(fs vfs.FS, args []string) (err error) {
ts, err := c.getTargetState(fs)
if err != nil {
return err
Expand Down
28 changes: 14 additions & 14 deletions cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestAddAfterModification(t *testing.T) {
t.Fatalf("vfst.NewTestFS(_) == _, _, %v, want _, _, <nil>", err)
}
args := []string{"/home/user/.bashrc"}
if err := c.runAddCommand(fs, args); err != nil {
t.Errorf("c.runAddCommand(fs, nil, %+v) == %v, want <nil>", args, err)
if err := c.runAddCmd(fs, args); err != nil {
t.Errorf("c.runAddCmd(fs, nil, %+v) == %v, want <nil>", args, err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi/dot_bashrc",
Expand All @@ -37,8 +37,8 @@ func TestAddAfterModification(t *testing.T) {
if err := fs.WriteFile("/home/user/.bashrc", []byte("# new contents of .bashrc\n"), 0644); err != nil {
t.Errorf("fs.WriteFile(...) == %v, want <nil>", err)
}
if err := c.runAddCommand(fs, args); err != nil {
t.Errorf("c.runAddCommand(fs, nil, %+v) == %v, want <nil>", args, err)
if err := c.runAddCmd(fs, args); err != nil {
t.Errorf("c.runAddCmd(fs, nil, %+v) == %v, want <nil>", args, err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi/dot_bashrc",
Expand All @@ -52,7 +52,7 @@ func TestAddCommand(t *testing.T) {
for _, tc := range []struct {
name string
args []string
add addCommandConfig
add addCmdConfig
root interface{}
tests interface{}
}{
Expand All @@ -76,7 +76,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_template",
args: []string{"/home/user/.gitconfig"},
add: addCommandConfig{
add: addCmdConfig{
options: chezmoi.AddOptions{
Template: true,
},
Expand All @@ -96,7 +96,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_recursive",
args: []string{"/home/user/.config"},
add: addCommandConfig{
add: addCmdConfig{
recursive: true,
},
root: map[string]interface{}{
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_exact_dir",
args: []string{"/home/user/dir"},
add: addCommandConfig{
add: addCmdConfig{
options: chezmoi.AddOptions{
Exact: true,
},
Expand All @@ -148,7 +148,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_exact_dir_recursive",
args: []string{"/home/user/dir"},
add: addCommandConfig{
add: addCmdConfig{
recursive: true,
options: chezmoi.AddOptions{
Exact: true,
Expand All @@ -174,7 +174,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_empty_file",
args: []string{"/home/user/empty"},
add: addCommandConfig{
add: addCmdConfig{
options: chezmoi.AddOptions{
Empty: true,
},
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestAddCommand(t *testing.T) {
{
name: "add_symlink_in_dir_recursive",
args: []string{"/home/user/foo"},
add: addCommandConfig{
add: addCmdConfig{
recursive: true,
},
root: map[string]interface{}{
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestAddCommand(t *testing.T) {
{
name: "dont_add_ignored_file_recursive",
args: []string{"/home/user/foo"},
add: addCommandConfig{
add: addCmdConfig{
recursive: true,
},
root: map[string]interface{}{
Expand Down Expand Up @@ -318,8 +318,8 @@ func TestAddCommand(t *testing.T) {
if err != nil {
t.Fatalf("vfst.NewTestFS(_) == _, _, %v, want _, _, <nil>", err)
}
if err := c.runAddCommand(fs, tc.args); err != nil {
t.Errorf("c.runAddCommand(fs, nil, %+v) == %v, want <nil>", tc.args, err)
if err := c.runAddCmd(fs, tc.args); err != nil {
t.Errorf("c.runAddCmd(fs, nil, %+v) == %v, want <nil>", tc.args, err)
}
vfst.RunTests(t, fs, "", tc.tests)
})
Expand Down
8 changes: 4 additions & 4 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var applyCommand = &cobra.Command{
var applyCmd = &cobra.Command{
Use: "apply [targets...]",
Short: "Update the destination directory to match the target state",
RunE: makeRunE(config.runApplyCommand),
RunE: makeRunE(config.runApplyCmd),
}

func init() {
rootCommand.AddCommand(applyCommand)
rootCmd.AddCommand(applyCmd)
}

func (c *Config) runApplyCommand(fs vfs.FS, args []string) error {
func (c *Config) runApplyCmd(fs vfs.FS, args []string) error {
mutator := c.getDefaultMutator(fs)
return c.applyArgs(fs, args, mutator)
}
8 changes: 4 additions & 4 deletions cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var archiveCommand = &cobra.Command{
var archiveCmd = &cobra.Command{
Use: "archive",
Args: cobra.NoArgs,
Short: "Write a tar archive of the target state to stdout",
RunE: makeRunE(config.runArchiveCommand),
RunE: makeRunE(config.runArchiveCmd),
}

func init() {
rootCommand.AddCommand(archiveCommand)
rootCmd.AddCommand(archiveCmd)
}

func (c *Config) runArchiveCommand(fs vfs.FS, args []string) error {
func (c *Config) runArchiveCmd(fs vfs.FS, args []string) error {
ts, err := c.getTargetState(fs)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var catCommand = &cobra.Command{
var catCmd = &cobra.Command{
Use: "cat targets...",
Args: cobra.MinimumNArgs(1),
Short: "Write the target state of a file or symlink to stdout",
RunE: makeRunE(config.runCatCommand),
RunE: makeRunE(config.runCatCmd),
}

func init() {
rootCommand.AddCommand(catCommand)
rootCmd.AddCommand(catCmd)
}

func (c *Config) runCatCommand(fs vfs.FS, args []string) error {
func (c *Config) runCatCmd(fs vfs.FS, args []string) error {
ts, err := c.getTargetState(fs)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var cdCommand = &cobra.Command{
var cdCmd = &cobra.Command{
Use: "cd",
Args: cobra.NoArgs,
Short: "Launch a shell in the source directory",
RunE: makeRunE(config.runCDCommand),
RunE: makeRunE(config.runCDCmd),
}

func init() {
rootCommand.AddCommand(cdCommand)
rootCmd.AddCommand(cdCmd)
}

func (c *Config) runCDCommand(fs vfs.FS, args []string) error {
func (c *Config) runCDCmd(fs vfs.FS, args []string) error {
mutator := c.getDefaultMutator(fs)
if err := c.ensureSourceDirectory(fs, mutator); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions cmd/chattr.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
vfs "github.com/twpayne/go-vfs"
)

var chattrCommand = &cobra.Command{
var chattrCmd = &cobra.Command{
Use: "chattr attributes targets...",
Args: cobra.MinimumNArgs(2),
Short: "Change the attributes of a target in the source state",
RunE: makeRunE(config.runChattrCommand),
RunE: makeRunE(config.runChattrCmd),
}

type boolModifier int
Expand All @@ -30,10 +30,10 @@ type attributeModifiers struct {
}

func init() {
rootCommand.AddCommand(chattrCommand)
rootCmd.AddCommand(chattrCmd)
}

func (c *Config) runChattrCommand(fs vfs.FS, args []string) error {
func (c *Config) runChattrCmd(fs vfs.FS, args []string) error {
ams, err := parseAttributeModifiers(args[0])
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/chattr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ func TestChattrCommand(t *testing.T) {
t.Fatalf("vfst.NewTestFS(_) == _, _, %v, want _, _, <nil>", err)
}
defer cleanup()
if err := c.runChattrCommand(fs, tc.args); err != nil {
t.Errorf("c.runChattrCommand(fs, nil, %+v) == %v, want <nil>", tc.args, err)
if err := c.runChattrCmd(fs, tc.args); err != nil {
t.Errorf("c.runChattrCmd(fs, nil, %+v) == %v, want <nil>", tc.args, err)
}
vfst.RunTests(t, fs, "", tc.tests)
})
Expand Down
24 changes: 12 additions & 12 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestExercise(t *testing.T) {

// chezmoi add ~/.bashrc
t.Run("chezmoi_add_bashrc", func(t *testing.T) {
if err := c.runAddCommand(fs, []string{"/home/user/.bashrc"}); err != nil {
t.Errorf("c.runAddCommand(...) == %v, want <nil>", err)
if err := c.runAddCmd(fs, []string{"/home/user/.bashrc"}); err != nil {
t.Errorf("c.runAddCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi",
Expand All @@ -50,8 +50,8 @@ func TestExercise(t *testing.T) {

// chezmoi forget ~/.bashrc
t.Run("chezmoi_forget_bashrc", func(t *testing.T) {
if err := c.runForgetCommand(fs, []string{"/home/user/.bashrc"}); err != nil {
t.Errorf("c.runForgetCommand(...) == %v, want <nil>", err)
if err := c.runForgetCmd(fs, []string{"/home/user/.bashrc"}); err != nil {
t.Errorf("c.runForgetCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi/dot_bashrc",
Expand All @@ -63,8 +63,8 @@ func TestExercise(t *testing.T) {
// chezmoi add ~/.netrc
t.Run("chezmoi_add_netrc", func(t *testing.T) {
mustWriteFile("/home/user/.netrc", "# contents of .netrc\n", 0600)
if err := c.runAddCommand(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runAddCommand(...) == %v, want <nil>", err)
if err := c.runAddCmd(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runAddCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi/private_dot_netrc",
Expand All @@ -77,8 +77,8 @@ func TestExercise(t *testing.T) {

// chezmoi chattr -- -private,+empty ~/.netrc
t.Run("chezmoi_chattr_netrc", func(t *testing.T) {
if err := c.runChattrCommand(fs, []string{"-private,+empty", "/home/user/.netrc"}); err != nil {
t.Errorf("c.runChattrCommand(...) == %v, want <nil>", err)
if err := c.runChattrCmd(fs, []string{"-private,+empty", "/home/user/.netrc"}); err != nil {
t.Errorf("c.runChattrCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.chezmoi/empty_dot_netrc",
Expand All @@ -91,8 +91,8 @@ func TestExercise(t *testing.T) {

// chezmoi apply ~/.netrc
t.Run("chezmoi_apply_netrc", func(t *testing.T) {
if err := c.runApplyCommand(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runApplyCommand(...) == %v, want <nil>", err)
if err := c.runApplyCmd(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runApplyCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.netrc",
Expand All @@ -105,8 +105,8 @@ func TestExercise(t *testing.T) {

// chezmoi remove ~/.netrc
t.Run("chezmoi_remove_netrc", func(t *testing.T) {
if err := c.runRemoveCommand(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runRemoveCommand(...) == %v, want <nil>", err)
if err := c.runRemoveCmd(fs, []string{"/home/user/.netrc"}); err != nil {
t.Errorf("c.runRemoveCmd(...) == %v, want <nil>", err)
}
vfst.RunTests(t, fs, "",
vfst.TestPath("/home/user/.netrc",
Expand Down
32 changes: 16 additions & 16 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ type Config struct {
DryRun bool
Verbose bool
SourceVCS sourceVCSConfig
Bitwarden bitwardenCommandConfig
GenericSecret genericSecretCommandConfig
LastPass lastpassCommandConfig
OnePassword onepasswordCommandConfig
Vault vaultCommandConfig
Pass passCommandConfig
Bitwarden bitwardenCmdConfig
GenericSecret genericSecretCmdConfig
Lastpass lastpassCmdConfig
OnePassword onepasswordCmdConfig
Vault vaultCmdConfig
Pass passCmdConfig
Data map[string]interface{}
templateFuncs template.FuncMap
add addCommandConfig
data dataCommandConfig
dump dumpCommandConfig
edit editCommandConfig
init initCommandConfig
_import importCommandConfig
keyring keyringCommandConfig
update updateCommandConfig
add addCmdConfig
data dataCmdConfig
dump dumpCmdConfig
edit editCmdConfig
init initCmdConfig
_import importCmdConfig
keyring keyringCmdConfig
update updateCmdConfig
}

var (
Expand Down Expand Up @@ -321,9 +321,9 @@ func isWellKnownAbbreviation(word string) bool {
return ok
}

func makeRunE(runCommand func(vfs.FS, []string) error) func(*cobra.Command, []string) error {
func makeRunE(runCmd func(vfs.FS, []string) error) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
return runCommand(vfs.OSFS, args)
return runCmd(vfs.OSFS, args)
}
}

Expand Down
Loading

0 comments on commit 13f5d47

Please sign in to comment.