]> kaliko git repositories - mpd-sima.git/blobdiff - sima/utils/startopt.py
Add option to generate config on stdout
[mpd-sima.git] / sima / utils / startopt.py
index 04df3b4b5f287351960a2efc50b4955e0fcbce65..2081c19266951f3b215d6353cd0229467c75c47a 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright (c) 2009, 2010, 2011, 2012, 2013 Jack Kaliko <kaliko@azylum.org>
+# Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jack Kaliko <kaliko@azylum.org>
 #
 #  This file is part of sima
 #
 #
 #
 
-import sys
 from argparse import (ArgumentParser, SUPPRESS)
 
 
-from .utils import Obsolete, Wfile, Rfile, Wdir
+from .utils import Wfile, Rfile, Wdir
 
-USAGE = """USAGE:  %prog [--help] [options]"""
 DESCRIPTION = """
-sima automagicaly queue new tracks in MPD playlist.
-All command line options will override their equivalent in configuration
-file.
-"""
+MPD_sima automagicaly queue new tracks in MPD playlist.
+Command line options override their equivalent in configuration file."""
 
 
 def clean_dict(to_clean):
@@ -85,6 +81,13 @@ OPTS = [
         'dest': 'conf_file',
         'action': Rfile,
         'help': 'Configuration file to load'},
+    {
+        'sw':['--generate-config'],
+        'dest': 'generate_config',
+        'action': 'store_true',
+        'help': 'Generate a sample configuration file to stdout according to the current\
+         configuration. You can put other options with this one to get them in\
+         the generated configuration.'},
     {
         'sw':['--var_dir'],
         'dest': 'var_dir',
@@ -115,6 +118,7 @@ class StartOpt(object):
     """
 
     def __init__(self, script_info,):
+        self.parser = None
         self.info = dict(script_info)
         self.options = dict()
         self.main()
@@ -124,12 +128,11 @@ class StartOpt(object):
         Declare options in ArgumentParser object.
         """
         self.parser = ArgumentParser(description=DESCRIPTION,
-                                   usage='%(prog)s [options]',
-                                   prog=self.info.get('prog'),
-                                   epilog='Happy Listening',
-                )
+                                     prog=self.info.get('prog'),
+                                     epilog='Happy Listening',
+                                    )
         self.parser.add_argument('--version', action='version',
-                version='%(prog)s {version}'.format(**self.info))
+                        version='%(prog)s {version}'.format(**self.info))
         # Add all options declare in OPTS
         for opt in OPTS:
             opt_names = opt.pop('sw')