-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add proper CLI, supports upload, download and repl commands #30
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" Command-line interface for druid """ | ||
|
||
import sys | ||
import time | ||
|
||
import click | ||
|
||
from druid import crowlib | ||
from druid import repl as druid_repl | ||
|
||
@click.group(invoke_without_command=True) | ||
@click.pass_context | ||
@click.version_option() | ||
def cli(ctx): | ||
""" Terminal interface for crow """ | ||
if ctx.invoked_subcommand is None: | ||
ctx.invoke(repl) | ||
|
||
@cli.command(short_help="Download a file from crow") | ||
def download(): | ||
""" | ||
Download a file from crow and print it to stdout | ||
""" | ||
try: | ||
crow = crowlib.connect() | ||
except ValueError as err: | ||
click.echo(err) | ||
sys.exit(1) | ||
|
||
crow.write(bytes("^^p", "utf-8")) | ||
click.echo(crow.read(1000000).decode()) | ||
crow.close() | ||
|
||
def myprint(string): | ||
click.echo(string) | ||
|
||
@cli.command(short_help="Upload a file to crow") | ||
@click.argument("filename", type=click.Path(exists=True)) | ||
def upload(filename): | ||
""" | ||
Upload a file to crow. | ||
FILENAME is the path to the Lua file to upload | ||
""" | ||
try: | ||
crow = crowlib.connect() | ||
except ValueError as err: | ||
click.echo(err) | ||
sys.exit(1) | ||
|
||
crowlib.upload(crow.write, myprint, filename) | ||
click.echo(crow.read(1000000).decode()) | ||
click.echo("File uploaded") | ||
time.sleep(0.5) # wait for new script to be ready | ||
crow.write(bytes("^^p", "utf-8")) | ||
click.echo(crow.read(1000000).decode()) | ||
simonvanderveldt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
crow.close() | ||
|
||
@cli.command() | ||
@click.argument("filename", type=click.Path(exists=True), required=False) | ||
def repl(filename): | ||
""" Start interactive terminal """ | ||
druid_repl.main(filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the repl interaction (
p
) and the crow command (^^p
) it might make more sense to call thisprint
instead ofupload
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think
^^p
is 'download' right? the main usage of the download script is that you arrow it to a filedruid download > myscript.lua
. this style of behaviour makes it feel more like a 'download' than a 'print' to me. that said, you are correct that what druid does is just 'print'.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was just thinking that for naming consistency it might make sense to call it
print
.Also looking at your example for me it seems to support that
print
might be a better name in that the command itself just prints to stdout, it doesn't write to a file, which is what I'd normally associate with downloading.On the other hand if you curl a file then it goes to stdout as well and I'd call that downloading as well.
Hmm 🤔
Naming is hard...