Hugoifier
fix(cli,translate): raise exceptions on errors, remove getattr, expose --target-language Closes #4
Commit
e0420f1afbfd8647a23724fca6054f52488c9feb0f3a81888371cd3aae67f77f
Parent
e36cfdb885d63b2…
1 file changed
+40
-32
+40
-32
| --- src/cli.py | ||
| +++ src/cli.py | ||
| @@ -9,10 +9,11 @@ | ||
| 9 | 9 | python cli.py hugoify themes/revolve-hugo |
| 10 | 10 | python cli.py decapify output/revolve-hugo |
| 11 | 11 | """ |
| 12 | 12 | |
| 13 | 13 | import argparse |
| 14 | +import logging | |
| 14 | 15 | import sys |
| 15 | 16 | import os |
| 16 | 17 | |
| 17 | 18 | # Ensure src/ is on the path when called directly |
| 18 | 19 | sys.path.insert(0, os.path.dirname(__file__)) |
| @@ -61,12 +62,13 @@ | ||
| 61 | 62 | decapify_parser.add_argument("--cms-name", default=None, help="Whitelabel CMS name (default: 'Content Manager')") |
| 62 | 63 | decapify_parser.add_argument("--cms-logo", default=None, help="Whitelabel logo URL") |
| 63 | 64 | decapify_parser.add_argument("--cms-color", default=None, help="Whitelabel top-bar hex color") |
| 64 | 65 | |
| 65 | 66 | # translate |
| 66 | - translate_parser = subparsers.add_parser("translate", help="Translate content (stub)") | |
| 67 | - translate_parser.add_argument("path", help="Path to the content") | |
| 67 | + translate_parser = subparsers.add_parser("translate", help="Translate content to another language") | |
| 68 | + translate_parser.add_argument("path", help="Path to the content file") | |
| 69 | + translate_parser.add_argument("--target-language", default="Spanish", help="Target language (default: Spanish)") | |
| 68 | 70 | |
| 69 | 71 | # parse / lint |
| 70 | 72 | parser_parser = subparsers.add_parser("parser", help="Parse and lint (stub)") |
| 71 | 73 | parser_parser.add_argument("path", help="Path to the theme") |
| 72 | 74 | |
| @@ -80,44 +82,50 @@ | ||
| 80 | 82 | cloudflare_parser.add_argument("path", help="Path to the site") |
| 81 | 83 | cloudflare_parser.add_argument("zone", help="Cloudflare zone") |
| 82 | 84 | |
| 83 | 85 | args = parser.parse_args() |
| 84 | 86 | |
| 87 | + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| 88 | + | |
| 85 | 89 | # Override backend if specified on command line |
| 86 | 90 | if args.backend: |
| 87 | 91 | import config as cfg |
| 88 | 92 | cfg.BACKEND = args.backend |
| 89 | 93 | |
| 90 | - if args.command == "complete": | |
| 91 | - result = complete( | |
| 92 | - args.path, | |
| 93 | - output_dir=getattr(args, 'output', None), | |
| 94 | - cms_name=getattr(args, 'cms_name', None), | |
| 95 | - cms_logo=getattr(args, 'cms_logo', None), | |
| 96 | - cms_color=getattr(args, 'cms_color', None), | |
| 97 | - ) | |
| 98 | - print(result) | |
| 99 | - elif args.command == "analyze": | |
| 100 | - print(analyze(args.path)) | |
| 101 | - elif args.command == "hugoify": | |
| 102 | - print(hugoify(args.path)) | |
| 103 | - elif args.command == "decapify": | |
| 104 | - print(decapify( | |
| 105 | - args.path, | |
| 106 | - cms_name=getattr(args, 'cms_name', None), | |
| 107 | - cms_logo=getattr(args, 'cms_logo', None), | |
| 108 | - cms_color=getattr(args, 'cms_color', None), | |
| 109 | - )) | |
| 110 | - elif args.command == "translate": | |
| 111 | - print(translate(args.path)) | |
| 112 | - elif args.command == "parser": | |
| 113 | - print(parse(args.path)) | |
| 114 | - elif args.command == "deploy": | |
| 115 | - print(deploy(args.path, args.zone)) | |
| 116 | - elif args.command == "cloudflare": | |
| 117 | - print(configure_cloudflare(args.path, args.zone)) | |
| 118 | - else: | |
| 119 | - parser.print_help() | |
| 94 | + try: | |
| 95 | + if args.command == "complete": | |
| 96 | + result = complete( | |
| 97 | + args.path, | |
| 98 | + output_dir=args.output, | |
| 99 | + cms_name=args.cms_name, | |
| 100 | + cms_logo=args.cms_logo, | |
| 101 | + cms_color=args.cms_color, | |
| 102 | + ) | |
| 103 | + print(result) | |
| 104 | + elif args.command == "analyze": | |
| 105 | + print(analyze(args.path)) | |
| 106 | + elif args.command == "hugoify": | |
| 107 | + print(hugoify(args.path)) | |
| 108 | + elif args.command == "decapify": | |
| 109 | + print(decapify( | |
| 110 | + args.path, | |
| 111 | + cms_name=args.cms_name, | |
| 112 | + cms_logo=args.cms_logo, | |
| 113 | + cms_color=args.cms_color, | |
| 114 | + )) | |
| 115 | + elif args.command == "translate": | |
| 116 | + print(translate(args.path, target_language=args.target_language)) | |
| 117 | + elif args.command == "parser": | |
| 118 | + print(parse(args.path)) | |
| 119 | + elif args.command == "deploy": | |
| 120 | + print(deploy(args.path, args.zone)) | |
| 121 | + elif args.command == "cloudflare": | |
| 122 | + print(configure_cloudflare(args.path, args.zone)) | |
| 123 | + else: | |
| 124 | + parser.print_help() | |
| 125 | + except (ValueError, EnvironmentError) as e: | |
| 126 | + print(f"Error: {e}", file=sys.stderr) | |
| 127 | + sys.exit(1) | |
| 120 | 128 | |
| 121 | 129 | |
| 122 | 130 | if __name__ == "__main__": |
| 123 | 131 | main() |
| 124 | 132 |
| --- src/cli.py | |
| +++ src/cli.py | |
| @@ -9,10 +9,11 @@ | |
| 9 | python cli.py hugoify themes/revolve-hugo |
| 10 | python cli.py decapify output/revolve-hugo |
| 11 | """ |
| 12 | |
| 13 | import argparse |
| 14 | import sys |
| 15 | import os |
| 16 | |
| 17 | # Ensure src/ is on the path when called directly |
| 18 | sys.path.insert(0, os.path.dirname(__file__)) |
| @@ -61,12 +62,13 @@ | |
| 61 | decapify_parser.add_argument("--cms-name", default=None, help="Whitelabel CMS name (default: 'Content Manager')") |
| 62 | decapify_parser.add_argument("--cms-logo", default=None, help="Whitelabel logo URL") |
| 63 | decapify_parser.add_argument("--cms-color", default=None, help="Whitelabel top-bar hex color") |
| 64 | |
| 65 | # translate |
| 66 | translate_parser = subparsers.add_parser("translate", help="Translate content (stub)") |
| 67 | translate_parser.add_argument("path", help="Path to the content") |
| 68 | |
| 69 | # parse / lint |
| 70 | parser_parser = subparsers.add_parser("parser", help="Parse and lint (stub)") |
| 71 | parser_parser.add_argument("path", help="Path to the theme") |
| 72 | |
| @@ -80,44 +82,50 @@ | |
| 80 | cloudflare_parser.add_argument("path", help="Path to the site") |
| 81 | cloudflare_parser.add_argument("zone", help="Cloudflare zone") |
| 82 | |
| 83 | args = parser.parse_args() |
| 84 | |
| 85 | # Override backend if specified on command line |
| 86 | if args.backend: |
| 87 | import config as cfg |
| 88 | cfg.BACKEND = args.backend |
| 89 | |
| 90 | if args.command == "complete": |
| 91 | result = complete( |
| 92 | args.path, |
| 93 | output_dir=getattr(args, 'output', None), |
| 94 | cms_name=getattr(args, 'cms_name', None), |
| 95 | cms_logo=getattr(args, 'cms_logo', None), |
| 96 | cms_color=getattr(args, 'cms_color', None), |
| 97 | ) |
| 98 | print(result) |
| 99 | elif args.command == "analyze": |
| 100 | print(analyze(args.path)) |
| 101 | elif args.command == "hugoify": |
| 102 | print(hugoify(args.path)) |
| 103 | elif args.command == "decapify": |
| 104 | print(decapify( |
| 105 | args.path, |
| 106 | cms_name=getattr(args, 'cms_name', None), |
| 107 | cms_logo=getattr(args, 'cms_logo', None), |
| 108 | cms_color=getattr(args, 'cms_color', None), |
| 109 | )) |
| 110 | elif args.command == "translate": |
| 111 | print(translate(args.path)) |
| 112 | elif args.command == "parser": |
| 113 | print(parse(args.path)) |
| 114 | elif args.command == "deploy": |
| 115 | print(deploy(args.path, args.zone)) |
| 116 | elif args.command == "cloudflare": |
| 117 | print(configure_cloudflare(args.path, args.zone)) |
| 118 | else: |
| 119 | parser.print_help() |
| 120 | |
| 121 | |
| 122 | if __name__ == "__main__": |
| 123 | main() |
| 124 |
| --- src/cli.py | |
| +++ src/cli.py | |
| @@ -9,10 +9,11 @@ | |
| 9 | python cli.py hugoify themes/revolve-hugo |
| 10 | python cli.py decapify output/revolve-hugo |
| 11 | """ |
| 12 | |
| 13 | import argparse |
| 14 | import logging |
| 15 | import sys |
| 16 | import os |
| 17 | |
| 18 | # Ensure src/ is on the path when called directly |
| 19 | sys.path.insert(0, os.path.dirname(__file__)) |
| @@ -61,12 +62,13 @@ | |
| 62 | decapify_parser.add_argument("--cms-name", default=None, help="Whitelabel CMS name (default: 'Content Manager')") |
| 63 | decapify_parser.add_argument("--cms-logo", default=None, help="Whitelabel logo URL") |
| 64 | decapify_parser.add_argument("--cms-color", default=None, help="Whitelabel top-bar hex color") |
| 65 | |
| 66 | # translate |
| 67 | translate_parser = subparsers.add_parser("translate", help="Translate content to another language") |
| 68 | translate_parser.add_argument("path", help="Path to the content file") |
| 69 | translate_parser.add_argument("--target-language", default="Spanish", help="Target language (default: Spanish)") |
| 70 | |
| 71 | # parse / lint |
| 72 | parser_parser = subparsers.add_parser("parser", help="Parse and lint (stub)") |
| 73 | parser_parser.add_argument("path", help="Path to the theme") |
| 74 | |
| @@ -80,44 +82,50 @@ | |
| 82 | cloudflare_parser.add_argument("path", help="Path to the site") |
| 83 | cloudflare_parser.add_argument("zone", help="Cloudflare zone") |
| 84 | |
| 85 | args = parser.parse_args() |
| 86 | |
| 87 | logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
| 88 | |
| 89 | # Override backend if specified on command line |
| 90 | if args.backend: |
| 91 | import config as cfg |
| 92 | cfg.BACKEND = args.backend |
| 93 | |
| 94 | try: |
| 95 | if args.command == "complete": |
| 96 | result = complete( |
| 97 | args.path, |
| 98 | output_dir=args.output, |
| 99 | cms_name=args.cms_name, |
| 100 | cms_logo=args.cms_logo, |
| 101 | cms_color=args.cms_color, |
| 102 | ) |
| 103 | print(result) |
| 104 | elif args.command == "analyze": |
| 105 | print(analyze(args.path)) |
| 106 | elif args.command == "hugoify": |
| 107 | print(hugoify(args.path)) |
| 108 | elif args.command == "decapify": |
| 109 | print(decapify( |
| 110 | args.path, |
| 111 | cms_name=args.cms_name, |
| 112 | cms_logo=args.cms_logo, |
| 113 | cms_color=args.cms_color, |
| 114 | )) |
| 115 | elif args.command == "translate": |
| 116 | print(translate(args.path, target_language=args.target_language)) |
| 117 | elif args.command == "parser": |
| 118 | print(parse(args.path)) |
| 119 | elif args.command == "deploy": |
| 120 | print(deploy(args.path, args.zone)) |
| 121 | elif args.command == "cloudflare": |
| 122 | print(configure_cloudflare(args.path, args.zone)) |
| 123 | else: |
| 124 | parser.print_help() |
| 125 | except (ValueError, EnvironmentError) as e: |
| 126 | print(f"Error: {e}", file=sys.stderr) |
| 127 | sys.exit(1) |
| 128 | |
| 129 | |
| 130 | if __name__ == "__main__": |
| 131 | main() |
| 132 |