diff --git a/command/changeport-cmd.go b/command/changeport-cmd.go new file mode 100644 index 0000000..2385baf --- /dev/null +++ b/command/changeport-cmd.go @@ -0,0 +1,15 @@ +package command + +func (i *Command) RunChangePort() error { + return i.runSteps( + i.CryosparcmChangePortStep( + i.cfg.HostName, + i.cfg.CryosparcPath, + i.cfg.BasePort, + portStart, + portEnd, + portCount, + i.cfg.CryosparcmHelp, + ), + ) +} diff --git a/command/install-cmd.go b/command/install-cmd.go index aaefcdd..8325a23 100644 --- a/command/install-cmd.go +++ b/command/install-cmd.go @@ -10,8 +10,8 @@ import ( ) var ( - portStart uint = 39400 // Start port range to assign new base port - portEnd uint = 40000 // End port range to assign new base port + portStart uint = 61000 // Start port range to assign new base port + portEnd uint = 62000 // End port range to assign new base port portCount uint = 10 // Number of contiguous ports available ) diff --git a/command/steps.go b/command/steps.go index 663e45d..083b088 100644 --- a/command/steps.go +++ b/command/steps.go @@ -76,7 +76,6 @@ func (i *Command) CryosparcmCreateUserStep( Message: fmt.Sprintf("Creating CryoSPARC user (instance: %s)", cryosparcpath), CompletedMessage: nil, Condition: func() (bool, error) { - return true, nil }, Prompt: func() *huh.Form { @@ -163,6 +162,33 @@ func (i *Command) CryosparcmCreateUserStep( } } +func (i *Command) CryosparcmChangePortStep( + hostname, + cryosparcpath string, + port, start, end, count uint, + help bool) ui.Step { + + return ui.Step{ + Message: fmt.Sprintf("Changing base port (instance: %s)", cryosparcpath), + CompletedMessage: nil, + Exec: func() *exec.Cmd { + + if port == 0 { + i.setCryosparcBasePort(hostname, start, end, count) + } + + return cryosparcmCmd( + hostname, + cryosparcpath, + "", + help, + "changeport", + strconv.FormatUint(uint64(i.cfg.BasePort), 10), + ) + }, + } +} + // ============================================================================= // cryosparcm commands Steps // ============================================================================= diff --git a/main.go b/main.go index fc4f226..ffb784e 100644 --- a/main.go +++ b/main.go @@ -93,6 +93,13 @@ func main() { cryosparcwCmd.PreRunE = preRunCmd("worker", false) + // changeport commands + changeportCmd := newCommand( + "changeport", + "Change base port", + runCmd((*command.Command).RunChangePort), + ) + // Install commands installCmd := newCommand( "install", @@ -197,6 +204,7 @@ func main() { instancesCmd, cryosparcmCmd, cryosparcwCmd, + changeportCmd, installCmd, lanesCmd, userCmd, @@ -217,6 +225,11 @@ func main() { // ============================================= addCryosparcwFlags(cryosparcwCmd) + // ============================================= + // changeport CLI Flags + // ============================================= + addChangePortFlags(changeportCmd) + // ============================================= // Install CLI Flags // ============================================= @@ -663,6 +676,18 @@ func addCryosparcmFlags(cmd *cobra.Command) { flags.SortFlags = false } +// changeport +func addChangePortFlags(cmd *cobra.Command) { + flags := cmd.Flags() + + addCryosparcPathFlag(cmd) + addHostnameFlag(cmd) + addBasePortFlag(cmd) + + flags.SetInterspersed(false) + flags.SortFlags = false +} + // cryosparcw func addCryosparcwFlags(cmd *cobra.Command) { flags := cmd.Flags()