diff --git a/.gitignore b/.gitignore index 0eefb11..947a183 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ *.swp *~ *.un~ + +.idea \ No newline at end of file diff --git a/cmd/start_alias.go b/cmd/start_alias.go index 5e6610b..abbc7b1 100644 --- a/cmd/start_alias.go +++ b/cmd/start_alias.go @@ -21,6 +21,11 @@ The flags provided through this command can be used to override the one with the same name stored in the alias. `, Args: func(cmd *cobra.Command, args []string) error { + // for the child process when the `--detached` flag is used. + if conf.Id != "" { + aliasName = conf.Id + return nil + } if len(args) < 1 { return errors.New("alias name not provided") } @@ -67,6 +72,9 @@ func init() { startAliasCmd.Flags().BoolVarP(&conf.Verbose, "verbose", "v", false, "increase log verbosity") startAliasCmd.Flags().BoolVarP(&conf.Insecure, "insecure", "i", false, "skip host key validation when connecting to ssh server") startAliasCmd.Flags().BoolVarP(&conf.Detach, "detach", "x", false, "run process in background") - + // id is a hidden flag used to carry the unique identifier of the instance to + // the child process when the `--detached` flag is used. + startAliasCmd.Flags().StringVarP(&conf.Id, mole.IdFlagName, "", "", "") + _ = startAliasCmd.Flags().MarkHidden(mole.IdFlagName) startCmd.AddCommand(startAliasCmd) } diff --git a/go.mod b/go.mod index 2d8a88a..4be28a5 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/hpcloud/tail v1.0.0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c - github.com/mitchellh/go-ps v1.0.0 // indirect + github.com/mitchellh/go-ps v1.0.0 github.com/mitchellh/mapstructure v1.4.1 github.com/pelletier/go-buffruneio v0.2.0 // indirect github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2