Skip to content

Commit

Permalink
Add option to not prefix host name with profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored and ekini committed Jul 5, 2020
1 parent 34ede85 commit 3e0de4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/reconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion lib/reconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3e0de4b

Please sign in to comment.