From 9073bf1ccac68cfaa93d4bbe5c9b1b3fe98fcd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 8 Jan 2016 16:09:37 +0100 Subject: Change documentation and add configfile argument Configuration options are from previous commit documented directly in example configuration file. So they don't have to be documented in readme. New argument configfile was added because if user uses default paths for configuration files, it can be sometime unclear what file was used. This prints path to used file. Also as small feature, if no identifier is specified as argument neither in configuration file help text is printed. --- README.md | 28 +++++----------------------- mcwrapper | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6771e68..4fdea4c 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ mcwrapper [arguments...] IDENTIFIER Increase verbose level of output. -q, --quiet Decrease verbose level of output. + --config CONFIG_FILE + Specify configuration file to be used. + --configfile + prints used configuration file and exits. IDENTIFIER Identifier for new server. This allows multiple servers running with this @@ -73,26 +77,4 @@ Script is searching for configuration in these files (in order of precedence): * ~/.mcwrapper.conf * ~/.config/mcwrapper.conf * /etc/mcwrapper.conf - -### identifier -This option is string defining identifier of server. If this option is define, no -IDENTIFIER argument is expected on command line. If you have only one server, use -this to make command line commands shorter. - -### server -This variable is expected to be of type dictionary and contains configurations per -server. See example.conf for example. Options for servers are these: -#### directory -Defines directory where will be server executed. This way you can start server from -any directory and it will always start server in right one. -#### command -Defines command to start Minecraft server in `directory`. -#### status -Defines directory in which will be placed all status files generated by this -wrapper. - -### timeout -Numerical value, specifying time in minutes after which will be server -automatically shutdown if no player is on server. If value is less or equal zero, -automatic shutdown is disabled. If value is not specified in configuration file, 0 -is used. +Or you can use `--config` argument to specify any other file with valid content. diff --git a/mcwrapper b/mcwrapper index 8b0c253..ddf1d8d 100755 --- a/mcwrapper +++ b/mcwrapper @@ -324,16 +324,26 @@ def print_help(): print(' Decrease verbose level of output.') print(' --config CONFIG_FILE') print(' Specify configuration file to be used.') + print(' --configfile') + print(' prints used configuration file and exits.') print(' IDENTIFIER') print(' Identifier for new server. This allows multiple servers running with this') print(' wrapper. Identifier is word without spaces and preferably without special') print(' characters.') sys.exit(_EC_OK) +def print_conffile(): + if '__file__' in vars(conf): + print(conf.__file__) + else: + print("No configuration file used.") + sys.exit(_EC_OK) + if __name__ == '__main__': identifier = None use_config = None verbose_level = 0 + print_config_file = False i = 1 while i < len(sys.argv): arg = sys.argv[i] @@ -353,6 +363,8 @@ if __name__ == '__main__': else: use_config = sys.argv[i] i += 1 + elif arg == '--configfile': + print_config_file = True continue else: for l in arg[1:]: @@ -372,10 +384,16 @@ if __name__ == '__main__': # Parsing args ends load_conf(use_config) + + if print_config_file: + print_conffile() + conf.verbose_level += verbose_level # Set identifier if provided if identifier: conf.identifier = identifier + elif not "identifier" in vars(conf): + print_help() signal.signal(signal.SIGTERM, __signal_term__) signal.signal(signal.SIGINT, __signal_term__) -- cgit v1.2.3