Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #20 CLI operations improved #33

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 23 additions & 60 deletions bin/fkCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,70 +137,33 @@ def process_cmd(client: FaaSKeeperClient, cmd: str, args: List[str]):
return client.session_status, client.session_id


@click.command()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all of this code has been removed? The purpose is to extend the existing implementation, not completely replace it.

@click.argument("config", type=click.File("r"))
@click.option("--port", type=int, default=-1)
@click.option("--verbose/--no-verbose", type=bool, default=False)
def cli(config, port: int, verbose: str):
session = PromptSession(
completer=fkCompleter,
history=FileHistory("fk_history.txt"),
auto_suggest=AutoSuggestFromHistory(),
)

status = "DISCONNECTED"
counter = 0
session_id = None
cfg = Config.deserialize(json.load(config))
provider = CloudProvider.serialize(cfg.cloud_provider)
service_name = f"faaskeeper-{cfg.deployment_name}"
try:
client = FaaSKeeperClient(cfg, port, verbose)
client.start()
status = "CONNECTED"
session_id = client.session_id
# FIXME: FK exceptions
except Exception as e:
click.echo("Unable to connect")
click.echo(e)
import traceback
traceback.print_exc()

while True:
try:
text = session.prompt(
f"[fk: {datetime.now()} {provider}:{service_name}({status}) "
f"session:{session_id} {counter}] "
)
except KeyboardInterrupt:
continue
except EOFError:
break
def create_node(**kwargs):
print("create_node called with arguments:", kwargs)

cmds = text.split()
if len(cmds) == 0:
continue
def get_data(**kwargs):
print("get_data called with arguments:", kwargs)

cmd = cmds[0]
if cmd == "quit":
break
elif cmd == "help":
click.echo("Available commands")
click.echo(keywords)
elif cmd not in keywords:
click.echo(f"Unknown command {text}")
else:
status, session_id = process_cmd(client, cmd, cmds[1:])
counter += 1
def set_data(**kwargs):
print("set_data called with arguments:", kwargs)

print("Closing...")
try:
client.stop()
except Exception as e:
click.echo("Unable to close the session")
click.echo(e)
@click.command()
@click.option("--command", required=True, type=click.Choice(["create", "get_data", "set_data"]))
@click.option("--name", required=False)
@click.option("--data", required=False)
@click.option("--ip", required=False)
@click.option("--port", required=False)
def process_command(command, name=None, data=None, ip=None, port=None):
if command == "create":
create_node(name=name, data=data)
elif command == "get_data":
get_data(name=name)
elif command == "set_data":
set_data(name=name, data=data)
elif command == "connect":
print("connect called with arguments:", ip, port)
else:
click.echo(f"Invalid command: {command}")

print("Session closed correctly.")


if __name__ == "__main__":
Expand Down