Commits

Nikolaj Sjujskij committed e57e9cb

Improve argument handling

Comments (0)

Files changed (1)

rst2epub/converter.py

 
 from package import Package
 
-def main():
-    rst = RstDocument(sys.argv[1])
+def main(rstfile, epubfile):
+    rst = RstDocument(rstfile)
     title = rst.get_title()
     author = rst.get_author()
     identifier = "TODO"
     language = "en_TODO"
-    writer = EpubWriter(sys.argv[2], title, identifier, language, author)
+    writer = EpubWriter(epubfile, title, identifier, language, author)
 
     writer.container.add_rootfile(Package.path, Package.media_type)
 
 
 
 if __name__ == "__main__":
-    main()
+    usage = '''Usage:
+    $ {0} <input_file.rst> <output_file.epub>\n'''.format(sys.argv[0])
+    if '--help' in sys.argv:
+        print(usage)
+        sys.exit(0)
+    if len(sys.argv) != 3:
+        sys.stderr.write(usage)
+        sys.stderr.write("Invalid argument number\n")
+        sys.exit(1)
+    rstfile, epubfile = sys.argv[1:]
+    main(rstfile, epubfile)