teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

エラー条件の記載がなかった為。

2019/04/05 06:45

投稿

sou00
sou00

スコア13

title CHANGED
File without changes
body CHANGED
@@ -20,4 +20,14 @@
20
20
  test.py -d path
21
21
 
22
22
  [パターン5]
23
- test.py -d path -c count
23
+ test.py -d path -c count
24
+
25
+ 上記の5パターン以外の引数の組み合わせではエラーとしたいです。
26
+
27
+ [エラーパターン例]
28
+ test.py -d path -f file1 ・・・「-d」と[-f」の同時指定によりエラー
29
+ test.py -c count ・・・「-c」の単独指定によりエラー
30
+ test.py file1 file2 -f file3 file4 ・・・オプション無しfileと[-f」の同時指定によりエラー
31
+
32
+ 単純な引数排他ではparser.add_mutually_exclusive_groupを使用すればいいと思うのですが、
33
+ 「-c」は「-d」とセットにするやり方が分かりませんでした。

1

コマンドライン引数の記載間違いを修正

2019/04/05 06:45

投稿

sou00
sou00

スコア13

title CHANGED
File without changes
body CHANGED
@@ -5,7 +5,7 @@
5
5
  以下のようなコマンドライン引数パターンのみを許容するコーディング方法が分かりません。
6
6
  どのようにコーディングすればよろしいでしょうか?
7
7
 
8
- test.py [-d path [-c count]|-f file...] [file...]
8
+ test.py [-d path [-c count]|-f file...|file...]
9
9
 
10
10
  [パターン1]
11
11
  test.py (引数無し)