ara-cli 0.1.9.75__py3-none-any.whl → 0.1.9.77__py3-none-any.whl

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.
ara_cli/__main__.py CHANGED
@@ -19,7 +19,7 @@ from ara_cli.ara_command_action import (
19
19
  set_user_action,
20
20
  classifier_directory_action,
21
21
  scan_action,
22
- autofix_action
22
+ autofix_action,
23
23
  )
24
24
  import argcomplete
25
25
  import sys
@@ -44,7 +44,7 @@ def define_action_mapping():
44
44
  "set-user": set_user_action,
45
45
  "classifier-directory": classifier_directory_action,
46
46
  "scan": scan_action,
47
- "autofix": autofix_action
47
+ "autofix": autofix_action,
48
48
  }
49
49
 
50
50
 
@@ -54,14 +54,21 @@ def handle_invalid_action(args):
54
54
 
55
55
  def cli():
56
56
  parser = action_parser()
57
- parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version__}')
57
+
58
+ # Show examples when help is called
59
+ if any(arg in sys.argv for arg in ["-h", "--help"]):
60
+ parser.add_examples = True
61
+
62
+ parser.add_argument(
63
+ "-v", "--version", action="version", version=f"%(prog)s {__version__}"
64
+ )
58
65
 
59
66
  action_mapping = define_action_mapping()
60
67
 
61
68
  argcomplete.autocomplete(parser)
62
69
 
63
70
  args = parser.parse_args()
64
- if not hasattr(args, 'action') or not args.action:
71
+ if not hasattr(args, "action") or not args.action:
65
72
  parser.print_help()
66
73
  return
67
74
  action = action_mapping.get(args.action, handle_invalid_action)
@@ -1,6 +1,11 @@
1
1
  import argparse
2
+ import sys
2
3
  from ara_cli.classifier import Classifier
3
- from ara_cli.commandline_completer import ArtefactCompleter, ParentNameCompleter, StatusCompleter
4
+ from ara_cli.commandline_completer import (
5
+ ArtefactCompleter,
6
+ ParentNameCompleter,
7
+ StatusCompleter,
8
+ )
4
9
  from ara_cli.template_manager import SpecificationBreakdownAspects
5
10
 
6
11
 
@@ -9,33 +14,71 @@ aspects = SpecificationBreakdownAspects.VALID_ASPECTS
9
14
 
10
15
 
11
16
  def create_parser(subparsers):
12
- create_parser = subparsers.add_parser("create", help="Create a classified artefact with data directory")
13
- create_parser.add_argument("classifier", choices=classifiers, help="Classifier that also serves as file extension for the artefact file to be created. Valid Classifiers are: businessgoal, capability, keyfeature, feature, epic, userstory, example, task")
14
- create_parser.add_argument("parameter", help="Artefact name that serves as filename").completer = ArtefactCompleter()
17
+ create_parser = subparsers.add_parser(
18
+ "create", help="Create a classified artefact with data directory"
19
+ )
20
+ create_parser.add_argument(
21
+ "classifier",
22
+ choices=classifiers,
23
+ help="Classifier that also serves as file extension for the artefact file to be created. Valid Classifiers are: businessgoal, capability, keyfeature, feature, epic, userstory, example, task",
24
+ )
25
+ create_parser.add_argument(
26
+ "parameter", help="Artefact name that serves as filename"
27
+ ).completer = ArtefactCompleter()
15
28
 
16
29
  option_parser = create_parser.add_subparsers(dest="option")
17
30
 
18
31
  contribution_parser = option_parser.add_parser("contributes-to")
19
- contribution_parser.add_argument("parent_classifier", choices=classifiers, help="Classifier of the parent")
20
- contribution_parser.add_argument("parent_name", help="Name of a parent artefact").completer = ParentNameCompleter()
32
+ contribution_parser.add_argument(
33
+ "parent_classifier", choices=classifiers, help="Classifier of the parent"
34
+ )
35
+ contribution_parser.add_argument(
36
+ "parent_name", help="Name of a parent artefact"
37
+ ).completer = ParentNameCompleter()
21
38
  contribution_parser.add_argument("-r", "--rule", dest="rule", action="store")
22
39
 
23
40
  aspect_parser = option_parser.add_parser("aspect")
24
- aspect_parser.add_argument("aspect", choices=aspects, help="Adds additional specification breakdown aspects in data directory.")
41
+ aspect_parser.add_argument(
42
+ "aspect",
43
+ choices=aspects,
44
+ help="Adds additional specification breakdown aspects in data directory.",
45
+ )
25
46
 
26
47
 
27
48
  def delete_parser(subparsers):
28
- delete_parser = subparsers.add_parser("delete", help="Delete an artefact file including its data directory")
29
- delete_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact to be deleted")
30
- delete_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
31
- delete_parser.add_argument("-f", "--force", dest="force", action="store_true", help="ignore nonexistent files and arguments, never prompt")
49
+ delete_parser = subparsers.add_parser(
50
+ "delete", help="Delete an artefact file including its data directory"
51
+ )
52
+ delete_parser.add_argument(
53
+ "classifier",
54
+ choices=classifiers,
55
+ help="Classifier of the artefact to be deleted",
56
+ )
57
+ delete_parser.add_argument(
58
+ "parameter", help="Filename of artefact"
59
+ ).completer = ArtefactCompleter()
60
+ delete_parser.add_argument(
61
+ "-f",
62
+ "--force",
63
+ dest="force",
64
+ action="store_true",
65
+ help="ignore nonexistent files and arguments, never prompt",
66
+ )
32
67
 
33
68
 
34
69
  def rename_parser(subparsers):
35
- rename_parser = subparsers.add_parser("rename", help="Rename a classified artefact and its data directory")
36
- rename_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact")
37
- rename_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
38
- rename_parser.add_argument("aspect", help="New artefact name and new data directory name")
70
+ rename_parser = subparsers.add_parser(
71
+ "rename", help="Rename a classified artefact and its data directory"
72
+ )
73
+ rename_parser.add_argument(
74
+ "classifier", choices=classifiers, help="Classifier of the artefact"
75
+ )
76
+ rename_parser.add_argument(
77
+ "parameter", help="Filename of artefact"
78
+ ).completer = ArtefactCompleter()
79
+ rename_parser.add_argument(
80
+ "aspect", help="New artefact name and new data directory name"
81
+ )
39
82
 
40
83
 
41
84
  def add_filter_flags(parser):
@@ -44,27 +87,27 @@ def add_filter_flags(parser):
44
87
  "--include-content",
45
88
  nargs="+",
46
89
  default=None,
47
- help="filter for files which include given content"
90
+ help="filter for files which include given content",
48
91
  )
49
92
  parser.add_argument(
50
93
  "-E",
51
94
  "--exclude-content",
52
95
  nargs="+",
53
96
  default=None,
54
- help="filter for files which do not include given content"
97
+ help="filter for files which do not include given content",
55
98
  )
56
99
 
57
100
  parser.add_argument(
58
101
  "--include-tags",
59
102
  nargs="+",
60
103
  default=None,
61
- help="filter for files which include given tags"
104
+ help="filter for files which include given tags",
62
105
  )
63
106
  parser.add_argument(
64
107
  "--exclude-tags",
65
108
  nargs="+",
66
109
  default=None,
67
- help="filter for files which do not include given tags"
110
+ help="filter for files which do not include given tags",
68
111
  )
69
112
 
70
113
  extension_group = parser.add_mutually_exclusive_group()
@@ -73,16 +116,16 @@ def add_filter_flags(parser):
73
116
  "--include-extension",
74
117
  "--include-classifier",
75
118
  dest="include_extension",
76
- nargs='+',
77
- help='list of extensions to include in listing'
119
+ nargs="+",
120
+ help="list of extensions to include in listing",
78
121
  )
79
122
  extension_group.add_argument(
80
123
  "-e",
81
124
  "--exclude-extension",
82
125
  "--exclude-classifier",
83
126
  dest="exclude_extension",
84
- nargs='+',
85
- help='list of extensions to exclude from listing'
127
+ nargs="+",
128
+ help="list of extensions to exclude from listing",
86
129
  )
87
130
 
88
131
 
@@ -94,134 +137,260 @@ def list_parser(subparsers):
94
137
 
95
138
  argument_group = list_parser.add_mutually_exclusive_group()
96
139
  argument_group.add_argument(
97
- "-b", "--branch",
140
+ "-b",
141
+ "--branch",
98
142
  dest="branch_args",
99
143
  nargs=2,
100
144
  metavar=("classifier", "artefact_name"),
101
- help="List artefacts in the parent chain of the artefact with specified classifier and artefact_name"
145
+ help="List artefacts in the parent chain of the artefact with specified classifier and artefact_name",
102
146
  )
103
147
  argument_group.add_argument(
104
- "-c", "--children",
148
+ "-c",
149
+ "--children",
105
150
  dest="children_args",
106
151
  nargs=2,
107
152
  metavar=("classifier", "artefact_name"),
108
- help="List child artefacts of the artefact with specified classifier and artefact_name"
153
+ help="List child artefacts of the artefact with specified classifier and artefact_name",
109
154
  )
110
155
  argument_group.add_argument(
111
- "-d", "--data",
156
+ "-d",
157
+ "--data",
112
158
  dest="data_args",
113
159
  nargs=2,
114
160
  metavar=("classifier", "artefact_name"),
115
- help="List file in the data directory of the artefact with specified classifier and artefact_name"
161
+ help="List file in the data directory of the artefact with specified classifier and artefact_name",
116
162
  )
117
163
 
118
164
  list_parser.set_defaults(
119
- branch_args=(None, None),
120
- children_args=(None, None),
121
- data_args=(None, None)
165
+ branch_args=(None, None), children_args=(None, None), data_args=(None, None)
122
166
  )
123
167
 
124
168
 
125
169
  def list_tags_parser(subparsers):
126
170
  tags_parser = subparsers.add_parser("list-tags", help="Show tags")
127
- tags_parser.add_argument("--json", "-j", help="Output tags as JSON", action=argparse.BooleanOptionalAction)
128
- tags_parser.add_argument("--include-classifier", choices=classifiers, help="Show tags for an artefact type")
129
- tags_parser.add_argument("--exclude_classifier", choices=classifiers, help="Show tags for an artefact type")
130
- tags_parser.add_argument("--filtered-extra-column", action="store_true", help="Filter tags for extra column")
171
+ tags_parser.add_argument(
172
+ "--json",
173
+ "-j",
174
+ help="Output tags as JSON",
175
+ action=argparse.BooleanOptionalAction,
176
+ )
177
+ tags_parser.add_argument(
178
+ "--include-classifier",
179
+ choices=classifiers,
180
+ help="Show tags for an artefact type",
181
+ )
182
+ tags_parser.add_argument(
183
+ "--exclude_classifier",
184
+ choices=classifiers,
185
+ help="Show tags for an artefact type",
186
+ )
187
+ tags_parser.add_argument(
188
+ "--filtered-extra-column",
189
+ action="store_true",
190
+ help="Filter tags for extra column",
191
+ )
131
192
 
132
193
 
133
194
  def add_chat_arguments(chat_parser):
134
- chat_parser.add_argument("chat_name", help="Optional name for a specific chat. Pass the .md file to continue an existing chat", nargs='?', default=None)
195
+ chat_parser.add_argument(
196
+ "chat_name",
197
+ help="Optional name for a specific chat. Pass the .md file to continue an existing chat",
198
+ nargs="?",
199
+ default=None,
200
+ )
135
201
 
136
- chat_parser.add_argument("-r", "--reset", dest="reset", action=argparse.BooleanOptionalAction, help="Reset the chat file if it exists")
202
+ chat_parser.add_argument(
203
+ "-r",
204
+ "--reset",
205
+ dest="reset",
206
+ action=argparse.BooleanOptionalAction,
207
+ help="Reset the chat file if it exists",
208
+ )
137
209
  chat_parser.set_defaults(reset=None)
138
210
 
139
- chat_parser.add_argument("--out", dest="output_mode", action="store_true", help="Output the contents of the chat file instead of entering interactive chat mode")
211
+ chat_parser.add_argument(
212
+ "--out",
213
+ dest="output_mode",
214
+ action="store_true",
215
+ help="Output the contents of the chat file instead of entering interactive chat mode",
216
+ )
140
217
 
141
- chat_parser.add_argument("--append", nargs='*', default=None, help="Append strings to the chat file")
218
+ chat_parser.add_argument(
219
+ "--append", nargs="*", default=None, help="Append strings to the chat file"
220
+ )
142
221
 
143
- chat_parser.add_argument("--restricted", dest="restricted", action=argparse.BooleanOptionalAction, help="Start with a limited set of commands")
222
+ chat_parser.add_argument(
223
+ "--restricted",
224
+ dest="restricted",
225
+ action=argparse.BooleanOptionalAction,
226
+ help="Start with a limited set of commands",
227
+ )
144
228
 
145
229
 
146
230
  def prompt_parser(subparsers):
147
- prompt_parser = subparsers.add_parser("prompt", help="Base command for prompt interaction mode")
231
+ prompt_parser = subparsers.add_parser(
232
+ "prompt", help="Base command for prompt interaction mode"
233
+ )
148
234
 
149
- steps = ['init', 'load', 'send', 'load-and-send', 'extract', 'update', 'chat', 'init-rag']
150
- steps_parser = prompt_parser.add_subparsers(dest='steps')
235
+ steps = [
236
+ "init",
237
+ "load",
238
+ "send",
239
+ "load-and-send",
240
+ "extract",
241
+ "update",
242
+ "chat",
243
+ "init-rag",
244
+ ]
245
+ steps_parser = prompt_parser.add_subparsers(dest="steps")
151
246
  for step in steps:
152
247
  step_parser = steps_parser.add_parser(step)
153
- step_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact")
154
- step_parser.add_argument("parameter", help="Name of artefact data directory for prompt creation and interaction").completer = ArtefactCompleter()
155
- if step == 'chat':
248
+ step_parser.add_argument(
249
+ "classifier", choices=classifiers, help="Classifier of the artefact"
250
+ )
251
+ step_parser.add_argument(
252
+ "parameter",
253
+ help="Name of artefact data directory for prompt creation and interaction",
254
+ ).completer = ArtefactCompleter()
255
+ if step == "chat":
156
256
  add_chat_arguments(step_parser)
157
257
 
158
258
 
159
259
  def chat_parser(subparsers):
160
- chat_parser = subparsers.add_parser("chat", help="Command line chatbot. Chat control with SEND/s | RERUN/r | QUIT/q")
260
+ chat_parser = subparsers.add_parser(
261
+ "chat", help="Command line chatbot. Chat control with SEND/s | RERUN/r | QUIT/q"
262
+ )
161
263
  add_chat_arguments(chat_parser)
162
264
 
163
265
 
164
266
  def template_parser(subparsers):
165
- template_parser = subparsers.add_parser("template", help="Outputs a classified ara template in the terminal")
166
- template_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
267
+ template_parser = subparsers.add_parser(
268
+ "template", help="Outputs a classified ara template in the terminal"
269
+ )
270
+ template_parser.add_argument(
271
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
272
+ )
167
273
 
168
274
 
169
275
  def fetch_templates_parser(subparsers):
170
- subparsers.add_parser("fetch-templates", help="Fetches templates and stores them in .araconfig")
276
+ subparsers.add_parser(
277
+ "fetch-templates", help="Fetches templates and stores them in .araconfig"
278
+ )
171
279
 
172
280
 
173
281
  def read_parser(subparsers):
174
282
  read_parser = subparsers.add_parser("read", help="Reads contents of artefacts")
175
- read_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
176
- read_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
283
+ read_parser.add_argument(
284
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
285
+ )
286
+ read_parser.add_argument(
287
+ "parameter", help="Filename of artefact"
288
+ ).completer = ArtefactCompleter()
177
289
 
178
290
  branch_group = read_parser.add_mutually_exclusive_group()
179
- branch_group.add_argument("-b", "--branch", dest="read_mode", action="store_const", const="branch",
180
- help="Output the contents of artefacts in the parent chain")
181
- branch_group.add_argument("-c", "--children", dest="read_mode", action="store_const", const="children",
182
- help="Output the contents of child artefacts")
291
+ branch_group.add_argument(
292
+ "-b",
293
+ "--branch",
294
+ dest="read_mode",
295
+ action="store_const",
296
+ const="branch",
297
+ help="Output the contents of artefacts in the parent chain",
298
+ )
299
+ branch_group.add_argument(
300
+ "-c",
301
+ "--children",
302
+ dest="read_mode",
303
+ action="store_const",
304
+ const="children",
305
+ help="Output the contents of child artefacts",
306
+ )
183
307
 
184
308
  read_parser.set_defaults(read_mode=None)
185
309
 
186
310
 
187
311
  def reconnect_parser(subparsers):
188
- reconnect_parser = subparsers.add_parser("reconnect", help="Connect an artefact to a parent artefact")
189
- reconnect_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
190
- reconnect_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
191
- reconnect_parser.add_argument("parent_classifier", choices=classifiers, help="Classifier of the parent artefact type")
192
- reconnect_parser.add_argument("parent_name", help="Filename of parent artefact").completer = ParentNameCompleter()
312
+ reconnect_parser = subparsers.add_parser(
313
+ "reconnect", help="Connect an artefact to a parent artefact"
314
+ )
315
+ reconnect_parser.add_argument(
316
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
317
+ )
318
+ reconnect_parser.add_argument(
319
+ "parameter", help="Filename of artefact"
320
+ ).completer = ArtefactCompleter()
321
+ reconnect_parser.add_argument(
322
+ "parent_classifier",
323
+ choices=classifiers,
324
+ help="Classifier of the parent artefact type",
325
+ )
326
+ reconnect_parser.add_argument(
327
+ "parent_name", help="Filename of parent artefact"
328
+ ).completer = ParentNameCompleter()
193
329
  reconnect_parser.add_argument("-r", "--rule", dest="rule", action="store")
194
330
 
195
331
 
196
332
  def read_status_parser(subparsers):
197
- read_status_parser = subparsers.add_parser("read-status", help="Read status of an artefact by checking its tags")
198
- read_status_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
199
- read_status_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
333
+ read_status_parser = subparsers.add_parser(
334
+ "read-status", help="Read status of an artefact by checking its tags"
335
+ )
336
+ read_status_parser.add_argument(
337
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
338
+ )
339
+ read_status_parser.add_argument(
340
+ "parameter", help="Filename of artefact"
341
+ ).completer = ArtefactCompleter()
200
342
 
201
343
 
202
344
  def read_user_parser(subparsers):
203
- read_user_parser = subparsers.add_parser("read-user", help="Read user of an artefact by checking its tags")
204
- read_user_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
205
- read_user_parser.add_argument("parameter", help="Filename of artefact").completer = ArtefactCompleter()
345
+ read_user_parser = subparsers.add_parser(
346
+ "read-user", help="Read user of an artefact by checking its tags"
347
+ )
348
+ read_user_parser.add_argument(
349
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
350
+ )
351
+ read_user_parser.add_argument(
352
+ "parameter", help="Filename of artefact"
353
+ ).completer = ArtefactCompleter()
206
354
 
207
355
 
208
356
  def set_status_parser(subparsers):
209
- set_status_parser = subparsers.add_parser("set-status", help="Set the status of a task")
210
- set_status_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type, typically 'task'")
211
- set_status_parser.add_argument("parameter", help="Name of the task artefact").completer = ArtefactCompleter()
212
- set_status_parser.add_argument("new_status", help="New status to set for the task").completer = StatusCompleter()
357
+ set_status_parser = subparsers.add_parser(
358
+ "set-status", help="Set the status of a task"
359
+ )
360
+ set_status_parser.add_argument(
361
+ "classifier",
362
+ choices=classifiers,
363
+ help="Classifier of the artefact type, typically 'task'",
364
+ )
365
+ set_status_parser.add_argument(
366
+ "parameter", help="Name of the task artefact"
367
+ ).completer = ArtefactCompleter()
368
+ set_status_parser.add_argument(
369
+ "new_status", help="New status to set for the task"
370
+ ).completer = StatusCompleter()
213
371
 
214
372
 
215
373
  def set_user_parser(subparsers):
216
374
  set_user_parser = subparsers.add_parser("set-user", help="Set the user of a task")
217
- set_user_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type, typically 'task'")
218
- set_user_parser.add_argument("parameter", help="Name of the task artefact").completer = ArtefactCompleter()
375
+ set_user_parser.add_argument(
376
+ "classifier",
377
+ choices=classifiers,
378
+ help="Classifier of the artefact type, typically 'task'",
379
+ )
380
+ set_user_parser.add_argument(
381
+ "parameter", help="Name of the task artefact"
382
+ ).completer = ArtefactCompleter()
219
383
  set_user_parser.add_argument("new_user", help="New user to assign to the task")
220
384
 
221
385
 
222
386
  def classifier_directory_parser(subparsers):
223
- classifier_directory_parser = subparsers.add_parser("classifier-directory", help="Print the ara subdirectory for an artefact classifier")
224
- classifier_directory_parser.add_argument("classifier", choices=classifiers, help="Classifier of the artefact type")
387
+ classifier_directory_parser = subparsers.add_parser(
388
+ "classifier-directory",
389
+ help="Print the ara subdirectory for an artefact classifier",
390
+ )
391
+ classifier_directory_parser.add_argument(
392
+ "classifier", choices=classifiers, help="Classifier of the artefact type"
393
+ )
225
394
 
226
395
 
227
396
  def scan_parser(subparsers):
@@ -229,22 +398,38 @@ def scan_parser(subparsers):
229
398
 
230
399
 
231
400
  def autofix_parser(subparsers):
232
- autofix_parser = subparsers.add_parser("autofix", help="Fix ARA tree with llm models for scanned artefacts with ara scan command. By default three attemps for every file.")
233
- autofix_parser.add_argument("--single-pass", action="store_true", help="Run the autofix once for every scaned file.")
401
+ autofix_parser = subparsers.add_parser(
402
+ "autofix",
403
+ help="Fix ARA tree with llm models for scanned artefacts with ara scan command. By default three attemps for every file.",
404
+ )
405
+ autofix_parser.add_argument(
406
+ "--single-pass",
407
+ action="store_true",
408
+ help="Run the autofix once for every scaned file.",
409
+ )
234
410
  determinism_group = autofix_parser.add_mutually_exclusive_group()
235
- determinism_group.add_argument("--deterministic", "-d", action="store_true", help="Run only deterministic fixes e.g Title-FileName Mismatch fix")
236
- determinism_group.add_argument("--non-deterministic", "-nd", action="store_true", help="Run only non-deterministic fixes")
411
+ determinism_group.add_argument(
412
+ "--deterministic",
413
+ "-d",
414
+ action="store_true",
415
+ help="Run only deterministic fixes e.g Title-FileName Mismatch fix",
416
+ )
417
+ determinism_group.add_argument(
418
+ "--non-deterministic",
419
+ "-nd",
420
+ action="store_true",
421
+ help="Run only non-deterministic fixes",
422
+ )
237
423
 
238
424
 
239
425
  class CustomHelpFormatter(argparse.HelpFormatter):
426
+ def __init__(self, *args, **kwargs):
427
+ self.add_examples = kwargs.pop("add_examples", False)
428
+ super().__init__(*args, **kwargs)
429
+
240
430
  def format_help(self):
241
- from sys import argv
242
- # Get the default help message
243
431
  help_message = super().format_help()
244
-
245
- # Check if '-h' or '--help' is in the arguments
246
- if '-h' in argv or '--help' in argv:
247
- # Add custom examples or additional information
432
+ if self.add_examples:
248
433
  examples = (
249
434
  "\nValid classified artefacts are: businessgoal, vision, capability, keyfeature, feature, epic, userstory, example, feature, task.\n"
250
435
  "The default ara directory structure of classified artefact of the ara cli tool is:\n"
@@ -274,7 +459,7 @@ class CustomHelpFormatter(argparse.HelpFormatter):
274
459
  " > list artefact data with .md and .json file extensions ara list --data {classifier} {artefact_name} --include-extension .md .json\n"
275
460
  " > list everything but userstories ara list --exclude-extension .userstory\n"
276
461
  " > list all existing features: ara list --include-extension .feature\n"
277
- " > list all child artefacts contributing value to a parent artefact: ara list --include-content \"Contributes to {name_of_parent_artefact} {ara classifier_of_parent_artefact}\"\n"
462
+ ' > list all child artefacts contributing value to a parent artefact: ara list --include-content "Contributes to {name_of_parent_artefact} {ara classifier_of_parent_artefact}"\n'
278
463
  " > list tasks which contain 'example content' ara list --include-extension .task --include-content \"example content\"\n"
279
464
  " > list children artefacts of a userstory ara list --children userstory {name_of_userstory}\n"
280
465
  " > list parent artefacts of a userstory ara list --branch userstory {name_of_userstory}\n"
@@ -293,17 +478,40 @@ class CustomHelpFormatter(argparse.HelpFormatter):
293
478
  " > load selected templates in config_prompt_templates.md for the task {task_name}: ara prompt load task {task_name}\n"
294
479
  " > create and send configured prompt of the task {task_name} to the configured LLM: ara prompt send task {task_name}\n"
295
480
  " > extract the selected LLM response in task.exploration.md and save to disk: ara prompt extract task {task_name}\n"
296
-
297
481
  )
298
- # Combine the default help message with the examples
299
482
  return help_message + examples
300
-
301
483
  return help_message
302
484
 
303
485
 
486
+ class CustomArgumentParser(argparse.ArgumentParser):
487
+ def __init__(self, *args, **kwargs):
488
+ self.add_examples = False
489
+ kwargs["formatter_class"] = CustomHelpFormatter
490
+ super().__init__(*args, **kwargs)
491
+
492
+ def _get_formatter(self):
493
+ # Pass add_examples flag to formatter
494
+ return self.formatter_class(prog=self.prog, add_examples=self.add_examples)
495
+
496
+ def print_help(self, file=None):
497
+ # Use the formatter with the current add_examples
498
+ if file is None:
499
+ file = sys.stdout
500
+ file.write(self.format_help())
501
+ file.write("\n")
502
+
503
+ def error(self, message):
504
+ self.add_examples = True
505
+ sys.stderr.write(f"error: {message}\n")
506
+ self.print_help(sys.stderr)
507
+ sys.exit(2)
508
+
509
+
304
510
  def action_parser():
305
- # Use the CustomHelpFormatter here
306
- parser = argparse.ArgumentParser(description="The ara cli terminal tool is a management tool for classified ara artefacts.", formatter_class=CustomHelpFormatter)
511
+ # Use the CustomArgumentParser instead of argparse.ArgumentParser
512
+ parser = CustomArgumentParser(
513
+ description="The ara cli terminal tool is a management tool for classified ara artefacts."
514
+ )
307
515
 
308
516
  subparsers = parser.add_subparsers(dest="action", help="Action to perform")
309
517
  create_parser(subparsers)