diff --git a/cmd/add.go b/cmd/add.go index d2447fb..03357b6 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -73,8 +73,7 @@ var addCmd = &cobra.Command{ } if dryRun { - cmd.Print(helpers.Header(fmt.Sprintf("%s:", hostsFilePath), "")) - cmd.Print(hosts) + cmd.Print(helpers.PrintFile(hostsFilePath, hosts)) } sshConfigPath, _ := cmd.PersistentFlags().GetString("ssh-config") @@ -102,8 +101,7 @@ var addCmd = &cobra.Command{ } if dryRun { - cmd.Print(helpers.Header(fmt.Sprintf("%s:", sshConfigPath), "\n--\n")) - cmd.Print(sshConfig) + cmd.Print(helpers.PrintFileWithSpacer(sshConfigPath, sshConfig)) } }, } diff --git a/cmd/print.go b/cmd/print.go index a74d5a3..7c66a41 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -62,8 +62,7 @@ func Print(cmd *cobra.Command, args []string) { os.Exit(1) } - cmd.Print(helpers.Header(fmt.Sprintf("%s:", hostsFilePath), "")) - cmd.Print(hosts) + cmd.Print(helpers.PrintFile(hostsFilePath, hosts)) sshConfigPath, _ := cmd.Flags().GetString("ssh-config") if sshConfigPath == "" { @@ -82,6 +81,5 @@ func Print(cmd *cobra.Command, args []string) { os.Exit(1) } - cmd.Print(helpers.Header(fmt.Sprintf("%s:", sshConfigPath), "\n--\n")) - cmd.Print(sshConfig) + cmd.Print(helpers.PrintFileWithSpacer(hostsFilePath, sshConfig)) } diff --git a/cmd/rm.go b/cmd/rm.go index b5d7a1f..18fd9ca 100644 --- a/cmd/rm.go +++ b/cmd/rm.go @@ -67,8 +67,7 @@ var rmCmd = &cobra.Command{ } if dryRun { - cmd.Print(helpers.Header(fmt.Sprintf("%s:", hostsFilePath), "")) - cmd.Print(hosts) + cmd.Print(helpers.PrintFile(hostsFilePath, hosts)) } sshConfigPath, _ := cmd.Flags().GetString("ssh-config") @@ -95,8 +94,7 @@ var rmCmd = &cobra.Command{ } if dryRun { - cmd.Print(helpers.Header(fmt.Sprintf("%s:", sshConfigPath), "\n--\n")) - cmd.Print(sshConfig) + cmd.Print(helpers.PrintFileWithSpacer(sshConfigPath, sshConfig)) } }, } diff --git a/internal/helpers/print.go b/internal/helpers/print.go index f5df1af..ae42331 100644 --- a/internal/helpers/print.go +++ b/internal/helpers/print.go @@ -1,5 +1,17 @@ package helpers -func Header(heading string, spacer string) string { - return spacer + heading + "\n" +import "fmt" + +func PrintFile(filename string, file interface{}) (output string) { + output = filename + "\n" + output = output + fmt.Sprint(file) + + return +} + +func PrintFileWithSpacer(filename string, file interface{}) (output string) { + output = "\n--\n" + filename + ":\n" + output = output + fmt.Sprint(file) + + return }