Support running with no args - show help
This commit is contained in:
parent
acd736c970
commit
c08c5609ca
1 changed files with 18 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -15,16 +16,17 @@ def main() -> None:
|
||||||
setup_logging(args.logging)
|
setup_logging(args.logging)
|
||||||
|
|
||||||
# Load config from file if it exists
|
# Load config from file if it exists
|
||||||
conf_path = Path(args.album_path) / Path(args.config)
|
if hasattr(args, "album_path"):
|
||||||
if conf_path.exists():
|
conf_path = Path(args.album_path) / Path(args.config)
|
||||||
logger.debug(f"Reading config from {conf_path}")
|
if conf_path.exists():
|
||||||
config = Config.from_yaml(conf_path.read_bytes())
|
logger.debug(f"Reading config from {conf_path}")
|
||||||
elif args.action != "init":
|
config = Config.from_yaml(conf_path.read_bytes())
|
||||||
logger.error(
|
elif args.action != "init":
|
||||||
f"No config file found at {conf_path}. If this is a new photo directory, "
|
logger.error(
|
||||||
"please run `photojawn init` in there first."
|
f"No config file found at {conf_path}. If this is a new photo directory, "
|
||||||
)
|
"please run `photojawn init` in there first."
|
||||||
return
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Call the subcommand function
|
# Call the subcommand function
|
||||||
match args.action:
|
match args.action:
|
||||||
|
@ -98,7 +100,12 @@ def parse_args() -> Namespace:
|
||||||
help="Path to the main photos directory",
|
help="Path to the main photos directory",
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if not hasattr(args, 'action'):
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
|
|
Loading…
Add table
Reference in a new issue