Skip to content

Commit

Permalink
Feature/cli (#47)
Browse files Browse the repository at this point in the history
* add --file argument to arg parser

* nava handling of --file argument

* `CHANGELOG.md` updated

* `autopep8.sh` applied

* add SOUND_FILE_NAME_EXIST_ERROR string

* handle non-named arg

* fulfill the implementation of `nava --file="test.wav"`, `nava "test.wav"` and `nava test.wav`

* remove trailing whitespaces

* update : `__main__.py` updated.

* add : `play_cli` function added.

* add : version test added.

* update : `README.md` updated.

* remove : `SOUND_FILE_NAME_EXIST_ERROR` removed.

* fix : typo in README.md fixed.

* fix : changelog fixed.

* update : readme updated.

* apply : requested changes applied.

* fix mentinoed issue by Sepand

* add `-v` flag

* apply `autopep8.sh`

---------

Co-authored-by: Sadra Sabouri <[email protected]>
  • Loading branch information
AHReccese and sadrasabouri authored May 23, 2024
1 parent 2cc1bb0 commit c730633
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: First test
run: |
sudo nava
sudo nava --version
- name: Install ALSA
run: |
sudo apt-get update
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/macOS_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: First test
run: |
nava
nava --version
- name: Test requirements Installation
run: |
python others/requirements-splitter.py
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: First test
run: |
nava
nava --version
- name: Install Scream
shell: powershell
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- `play_cli` function
- `SECURITY.md`
### Changed
- `main` function updated
- OSs local checklist added to pull request template
- `README.md` modified
## [0.5] - 2024-04-03
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ except NavaBaseError as e:
print(str(e))
```

### CLI
```bash
$ nava [--file FILE_PATH] [--loop] FILE_PATH
```

## Engine

List of different platforms and the corresponding engines that are used for sound playing.
Expand Down
41 changes: 34 additions & 7 deletions nava/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
"""Nava main."""

import sys
import argparse
from art import tprint
from .params import NAVA_VERSION
from .functions import nava_help
from .functions import nava_help, play_cli


def main():
Expand All @@ -13,10 +12,38 @@ def main():
:return: None
"""
args = sys.argv
tprint("nava")
tprint("V:" + NAVA_VERSION)
nava_help()
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()


if __name__ == "__main__":
Expand Down
22 changes: 21 additions & 1 deletion nava/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def nava_help():
"""
print(OVERVIEW)
print("Repo : https://github.com/openscilab/nava")
print("Webpage : https://openscilab.com/")
print("Webpage : https://openscilab.com/\n")


def quote(func):
Expand Down Expand Up @@ -275,3 +275,23 @@ def play(sound_path, async_mode=False, loop=False):
return __play_linux(sound_path, async_mode, loop)
except Exception: # pragma: no cover
raise NavaBaseError(SOUND_FILE_PLAY_ERROR)


def play_cli(sound_path, loop=False):
"""
Play sound from CLI.
:param sound_path: sound path
:type sound_path: str
:param loop: sound loop flag
:type loop: bool
:return: None
"""
try:
while True:
play(sound_path)
if not loop:
break
except KeyboardInterrupt:
stop_all()
sys.exit(0)

0 comments on commit c730633

Please sign in to comment.