Skip to content

Commit 18b2827

Browse files
authored
Merge pull request #78 from kairu-ms/fix-more-bugs
Support `singular_options` by default.
2 parents d5f8ed8 + 78e5a7d commit 18b2827

File tree

7 files changed

+70
-41
lines changed

7 files changed

+70
-41
lines changed

src/aaz_dev/cli/controller/az_arg_group_generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ def parse_arg_help(help):
168168
assert isinstance(help, CMDArgumentHelp)
169169
if not help.lines and not help.ref_commands:
170170
if not help.short:
171-
raise exceptions.InvalidAPIUsage("Invalid argument help, short summery is miss.")
171+
raise exceptions.InvalidAPIUsage("Invalid argument help, short summary is miss.")
172172
return help.short
173173
h = {
174-
"short-summery": help.short
174+
"short-summary": help.short
175175
}
176176
if help.lines:
177-
h["long-summery"] = '\n'.join(help.lines)
177+
h["long-summary"] = '\n'.join(help.lines)
178178
if help.ref_commands:
179179
h["populator-commands"] = [*help.ref_commands]
180+
return h
180181

181182

182183
def parse_arg_enum(enum):

src/aaz_dev/command/controller/specs_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,14 @@ def verify_command_tree(self):
393393
if not group.help or not group.help.short:
394394
details[' '.join(group.names)] = {
395395
'type': 'group',
396-
'help': "Miss short summery."
396+
'help': "Miss short summary."
397397
}
398398

399399
for cmd in self.iter_commands():
400400
if not cmd.help or not cmd.help.short:
401401
details[' '.join(cmd.names)] = {
402402
'type': 'command',
403-
'help': "Miss short summery."
403+
'help': "Miss short summary."
404404
}
405405
if details:
406406
raise exceptions.VerificationError(message="Invalid Command Tree", details=details)

src/aaz_dev/command/model/configuration/_arg_builder.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import re
22

3-
# import inflect
3+
import inflect
44
from utils.case import to_camel_case
55

66
from ._arg import CMDArg, CMDArgBase, CMDArgumentHelp, CMDArgEnum, CMDArgDefault, CMDBooleanArgBase, \
77
CMDArgBlank, CMDObjectArgAdditionalProperties
88
from ._format import CMDFormat
99
from ._schema import CMDObjectSchema, CMDSchema, CMDSchemaBase, CMDObjectSchemaBase, CMDObjectSchemaDiscriminator, \
10-
CMDArraySchemaBase, CMDObjectSchemaAdditionalProperties, CMDResourceIdSchema
10+
CMDArraySchemaBase, CMDObjectSchemaAdditionalProperties, CMDResourceIdSchema, CMDArraySchema
1111

1212

1313
class CMDArgBuilder:
14-
# _inflect_engine = inflect.engine()
14+
_inflect_engine = inflect.engine()
1515

1616
@classmethod
1717
def new_builder(cls, schema, parent=None, var_prefix=None, ref_args=None, ref_arg=None, is_update_action=False):
@@ -275,16 +275,14 @@ def get_singular_options(self):
275275
singular_options = getattr(self._ref_arg, 'singular_options', None)
276276
if singular_options:
277277
return [*singular_options]
278-
return None
279278

280-
# disable to auto generate singular option by default
281-
# if not isinstance(self.schema, CMDArraySchema):
282-
# raise NotImplementedError()
283-
# opt_name = self._build_option_name(self.schema.name.replace('$', '')) # some schema name may contain $
284-
# singular_opt_name = self._inflect_engine.singular_noun(opt_name) or opt_name
285-
# if singular_opt_name != opt_name:
286-
# return [singular_opt_name, ]
287-
# return None
279+
if isinstance(self.schema, CMDArraySchema):
280+
opt_name = self._build_option_name(self.schema.name.replace('$', '')) # some schema name may contain $
281+
singular_opt_name = self._inflect_engine.singular_noun(opt_name) or opt_name
282+
if singular_opt_name != opt_name:
283+
return [singular_opt_name, ]
284+
# TODO: support CMDClsSchema when it reference from array schema
285+
return None
288286

289287
def get_help(self):
290288
if self._ref_arg:

src/aaz_dev/docs/Docs/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ The data of command tree is in [Commands/tree.json](https://github.com/kairu-ms/
193193

194194
![CommandTreeNode](/Docs/images/aaz_command_tree_folder.png)
195195

196-
Each folder represents each node of the tree and also represents a command group. Its readme.md file shows the summery, subgroups and commands of this group. And the links in the file help us to browse quickly.
196+
Each folder represents each node of the tree and also represents a command group. Its readme.md file shows the summary, subgroups and commands of this group. And the links in the file help us to browse quickly.
197197

198198
![CommandTreeLeaf](/Docs/images/aaz_command_tree_command_md.png)
199199

200-
Each Markdown files starts with '_' represents each leaf of the tree which also represents a command. Its contains the summery, versions and examples of this command. And each version links to a command configuration in Resources folder.
200+
Each Markdown files starts with '_' represents each leaf of the tree which also represents a command. Its contains the summary, versions and examples of this command. And each version links to a command configuration in Resources folder.
201201

202202
### 5.2 Command Configuration
203203

src/web/src/views/workspace/WSEditorCommandArgumentsContent.tsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function ArgNavBar(props: {
354354
}
355355

356356
const spliceArgOptionsString = (arg: CMDArg, depth: number) => {
357-
return arg.options.map((option) => {
357+
let optionsString = arg.options.map((option) => {
358358
if (depth === 0) {
359359
if (option.length === 1) {
360360
return '-' + option;
@@ -364,7 +364,37 @@ const spliceArgOptionsString = (arg: CMDArg, depth: number) => {
364364
} else {
365365
return '.' + option;
366366
}
367-
}).join(" ")
367+
}).join(" ");
368+
369+
if ((arg as CMDArrayArg).singularOptions) {
370+
let singularOptionString = (arg as CMDArrayArg).singularOptions!.map((option) => {
371+
if (depth === 0) {
372+
if (option.length === 1) {
373+
return '-' + option;
374+
} else {
375+
return '--' + option;
376+
}
377+
} else {
378+
return '.' + option;
379+
}
380+
}).join(" ");
381+
optionsString += ` (${singularOptionString})`;
382+
} else if ((arg as CMDClsArg).singularOptions) {
383+
let singularOptionString = (arg as CMDArrayArg).singularOptions!.map((option) => {
384+
if (depth === 0) {
385+
if (option.length === 1) {
386+
return '-' + option;
387+
} else {
388+
return '--' + option;
389+
}
390+
} else {
391+
return '.' + option;
392+
}
393+
}).join(" ");
394+
optionsString += ` (${singularOptionString})`;
395+
}
396+
397+
return optionsString;
368398
}
369399

370400

@@ -473,7 +503,7 @@ function ArgumentReviewer(props: {
473503
{`Choices: ` + choices.join(', ')}
474504
</ArgChoicesTypography>}
475505
{props.arg.help?.short && <ShortHelpTypography sx={{ ml: 6, mt: 1.5 }}> {props.arg.help?.short} </ShortHelpTypography>}
476-
{!(props.arg.help?.short) && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add argument short summery!</ShortHelpPlaceHolderTypography>}
506+
{!(props.arg.help?.short) && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add argument short summary!</ShortHelpPlaceHolderTypography>}
477507
{props.arg.help?.lines && <Box sx={{ ml: 6, mt: 1, mb: 1 }}>
478508
{props.arg.help.lines.map((line, idx) => (<LongHelpTypography key={idx}>{line}</LongHelpTypography>))}
479509
</Box>}
@@ -541,7 +571,7 @@ function ArgumentDialog(props: {
541571
}
542572

543573
if (sHelp.length < 1) {
544-
setInvalidText(`Field 'Short Summery' is required.`)
574+
setInvalidText(`Field 'Short Summary' is required.`)
545575
return undefined
546576
}
547577

@@ -760,8 +790,8 @@ function ArgumentDialog(props: {
760790
/>
761791
</>}
762792
<TextField
763-
id="shortSummery"
764-
label="Short Summery"
793+
id="shortSummary"
794+
label="Short Summary"
765795
type="text"
766796
fullWidth
767797
variant='standard'
@@ -773,8 +803,8 @@ function ArgumentDialog(props: {
773803
required
774804
/>
775805
<TextField
776-
id="longSummery"
777-
label="Long Summery"
806+
id="longSummary"
807+
label="Long Summary"
778808
helperText="Please add long summer in lines."
779809
type="text"
780810
fullWidth
@@ -1098,7 +1128,7 @@ const PropHiddenArgOptionTypography = styled(Typography)<TypographyProps>(({ the
10981128
fontWeight: 700,
10991129
}))
11001130

1101-
const PropArgShortSummeryTypography = styled(Typography)<TypographyProps>(({ theme }) => ({
1131+
const PropArgShortSummaryTypography = styled(Typography)<TypographyProps>(({ theme }) => ({
11021132
color: theme.palette.primary.main,
11031133
fontFamily: "'Roboto Condensed', sans-serif",
11041134
fontSize: 14,
@@ -1197,7 +1227,7 @@ function ArgumentPropsReviewer(props: {
11971227
{arg.help && <Box sx={{
11981228
ml: 4
11991229
}}>
1200-
<PropArgShortSummeryTypography>{arg.help.short}</PropArgShortSummeryTypography>
1230+
<PropArgShortSummaryTypography>{arg.help.short}</PropArgShortSummaryTypography>
12011231
</Box>}
12021232
</Box>
12031233

src/web/src/views/workspace/WSEditorCommandContent.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class WSEditorCommandContent extends React.Component<WSEditorCommandContentProps
287287
{name}
288288
</NameTypography>
289289
{shortHelp && <ShortHelpTypography sx={{ ml: 6, mt: 2 }}> {shortHelp} </ShortHelpTypography>}
290-
{!shortHelp && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add command short summery!</ShortHelpPlaceHolderTypography>}
290+
{!shortHelp && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add command short summary!</ShortHelpPlaceHolderTypography>}
291291
{longHelp && <Box sx={{ ml: 6, mt: 1, mb: 1 }}>
292292
{lines.map((line, idx) => (<LongHelpTypography key={idx}>{line}</LongHelpTypography>))}
293293
</Box>}
@@ -562,7 +562,7 @@ class CommandDialog extends React.Component<CommandDialogProps, CommandDialogSta
562562

563563
if (shortHelp.length < 1) {
564564
this.setState({
565-
invalidText: `Field 'Short Summery' is required.`
565+
invalidText: `Field 'Short Summary' is required.`
566566
})
567567
return
568568
}
@@ -668,8 +668,8 @@ class CommandDialog extends React.Component<CommandDialogProps, CommandDialogSta
668668
required
669669
/>
670670
<TextField
671-
id="shortSummery"
672-
label="Short Summery"
671+
id="shortSummary"
672+
label="Short Summary"
673673
type="text"
674674
fullWidth
675675
variant='standard'
@@ -683,8 +683,8 @@ class CommandDialog extends React.Component<CommandDialogProps, CommandDialogSta
683683
required
684684
/>
685685
<TextField
686-
id="longSummery"
687-
label="Long Summery"
686+
id="longSummary"
687+
label="Long Summary"
688688
helperText="Please add long summer in lines."
689689
type="text"
690690
fullWidth

src/web/src/views/workspace/WSEditorCommandGroupContent.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class WSEditorCommandGroupContent extends React.Component<WSEditorCommandGroupCo
147147
{name}
148148
</NameTypography>
149149
{shortHelp && <ShortHelpTypography sx={{ ml: 6, mt: 2 }}> {shortHelp} </ShortHelpTypography>}
150-
{!shortHelp && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add command group short summery!</ShortHelpPlaceHolderTypography>}
150+
{!shortHelp && <ShortHelpPlaceHolderTypography sx={{ ml: 6, mt: 2 }}>Please add command group short summary!</ShortHelpPlaceHolderTypography>}
151151
{longHelp && <Box sx={{ ml: 6, mt: 1, mb: 1 }}>
152152
{lines.map((line, idx) => (<LongHelpTypography key={idx}>{line}</LongHelpTypography>))}
153153
</Box>}
@@ -308,7 +308,7 @@ class CommandGroupDialog extends React.Component<CommandGroupDialogProps, Comman
308308

309309
if (shortHelp.length < 1) {
310310
this.setState({
311-
invalidText: `Field 'Short Summery' is required.`
311+
invalidText: `Field 'Short Summary' is required.`
312312
})
313313
}
314314

@@ -414,8 +414,8 @@ class CommandGroupDialog extends React.Component<CommandGroupDialogProps, Comman
414414
required
415415
/>
416416
<TextField
417-
id="shortSummery"
418-
label="Short Summery"
417+
id="shortSummary"
418+
label="Short Summary"
419419
type="text"
420420
fullWidth
421421
variant='standard'
@@ -429,8 +429,8 @@ class CommandGroupDialog extends React.Component<CommandGroupDialogProps, Comman
429429
required
430430
/>
431431
<TextField
432-
id="longSummery"
433-
label="Long Summery"
432+
id="longSummary"
433+
label="Long Summary"
434434
helperText="Please add long summer in lines."
435435
type="text"
436436
fullWidth

0 commit comments

Comments
 (0)