Skip to content

Commit

Permalink
Closes #122
Browse files Browse the repository at this point in the history
  • Loading branch information
gmittal committed Dec 28, 2021
1 parent 38a59de commit 436d886
Showing 1 changed file with 26 additions and 54 deletions.
80 changes: 26 additions & 54 deletions prototype/sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ def _truncate_long_string(s: str, max_length: int = 50) -> str:
return ' '.join(splits[:i]) + ' ...'


def _interactive_node_cli_command(cli_func):
cmd = cli.command()
cluster_option = click.option('--cluster',
'-c',
default=None,
type=str,
help=_CLUSTER_FLAG_HELP)
port_forward_option = click.option('--port-forward',
'-p',
multiple=True,
default=[],
type=int,
required=False,
help=('Port to be forwarded. To forward multiple ports, '
'use this option multiple times.'))
screen_option = click.option('--screen',
default=False,
is_flag=True,
help='If true, attach using screen.')

return cmd(cluster_option(port_forward_option(screen_option(cli_func))))


def _default_interactive_node_name(node_type: str):
"""Returns a deterministic name to refer to the same node."""
# FIXME: this technically can collide in Azure/GCP with another
Expand Down Expand Up @@ -463,24 +486,7 @@ def _terminate_or_stop(names: Tuple[str], apply_to_all: Optional[bool],
'or "sky cpunode/gpunode".')


@cli.command()
@click.option('--cluster',
'-c',
default=None,
type=str,
help=_CLUSTER_FLAG_HELP)
@click.option('--port-forward',
'-p',
multiple=True,
default=[],
type=int,
required=False,
help=('Port to be forwarded. To forward multiple ports, '
'use this option multiple times.'))
@click.option('--screen',
default=False,
is_flag=True,
help='If true, attach using screen.')
@_interactive_node_cli_command
def gpunode(cluster: str, port_forward: Optional[List[int]], screen):
"""Launch or attach to an interactive GPU node.
Expand Down Expand Up @@ -522,24 +528,7 @@ def gpunode(cluster: str, port_forward: Optional[List[int]], screen):
)


@cli.command()
@click.option('--cluster',
'-c',
default=None,
type=str,
help=_CLUSTER_FLAG_HELP)
@click.option('--port-forward',
'-p',
multiple=True,
default=[],
type=int,
required=False,
help=('Port to be forwarded. To forward multiple ports, '
'use this option multiple times.'))
@click.option('--screen',
default=False,
is_flag=True,
help='If true, attach using screen.')
@_interactive_node_cli_command
def cpunode(cluster: str, port_forward: Optional[List[int]], screen):
"""Launch or attach to an interactive CPU node.
Expand Down Expand Up @@ -581,24 +570,7 @@ def cpunode(cluster: str, port_forward: Optional[List[int]], screen):
)


@cli.command()
@click.option('--cluster',
'-c',
default=None,
type=str,
help=_CLUSTER_FLAG_HELP)
@click.option('--port-forward',
'-p',
multiple=True,
default=[],
type=int,
required=False,
help=('Port to be forwarded. To forward multiple ports, '
'use this option multiple times.'))
@click.option('--screen',
default=False,
is_flag=True,
help='If true, attach using screen.')
@_interactive_node_cli_command
def tpunode(cluster: str, port_forward: Optional[List[int]], screen):
"""Launch or attach to an interactive TPU node.
Expand Down

0 comments on commit 436d886

Please sign in to comment.