Add basic autocompletion
This commit is contained in:
parent
d497ce9c71
commit
382423fe5a
3 changed files with 31 additions and 6 deletions
21
README.md
21
README.md
|
@ -7,9 +7,28 @@ Script to generate multi-gallery upload-ready files.
|
|||
- A Python environment to install dependencies (`pip install -r requirements.txt`); if unsure, create a fresh one with `virtualenv venv`.
|
||||
- LibreOffice 6.0+, making sure that `libreoffice` is in your PATH.
|
||||
|
||||
## Installation
|
||||
|
||||
I recommend creating a virtualenv first. Linux/Mac/Unix example:
|
||||
|
||||
```sh
|
||||
virtualenv venv
|
||||
source venv/bin/activate # Also run every time you'll use this tool
|
||||
pip install -r requirements.txt
|
||||
activate-global-python-argcomplete
|
||||
```
|
||||
|
||||
Windows example (no autocompletion):
|
||||
|
||||
```powershell
|
||||
virtualenv venv
|
||||
./venv/Scripts/activate # Also run every time you'll use this tool
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Run with `python main.py -h` for options. Generated files are output to `./out` by default.
|
||||
Run with `python main.py -h` (or simply `./main.py -h`) for options. Generated files are output to `./out` by default.
|
||||
|
||||
### Story files
|
||||
|
||||
|
|
15
main.py
Normal file → Executable file
15
main.py
Normal file → Executable file
|
@ -1,3 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
import argcomplete
|
||||
from argcomplete.completers import FilesCompleter, DirectoriesCompleter
|
||||
import argparse
|
||||
import os
|
||||
from subprocess import CalledProcessError
|
||||
|
@ -52,19 +56,20 @@ def main(out_dir_path=None, story_path=None, description_path=None, file_path=No
|
|||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='generate multi-gallery upload-ready files')
|
||||
parser.add_argument('-o', '--output-dir', dest='out_dir_path', default='./out',
|
||||
help='path of output directory')
|
||||
help='path of output directory').completer = DirectoriesCompleter
|
||||
parser.add_argument('-c', '--config', dest='config_path', default='./config.json',
|
||||
help='path of JSON configuration file')
|
||||
help='path of JSON configuration file').completer = FilesCompleter
|
||||
parser.add_argument('-s', '--story', dest='story_path',
|
||||
help='path of LibreOffice-readable story file')
|
||||
help='path of LibreOffice-readable story file').completer = FilesCompleter
|
||||
parser.add_argument('-d', '--description', dest='description_path',
|
||||
help='path of BBCode-formatted description file')
|
||||
help='path of BBCode-formatted description file').completer = FilesCompleter
|
||||
parser.add_argument('-f', '--file', dest='file_path',
|
||||
help='path of generic file to include in output (i.e. an image or thumbnail)')
|
||||
help='path of generic file to include in output (i.e. an image or thumbnail)').completer = FilesCompleter
|
||||
parser.add_argument('-k', '--keep-out-dir', dest='keep_out_dir', action='store_true',
|
||||
help='whether output directory contents should be kept.\nif set, a script error may leave partial files behind')
|
||||
parser.add_argument('-I', '--ignore-empty-files', dest='ignore_empty_files', action='store_true',
|
||||
help='do not raise an error if any input file is empty or whitespace-only')
|
||||
argcomplete.autocomplete(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not any([args.story_path, args.description_path]):
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
argcomplete==3.2.1
|
||||
lark==1.1.8
|
||||
psutil==5.9.6
|
||||
|
|
Reference in a new issue