wizlib 3.1.0__tar.gz → 3.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wizlib might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 3.1.0
3
+ Version: 3.1.1
4
4
  Summary: Framework for flexible and powerful command-line applications
5
5
  License: MIT
6
6
  Author: Steampunk Wizard
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wizlib"
3
- version = "3.1.0"
3
+ version = "3.1.1"
4
4
  description = "Framework for flexible and powerful command-line applications"
5
5
  authors = ["Steampunk Wizard <wizlib@steampunkwizard.ca>"]
6
6
  license = "MIT"
@@ -1,3 +1,4 @@
1
+ from argparse import ArgumentError
1
2
  import sys
2
3
  from dataclasses import dataclass
3
4
  import os
@@ -6,7 +7,7 @@ from pathlib import Path
6
7
  from wizlib.class_family import ClassFamily
7
8
  from wizlib.command import WizHelpCommand
8
9
  from wizlib.super_wrapper import SuperWrapper
9
- from wizlib.parser import WizParser
10
+ from wizlib.parser import WizArgumentError, WizParser
10
11
  from wizlib.ui import UI
11
12
 
12
13
 
@@ -44,7 +45,12 @@ class WizApp:
44
45
  """Call this from a Python entrypoint"""
45
46
  try:
46
47
  cls.initialize()
47
- ns = cls.parser.parse_args(args)
48
+ try:
49
+ ns = cls.parser.parse_args(args)
50
+ if (ns.command is None) and (not hasattr(ns, 'help')):
51
+ ns = cls.dparser.parse_args(args)
52
+ except ArgumentError as e:
53
+ ns = cls.dparser.parse_args(args)
48
54
  app = cls(**vars(ns))
49
55
  app.run(**vars(ns))
50
56
  except AppCancellation as cancellation:
@@ -63,14 +69,17 @@ class WizApp:
63
69
  def initialize(cls):
64
70
  """Set up the parser for the app class"""
65
71
  cls.parser = WizParser(prog=cls.name)
66
- for handler in cls.handlers:
67
- handler.add_args(cls.parser)
68
72
  subparsers = cls.parser.add_subparsers(dest='command')
69
73
  for command in cls.base.family_members('name'):
70
74
  key = command.get_member_attr('key')
71
75
  aliases = [key] if key else []
72
76
  subparser = subparsers.add_parser(command.name, aliases=aliases)
77
+ if command.name == cls.base.default:
78
+ cls.dparser = subparser
73
79
  command.add_args(subparser)
80
+ for handler in cls.handlers:
81
+ handler.add_args(cls.parser)
82
+ handler.add_args(cls.dparser)
74
83
 
75
84
  def __init__(self, **vals):
76
85
  """Create the app. Only interested in the handlers from the parsed
@@ -86,12 +95,13 @@ class WizApp:
86
95
  the command itself and its specific arguments from the values passed
87
96
  in."""
88
97
  if 'help' in vals:
89
- return WizHelpCommand(**vals)
90
- c = 'command'
91
- cname = (vals.pop(c) if c in vals else None) or self.base.default
92
- ccls = self.base.family_member('name', cname)
93
- if not ccls:
94
- raise Exception(f"Unknown command {cname}")
98
+ ccls = WizHelpCommand
99
+ else:
100
+ c = 'command'
101
+ cname = (vals.pop(c) if c in vals else None) or self.base.default
102
+ ccls = self.base.family_member('name', cname)
103
+ if not ccls:
104
+ raise Exception(f"Unknown command {cname}")
95
105
  command = ccls(self, **vals)
96
106
  result = command.execute()
97
107
  if result:
@@ -14,6 +14,8 @@ import sys
14
14
  import os
15
15
 
16
16
 
17
+ # We found the help process a little clumsy
18
+
17
19
  class WizHelpAction(Action):
18
20
 
19
21
  def __init__(self,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes