Commits

Takeshi Komiya committed a042964

Change option: use --config to specify path to config file

Comments (0)

Files changed (5)

src/schema2rst/commands/dump.py

 
     if options.config is None:
         parser.error('--config (-c) is required')
-        parser.print_usage()
-        sys.exit(0)
 
     return options, args
 

src/schema2rst/commands/graph.py

 def parse_option(args):
     usage = 'Usage: schema2graph CONFIG_FILE'
     parser = optparse.OptionParser(usage=usage)
+    parser.add_option('-c', '--config', action='store')
     parser.add_option('-o', '--output', action='store')
 
     options, args = parser.parse_args(args)
-    if len(args) != 1:
-        parser.print_usage()
-        sys.exit(0)
+    if options.config is None:
+        parser.error('--config (-c) is required')
 
     return options, args
 
 def main(args=sys.argv[1:]):
     options, args = parse_option(args)
 
-    config = yaml.load(io.open(args[0], encoding='utf-8'))
+    config = yaml.load(io.open(options.config, encoding='utf-8'))
     engine = inspectors.create_engine(config)
     try:
         schema = inspectors.create_for(engine).dump()

src/schema2rst/commands/rst.py

 def parse_option(args):
     usage = 'Usage: schema2rst CONFIG_FILE'
     parser = optparse.OptionParser(usage=usage)
+    parser.add_option('-c', '--config', action='store')
     parser.add_option('-o', '--output', action='store')
 
     options, args = parser.parse_args(args)
-    if len(args) != 1:
-        parser.print_usage()
-        sys.exit(0)
+    if options.config is None:
+        parser.error('--config (-c) is required')
 
     return options, args
 

src/schema2rst/tests/test_mysql.py

             fd, output = tempfile.mkstemp()
             os.close(fd)
 
-            rst.main(['-o', output, self.config.name])
+            rst.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/mysql_basic.rst'),
                              io.open(output, encoding='utf-8').read())
 
-            graph.main(['-o', output, self.config.name])
+            graph.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/mysql_basic_graph.rst'),
                              io.open(output, encoding='utf-8').read())
         finally:
             fd, output = tempfile.mkstemp()
             os.close(fd)
 
-            rst.main(['-o', output, self.config.name])
+            rst.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/mysql_comments.rst'),
                              io.open(output, encoding='utf-8').read())
 
-            graph.main(['-o', output, self.config.name])
+            graph.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/mysql_comments_graph.rst'),
                              io.open(output, encoding='utf-8').read())
         finally:

src/schema2rst/tests/test_pgsql.py

             fd, output = tempfile.mkstemp()
             os.close(fd)
 
-            rst.main(['-o', output, self.config.name])
+            rst.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/pgsql_basic.rst'),
                              io.open(output, encoding='utf-8').read())
 
-            graph.main(['-o', output, self.config.name])
+            graph.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/pgsql_basic_graph.rst'),
                              io.open(output, encoding='utf-8').read())
         finally:
             fd, output = tempfile.mkstemp()
             os.close(fd)
 
-            rst.main(['-o', output, self.config.name])
+            rst.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/pgsql_comments.rst'),
                              io.open(output, encoding='utf-8').read())
 
-            graph.main(['-o', output, self.config.name])
+            graph.main(['-c', self.config.name, '-o', output])
             self.assertEqual(self.readfile('rst/pgsql_comments_graph.rst'),
                              io.open(output, encoding='utf-8').read())
         finally: