File: 0006-Pass-command-line-arguments-as-explicit-parameter-to.patch

package info (click to toggle)
python-adventure 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 760 kB
  • ctags: 327
  • sloc: python: 1,991; makefile: 36; sh: 33
file content (51 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Description: Pass command-line arguments as explicit parameter to ‘main’.
Author: Ben Finney <ben+python@benfinney.id.au>
Last-Update: 2016-04-13

diff --git a/adventure/__main__.py b/adventure/__main__.py
index d9e239c..47b741c 100644
--- a/adventure/__main__.py
+++ b/adventure/__main__.py
@@ -79,11 +79,19 @@ def loop(game):
             baudout(game.do_command(words))
 
 
-def main():
-    """ Main-line code for this program. """
-    parser = AdventureArgumentParser(
-        prog='{} -m adventure'.format(os.path.basename(sys.executable)))
-    options = parser.parse_args()
+def main(argv=None):
+    """ Main-line code for this program.
+
+        :param argv: Sequence of command-line arguments to the process.
+            If ``None``, defaults to `sys.argv`.
+        :return: None.
+
+        """
+    if argv is None:
+        argv = sys.argv
+
+    parser = AdventureArgumentParser(prog=argv[0])
+    options = parser.parse_args(argv[1:])
 
     game = make_or_resume_game(options.savefile)
 
@@ -92,6 +100,6 @@ def main():
 
 if __name__ == '__main__':
     try:
-        main()
+        main(sys.argv)
     except EOFError:
         pass
-- 
Local variables:
coding: utf-8
mode: diff
time-stamp-format: "%:y-%02m-%02d"
time-stamp-start: "^Last-Update:[ 	]+"
time-stamp-end: "$"
time-stamp-line-limit: 20
End:
vim: fileencoding=utf-8 filetype=diff :