-
-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor #73
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
Merged
Merged
Refactor #73
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
908f139
fix : __init__.py import updated
sepandhaghighi ac8583c
fix : CLI section modified
sepandhaghighi f42a6f9
fix : CLI functions moved to cli.py
sepandhaghighi d236a69
fix : autopep8
sepandhaghighi 3d6d181
doc : CHANGELOG.md updated
sepandhaghighi 3e6d3e5
fix : sys.exit(1) added
sepandhaghighi 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 contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,46 +1,7 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Nava main.""" | ||
| import argparse | ||
| from art import tprint | ||
| from .params import NAVA_VERSION | ||
| from .functions import nava_help, play_cli | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """CLI main function.""" | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| 'filename', | ||
| nargs='?', | ||
| type=str, | ||
| metavar='FILE_PATH', | ||
| help='path to audio file' | ||
| ) | ||
| parser.add_argument( | ||
| '--file', | ||
| nargs='?', | ||
| type=str, | ||
| metavar='FILE_PATH', | ||
| help='path to audio file', | ||
| ) | ||
| parser.add_argument('--loop', help='sound play in loop', action='store_true', default=False) | ||
| parser.add_argument('--version', help="version", action='store_true', default=False) | ||
| parser.add_argument('-v', help="version", action='store_true', default=False) | ||
| args = parser.parse_known_args()[0] | ||
| if args.version or args.v: | ||
| print(NAVA_VERSION) | ||
| elif args.filename or args.file: | ||
| file_name = args.filename | ||
| if args.file: | ||
| file_name = args.file | ||
| loop = args.loop | ||
| play_cli(file_name, loop=loop) | ||
| else: | ||
| tprint("Nava") | ||
| tprint("V:" + NAVA_VERSION) | ||
| nava_help() | ||
| parser.print_help() | ||
|
|
||
| from .cli import main | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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,61 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Nava cli.""" | ||
| import sys | ||
| import argparse | ||
| from art import tprint | ||
| from .params import NAVA_VERSION, EXIT_MESSAGE | ||
| from .functions import nava_help, play_cli | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| """Parse arguments.""" | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| 'filename', | ||
| nargs='?', | ||
| type=str, | ||
| metavar='FILE_PATH', | ||
| help='path to audio file' | ||
| ) | ||
| parser.add_argument( | ||
| '--file', | ||
| nargs='?', | ||
| type=str, | ||
| metavar='FILE_PATH', | ||
| help='path to audio file', | ||
| ) | ||
| parser.add_argument('--loop', help='sound play in loop', action='store_true', default=False) | ||
| parser.add_argument('--version', help="version", action='store_true', default=False) | ||
| parser.add_argument('-v', help="version", action='store_true', default=False) | ||
| args = parser.parse_known_args()[0] | ||
| return args | ||
|
|
||
|
|
||
| def run(args: argparse.Namespace) -> None: | ||
| """ | ||
| Run nava CLI. | ||
|
|
||
| :param args: arguments | ||
| """ | ||
| if args.version or args.v: | ||
| print(NAVA_VERSION) | ||
| elif args.filename or args.file: | ||
| file_name = args.filename | ||
| if args.file: | ||
| file_name = args.file | ||
| loop = args.loop | ||
| play_cli(file_name, loop=loop) | ||
| else: | ||
| tprint("Nava") | ||
| tprint("V:" + NAVA_VERSION) | ||
| nava_help() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is that ok we remove
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
|
|
||
|
|
||
| def main() -> None: | ||
| """CLI main function.""" | ||
| try: | ||
| args = parse_args() | ||
| run(args) | ||
| except (KeyboardInterrupt, EOFError): | ||
| print(EXIT_MESSAGE) | ||
| sys.exit(1) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
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.
why we do have
parse_known_argshere?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.
It appears that the first argument (
filename) is positional, suggesting thatparse_known_argsshould be used.