diff --git a/cmd/reconf.go b/cmd/reconf.go index 6afe1e6..d6aac7d 100644 --- a/cmd/reconf.go +++ b/cmd/reconf.go @@ -17,10 +17,13 @@ which is a filename. In case of any errors, the preexisting file won't be touche initConfig() }, Run: func(cmd *cobra.Command, args []string) { - lib.Reconf(viper.GetStringSlice("profiles"), args[0]) + lib.Reconf(viper.GetStringSlice("profiles"), args[0], viper.GetBool("no-profile-prefix")) }, } func init() { + reconfCmd.Flags().BoolP("no-profile-prefix", "n", false, "Do not prefix host names with profile name") + + viper.BindPFlag("no-profile-prefix", reconfCmd.Flags().Lookup("no-profile-prefix")) rootCmd.AddCommand(reconfCmd) } diff --git a/lib/reconf.go b/lib/reconf.go index 62901e7..0435691 100644 --- a/lib/reconf.go +++ b/lib/reconf.go @@ -55,7 +55,7 @@ func instanceNameSorter(i interface{}) interface{} { // sort by instance name } // Reconf writes ssh config with profiles into the specified file -func Reconf(profiles []string, filename string) { +func Reconf(profiles []string, filename string, noProfilePrefix bool) { profileSummaries, err := TraverseProfiles(profiles) if err != nil { log.WithError(err).Error("got some errors") @@ -125,6 +125,9 @@ func Reconf(profiles []string, filename string) { Name: getInstanceCanonicalName(summary.Name, instanceName, instanceIndex), Profile: summary.Name, } + if noProfilePrefix { + entry.Name = getInstanceCanonicalName("", instanceName, instanceIndex) + } // first try to find a bastion from this vpc bastion := findBestBastion(instanceName, vpcBastions)