Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ A terminal help page can be shown by using the `-h`/`--help` option.
| `-p`, `--plugin` | `PLUGIN` | No | Load `PLUGIN` as a plugin. |
| `--disable-core-plugins` | - | No | Disable all core plugins. |
| `--plugin-dir` | `PLUGIN_DIR` | No | Load all plugins in `PLUGIN_DIR`. |
| `--version` | | No | Prints current version of snowsaw |


## Configuration
snowsaw uses [JSON](http://json.org) configuration files to specify tasks on how to set up your dotfiles.
Expand Down
26 changes: 25 additions & 1 deletion snowsaw/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from argparse import ArgumentParser
import glob
import os
import subprocess

from .config import ConfigReader, ReadingError
from .dispatcher import Dispatcher, DispatchError
Expand All @@ -27,11 +28,12 @@ def add_options(parser):
parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help='suppress most output')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='enable verbose output')
parser.add_argument('-s', '--snowblocks-directory', nargs=1, dest='snowblocks_directory',
help='base snowblock directory to run all tasks of', metavar='SNOWBLOCKSDIR', required=True)
help='base snowblock directory to run all tasks of', metavar='SNOWBLOCKSDIR')
parser.add_argument('-c', '--config-file', nargs=1, dest='config_file', help='run tasks for the specified snowblock', metavar='CONFIGFILE')
parser.add_argument('-p', '--plugin', action='append', dest='plugins', default=[], help='load PLUGIN as a plugin', metavar='PLUGIN')
parser.add_argument('--disable-core-plugins', dest='disable_core_plugins', action='store_true', help='disable all core plugins')
parser.add_argument('--plugin-dir', action='append', dest='plugin_dirs', default=[], metavar='PLUGIN_DIR', help='load all plugins in PLUGIN_DIR')
parser.add_argument('--version', action='store_true', help='print snowsaw version')


def read_config(config_file):
Expand All @@ -58,6 +60,28 @@ def main():
add_options(parser)
options = parser.parse_args()

if options.version :
"""
Just print version end exit. Don't need to process other arguments.
Change directory to ensure git-related commands are called inside
snowsaw repository and than change it back
"""
caller_dir = os.getcwd()
snowsaw_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(snowsaw_dir)
try:
current_version = subprocess.check_output(["git", "describe"]).strip()
except subprocess.CalledProcessError as Error :
current_version = "Not tagged (development) version"
print(current_version)
os.chdir(caller_dir)
return current_version
elif not options.snowblocks_directory :
"""
Since it's not a version request, check required arguments existance
"""
parser.error("argument -s/--snowblocks-directory is required")

if options.super_quiet:
log.set_level(Level.WARNING)
if options.quiet:
Expand Down