-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rationale ========= Click is more modular and easier to use for larger command-line programs. Breaking Changes ================ - Can no longer use an arbitrary number of arguments to options, i.e. `gentodo add -t title -d Arbitrary Number of Arguments` this is due to a technicial limitation and will not be fixed. Major Changes ============= - Convert from argparse to click - Remove parser.py as it is no longer needed Minor Changes ============= - Automatically make config directory if it doesn't exist Signed-off-by: Christopher Fore <[email protected]>
- Loading branch information
Showing
8 changed files
with
137 additions
and
180 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
'''__init__.py''' | ||
__version__ = "0.2.1" | ||
__version__ = "1.0.0" |
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
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 |
---|---|---|
@@ -1,37 +1,48 @@ | ||
'''config.py | ||
Module that handles configuration interactions | ||
''' | ||
|
||
import tomllib | ||
import sys | ||
import os | ||
|
||
STORAGE_DIR = os.path.expanduser("~/.config/gentodo") | ||
CONFIG_FILE = os.path.join(STORAGE_DIR, "config.toml") | ||
|
||
class Config: | ||
'''Class to handle the configuration file settings''' | ||
def __init__(self): | ||
if not os.path.isfile(CONFIG_FILE): | ||
os.makedirs(STORAGE_DIR) | ||
with open(CONFIG_FILE, "w", encoding="utf_8") as config: | ||
config.write("[gentodo]\n") | ||
self.data = self.load_config() | ||
|
||
def load_config(self): | ||
'''Loads the config from the TOML file''' | ||
with open(CONFIG_FILE, "rb") as config: | ||
return tomllib.load(config) | ||
|
||
def get_token(self): | ||
'''Gets the Bugzilla token''' | ||
try: | ||
return self.data['gentodo']['token'] | ||
except KeyError: | ||
print("API Key not found, please add it to config.toml.") | ||
exit(1) | ||
sys.exit(1) | ||
|
||
def get_urls(self): | ||
'''Gets Bugzilla URLs''' | ||
try: | ||
return self.data['gentodo']['urls'] | ||
except KeyError: | ||
print("Bugzilla URLs not found, please add them to config.toml.") | ||
exit(1) | ||
sys.exit(1) | ||
|
||
def get_emails(self): | ||
'''Gets emails to search for''' | ||
try: | ||
return self.data['gentodo']['emails'] | ||
except KeyError: | ||
print("Emails not found, please add them to config.toml.") | ||
exit(1) | ||
sys.exit(1) |
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 |
---|---|---|
@@ -1,21 +1,41 @@ | ||
'''Gentodo (c) 2023 Christopher Fore | ||
This code is licensed under the GPLv3 license (see LICENSE for details) | ||
''' | ||
import click | ||
|
||
#import bugzilla // commented out until used | ||
from gentodo import cli, parser, config, bugs | ||
from gentodo import commands, __version__ | ||
|
||
def main(): | ||
'''Main function''' | ||
todo = cli.Gentodo() | ||
unparsed = parser.setup_parser() | ||
|
||
args = unparsed.parse_args() | ||
args.func(args, todo) | ||
#conf = config.Config() | ||
#print(conf.get_token()) | ||
#bz = bugs.Bugs() | ||
#print(bz.get_cced()) | ||
@click.group(invoke_without_command=True) | ||
@click.version_option(__version__) | ||
@click.option('--verbose', '-v', default=False, is_flag=True) | ||
@click.option('--brief', '-b', default=None, type=str) | ||
@click.pass_context | ||
def cmd(ctx, verbose, brief): | ||
'''General purpose command group''' | ||
ctx.ensure_object(dict) | ||
ctx.obj['GENTODO'] = commands.Gentodo() | ||
if ctx.invoked_subcommand is None: | ||
ctx.forward(commands.show) | ||
|
||
|
||
@cmd.group() | ||
@click.pass_context | ||
def bugs(ctx): | ||
'''Bugs command group''' | ||
ctx.ensure_object(dict) | ||
ctx.obj['GENTODO'] = commands.Gentodo() | ||
|
||
cmd.add_command(commands.show) | ||
cmd.add_command(commands.add) | ||
cmd.add_command(commands.rm) | ||
cmd.add_command(commands.count) | ||
cmd.add_command(commands.edit) | ||
cmd.add_command(commands.search) | ||
bugs.add_command(commands.pull_bugs) | ||
|
||
|
||
def main(): | ||
'''Main entrypoint''' | ||
cmd() | ||
|
||
if __name__ == "__main__": | ||
# Alternative Entrypoint | ||
main() |
Oops, something went wrong.