def get_config(param): """Get Submarine CLI Config""" _config = loadConfig() try: click.echo("{}={}".format(param, rgetattr(_config, param))) except AttributeError as err: click.echo(err)
def test_list_config(): initConfig() runner = CliRunner() result = runner.invoke(main.entry_point, ["config", "list"]) _config = loadConfig() assert result.exit_code == 0 assert "SubmarineCliConfig" in result.output assert '"hostname": "{}"'.format( _config.connection.hostname) in result.output assert '"port": {}'.format(_config.connection.port) in result.output
def test_get_set_experiment(): initConfig() mock_hostname = "mockhost" runner = CliRunner() result = runner.invoke(main.entry_point, ["config", "get", "connection.hostname"]) assert result.exit_code == 0 _config = loadConfig() assert "connection.hostname={}".format( _config.connection.hostname) in result.output result = runner.invoke( main.entry_point, ["config", "set", "connection.hostname", mock_hostname]) assert result.exit_code == 0 result = runner.invoke(main.entry_point, ["config", "get", "connection.hostname"]) assert result.exit_code == 0 _config = loadConfig() assert "connection.hostname={}".format(mock_hostname) in result.output assert mock_hostname == _config.connection.hostname initConfig()
def set_config(param, value): """Set Submarine CLI Config""" _config = loadConfig() _paramField = rgetattr(_config, param) # define types that can be cast from command line input primitive = (int, str, bool) def is_primitiveType(_type): return _type in primitive # cast type if type(_paramField) == type(Union) and is_primitiveType( type(_paramField).__args__[0]): value = type(_paramField).__args__[0](value) elif is_primitiveType(type(_paramField)): value = type(_paramField)(value) try: rsetattr(_config, param, value) except TypeError as err: click.echo(err) saveConfig(_config)
specific language governing permissions and limitations under the License. """ import json import time import click from rich.console import Console from rich.json import JSON as richJSON from rich.panel import Panel from submarine.cli.config.config import loadConfig from submarine.client.api.serve_client import ServeClient from submarine.client.api_client import ApiException submarineCliConfig = loadConfig() serveClient = ServeClient( f"http://{submarineCliConfig.connection.hostname}:{submarineCliConfig.connection.port}" if submarineCliConfig else "http://*****:*****@click.command("serve") def list_serve(): """List serves""" click.echo("The command is not supported yet.") # TODO(kuanhsun) click.echo("list serve!")
def list_config(): """List Submarine CLI Config""" console = Console() _config = loadConfig() json_data = richJSON.from_data({**asdict(_config)}) console.print(Panel(json_data, title="SubmarineCliConfig"))