|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +def setup_config_parser(parent_parser): |
| 5 | + # Config subcommand: Create subparsers for config types |
| 6 | + parser = parent_parser.add_subparsers(title="config_type", dest="config_type") |
| 7 | + |
| 8 | + # Config subcommand: llm |
| 9 | + llm_config_parser = parser.add_parser("llm", help="Configure LLM settings.") |
| 10 | + llm_config_parser.add_argument("--model", required=True, help="LLM model to use") |
| 11 | + llm_config_parser.add_argument("--api-base", help="API base URL for the LLM service") |
| 12 | + llm_config_parser.add_argument("--api-key", help="API key for the LLM service") |
| 13 | + |
| 14 | + # Config subcommand: llm-web |
| 15 | + parser.add_parser("llm-web", help="Configure LLM settings through a web interface") |
| 16 | + |
| 17 | + # Config subcommand: jira |
| 18 | + jira_config_parser = parser.add_parser("jira", help="Configure JIRA settings.") |
| 19 | + jira_config_parser.add_argument("--url", required=True, help="JIRA base URL") |
| 20 | + jira_config_parser.add_argument("--username", required=True, help="JIRA username or email") |
| 21 | + jira_config_parser.add_argument("--api-token", required=True, help="JIRA API token") |
| 22 | + jira_config_parser.add_argument("--verify", action="store_true", help="Verify JIRA connection") |
| 23 | + |
| 24 | + # Config subcommand: jira-web |
| 25 | + parser.add_parser("jira-web", help="Configure JIRA settings through a web interface") |
| 26 | + |
| 27 | + # Add all other necessary arguments for config command |
| 28 | + |
| 29 | +def handle_config(args): |
| 30 | + # Only import dependencies needed for config functionality here |
| 31 | + from penify_hook.commands.config_commands import save_llm_config |
| 32 | + from penify_hook.jira_client import JiraClient # Import moved here |
| 33 | + from penify_hook.commands.config_commands import config_jira_web, config_llm_web, save_jira_config |
| 34 | + |
| 35 | + if args.config_type == "llm": |
| 36 | + save_llm_config(args.model, args.api_base, args.api_key) |
| 37 | + print(f"LLM configuration set: Model={args.model}, API Base={args.api_base or 'default'}") |
| 38 | + |
| 39 | + elif args.config_type == "llm-web": |
| 40 | + config_llm_web() |
| 41 | + |
| 42 | + elif args.config_type == "jira": |
| 43 | + save_jira_config(args.url, args.username, args.api_token) |
| 44 | + print(f"JIRA configuration set: URL={args.url}, Username={args.username}") |
| 45 | + |
| 46 | + # Verify connection if requested |
| 47 | + if args.verify: |
| 48 | + if JiraClient: |
| 49 | + jira_client = JiraClient( |
| 50 | + jira_url=args.url, |
| 51 | + jira_user=args.username, |
| 52 | + jira_api_token=args.api_token |
| 53 | + ) |
| 54 | + if jira_client.is_connected(): |
| 55 | + print("JIRA connection verified successfully!") |
| 56 | + else: |
| 57 | + print("Failed to connect to JIRA. Please check your credentials.") |
| 58 | + else: |
| 59 | + print("JIRA package not installed. Cannot verify connection.") |
| 60 | + |
| 61 | + elif args.config_type == "jira-web": |
| 62 | + config_jira_web() |
| 63 | + |
| 64 | + else: |
| 65 | + print("Please specify a config type: llm, llm-web, jira, or jira-web") |
| 66 | + return 1 |
| 67 | + |
| 68 | + return 0 |
0 commit comments