Skip to content

Commit

Permalink
Merge pull request #166 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
mathomp4 committed May 25, 2021
2 parents c6b87a5 + 13e3eee commit fec4dd4
Show file tree
Hide file tree
Showing 27 changed files with 548 additions and 69 deletions.
42 changes: 42 additions & 0 deletions etc/mepoconfig-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This is a skeleton example of a .mepoconfig file
#
# .mepoconfig is a config file a la gitconfig with sections and options.
#
# Currently, .mepoconfig files recognize two sections: [init] and [alias]
#
# =======================================================================
#
# [init] Section
#
# The init section currently recognizes one option, style.
# This has three allowed values: naked, postfix, prefix
#
# So if you have:
#
# [init]
# style = postfix
#
# This is equivalent to doing:
#
# mepo init --style postfix
#
# or when running with mepo clone:
#
# mepo clone --style postfix
#
# =======================================================================
#
# [alias] Section
#
# The [alias] Section is used to make aliases of mepo commands. For
# example this:
#
# [alias]
# st = status
#
# lets one run "mepo st" as an alias to "mepo status"
#
# Note: Due to lack of skill of the developer and limitations in Argparse,
# you can only alias mepo primary commands and not "subcommands" or
# "options". So you can have an alias for "commit" and for "branch",
# but you can't do an option for "commit -m" or "branch create".
83 changes: 83 additions & 0 deletions mepo.d/cmdline/config_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import argparse
import textwrap

class MepoConfigArgParser(object):

def __init__(self, config):
self.config = config.add_subparsers()
self.config.title = 'mepo config sub-commands'
self.config.dest = 'mepo_config_cmd'
self.config.required = True
self.__get()
self.__set()
self.__delete()
self.__print()

def __get(self):
get = self.config.add_parser(
'get',
formatter_class=argparse.RawDescriptionHelpFormatter,
description = textwrap.dedent('''\
Get config <entry> in .mepoconfig.
Note this uses gitconfig style where <entry> is
of the form "section.option" So to get something like:
[alias]
st = status
You would run "mepo config get alias.st"
'''))
get.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to display.')

def __set(self):
set = self.config.add_parser(
'set',
formatter_class=argparse.RawDescriptionHelpFormatter,
description = textwrap.dedent('''\
Set config <entry> to <value> in .mepoconfig.
Note this uses gitconfig style where <entry> is
of the form "section.option" So to set something like:
[alias]
st = status
You would run "mepo config set alias.st status"
'''))
set.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to set.')
set.add_argument(
'value',
metavar = 'value',
help = 'Value to set entry to.')

def __delete(self):
delete = self.config.add_parser(
'delete',
formatter_class=argparse.RawDescriptionHelpFormatter,
description = textwrap.dedent('''\
Delete config <entry> in .mepoconfig.
Note this uses gitconfig style where <entry> is
of the form "section.option" So to delete something like:
[alias]
st = status
You would run "mepo config delete alias.st"
'''))
delete.add_argument(
'entry',
metavar = 'entry',
help = 'Entry to delete.')

def __print(self):
print = self.config.add_parser(
'print',
description = 'Print contents of .mepoconfig')
104 changes: 81 additions & 23 deletions mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from cmdline.branch_parser import MepoBranchArgParser
from cmdline.stash_parser import MepoStashArgParser
from cmdline.tag_parser import MepoTagArgParser
from cmdline.config_parser import MepoConfigArgParser
from utilities import mepoconfig

class MepoArgParser(object):

Expand Down Expand Up @@ -39,24 +41,35 @@ def parse(self):
self.__unstage()
self.__commit()
self.__push()
self.__push_all()
self.__save()
self.__config()
return self.parser.parse_args()

def __init(self):
init = self.subparsers.add_parser(
'init',
description = 'Initialize mepo based on <config-file>')
description = 'Initialize mepo based on <config-file>',
aliases=mepoconfig.get_command_alias('init'))
init.add_argument(
'--config',
metavar = 'config-file',
nargs = '?',
default = 'components.yaml',
help = 'default: %(default)s')
init.add_argument(
'--style',
metavar = 'style-type',
nargs = '?',
default = None,
choices = ['naked', 'prefix','postfix'],
help = 'Style of directory file, default: prefix, allowed options: %(choices)s')

def __clone(self):
clone = self.subparsers.add_parser(
'clone',
description = "Clone repositories.")
description = "Clone repositories.",
aliases=mepoconfig.get_command_alias('clone'))
clone.add_argument(
'repo_url',
metavar = 'URL',
Expand All @@ -80,26 +93,37 @@ def __clone(self):
nargs = '?',
default = None,
help = 'Configuration file (ignored if init already called)')
clone.add_argument(
'--style',
metavar = 'style-type',
nargs = '?',
default = None,
choices = ['naked', 'prefix','postfix'],
help = 'Style of directory file, default: prefix, allowed options: %(choices)s (ignored if init already called)')

def __list(self):
listcomps = self.subparsers.add_parser(
'list',
description = 'List all components that are being tracked')
description = 'List all components that are being tracked',
aliases=mepoconfig.get_command_alias('list'))

def __status(self):
status = self.subparsers.add_parser(
'status',
description = 'Check current status of all components')
description = 'Check current status of all components',
aliases=mepoconfig.get_command_alias('status'))

def __restore_state(self):
restore_state = self.subparsers.add_parser(
'restore-state',
description = 'Restores all components to the last saved state.')
description = 'Restores all components to the last saved state.',
aliases=mepoconfig.get_command_alias('restore-state'))

def __diff(self):
diff = self.subparsers.add_parser(
'diff',
description = 'Diff all components')
description = 'Diff all components',
aliases=mepoconfig.get_command_alias('diff'))
diff.add_argument(
'--name-only',
action = 'store_true',
Expand All @@ -119,7 +143,8 @@ def __checkout(self):
'checkout',
description = 'Switch to branch <branch-name> in component <comp-name>. '
'Specifying -b causes the branch <branch-name> to be created in '
'the specified component(s).')
'the specified component(s).',
aliases=mepoconfig.get_command_alias('checkout'))
checkout.add_argument('branch_name', metavar = 'branch-name')
checkout.add_argument('comp_name', metavar = 'comp-name', nargs = '+')
checkout.add_argument('-b', action = 'store_true', help = 'create the branch')
Expand All @@ -128,7 +153,8 @@ def __checkout(self):
def __checkout_if_exists(self):
checkout_if_exists = self.subparsers.add_parser(
'checkout-if-exists',
description = 'Switch to branch <branch-name> in any component where it is present. ')
description = 'Switch to branch <branch-name> in any component where it is present. ',
aliases=mepoconfig.get_command_alias('checkout-if-exists'))
checkout_if_exists.add_argument('branch_name', metavar = 'branch-name')
checkout_if_exists.add_argument('--quiet', '-q', action = 'store_true', help = 'Suppress prints')
checkout_if_exists.add_argument('--dry-run','-n', action = 'store_true', help = 'Dry-run only (lists repos where branch exists)')
Expand All @@ -137,7 +163,8 @@ def __fetch(self):
fetch = self.subparsers.add_parser(
'fetch',
description = 'Download objects and refs from in component <comp-name>. '
'Specifying --all causes all remotes to be fetched.')
'Specifying --all causes all remotes to be fetched.',
aliases=mepoconfig.get_command_alias('fetch'))
fetch.add_argument('comp_name', metavar = 'comp-name', nargs = '+')
fetch.add_argument('--all', action = 'store_true', help = 'Fetch all remotes.')
fetch.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.')
Expand All @@ -148,7 +175,8 @@ def __fetch_all(self):
fetch_all = self.subparsers.add_parser(
'fetch-all',
description = 'Download objects and refs from all components. '
'Specifying --all causes all remotes to be fetched.')
'Specifying --all causes all remotes to be fetched.',
aliases=mepoconfig.get_command_alias('fetch-all'))
fetch_all.add_argument('--all', action = 'store_true', help = 'Fetch all remotes.')
fetch_all.add_argument('--prune','-p', action = 'store_true', help = 'Prune remote branches.')
fetch_all.add_argument('--tags','-t', action = 'store_true', help = 'Fetch tags.')
Expand All @@ -157,56 +185,65 @@ def __fetch_all(self):
def __branch(self):
branch = self.subparsers.add_parser(
'branch',
description = "Runs branch commands.")
description = "Runs branch commands.",
aliases=mepoconfig.get_command_alias('branch'))
MepoBranchArgParser(branch)

def __stash(self):
stash = self.subparsers.add_parser(
'stash',
description = "Runs stash commands.")
description = "Runs stash commands.",
aliases=mepoconfig.get_command_alias('stash'))
MepoStashArgParser(stash)

def __tag(self):
tag = self.subparsers.add_parser(
'tag',
description = "Runs tag commands.")
description = "Runs tag commands.",
aliases=mepoconfig.get_command_alias('tag'))
MepoTagArgParser(tag)

def __develop(self):
develop = self.subparsers.add_parser(
'develop',
description = "Checkout current version of 'develop' branches of specified components")
description = "Checkout current version of 'develop' branches of specified components",
aliases=mepoconfig.get_command_alias('develop'))
develop.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None)
develop.add_argument('--quiet', '-q', action = 'store_true', help = 'Suppress prints')

def __pull(self):
pull = self.subparsers.add_parser(
'pull',
description = "Pull branches of specified components")
description = "Pull branches of specified components",
aliases=mepoconfig.get_command_alias('pull'))
pull.add_argument('comp_name', metavar = 'comp-name', nargs = '+', default = None)

def __pull_all(self):
pull_all = self.subparsers.add_parser(
'pull-all',
description = "Pull branches of all components (only those in non-detached HEAD state)")
description = "Pull branches of all components (only those in non-detached HEAD state)",
aliases=mepoconfig.get_command_alias('pull-all'))

def __compare(self):
compare = self.subparsers.add_parser(
'compare',
description = 'Compare current and original states of all components')
description = 'Compare current and original states of all components',
aliases=mepoconfig.get_command_alias('compare'))

def __whereis(self):
whereis = self.subparsers.add_parser(
'whereis',
description = 'Get the location of component <comp-name> '
'relative to my current location. If <comp-name> is not present, '
'get the relative locations of ALL components.')
'get the relative locations of ALL components.',
aliases=mepoconfig.get_command_alias('whereis'))
whereis.add_argument('comp_name', metavar = 'comp-name', nargs = '?', default = None)

def __stage(self):
stage = self.subparsers.add_parser(
'stage',
description = 'Stage modified & untracked files in the specified component(s)')
description = 'Stage modified & untracked files in the specified component(s)',
aliases=mepoconfig.get_command_alias('stage'))
stage.add_argument(
'--untracked',
action = 'store_true',
Expand All @@ -221,7 +258,8 @@ def __unstage(self):
unstage = self.subparsers.add_parser(
'unstage',
description = 'Un-stage staged files. '
'If a component is specified, files are un-staged only for that component.')
'If a component is specified, files are un-staged only for that component.',
aliases=mepoconfig.get_command_alias('unstage'))
unstage.add_argument(
'comp_name',
metavar = 'comp-name',
Expand All @@ -232,7 +270,8 @@ def __unstage(self):
def __commit(self):
commit = self.subparsers.add_parser(
'commit',
description = 'Commit staged files in the specified components')
description = 'Commit staged files in the specified components',
aliases=mepoconfig.get_command_alias('commit'))
commit.add_argument('-a', '--all', action = 'store_true', help = 'stage all tracked files and then commit')
commit.add_argument('-m', '--message', type=str, metavar = 'message', default=None)
commit.add_argument(
Expand All @@ -244,7 +283,8 @@ def __commit(self):
def __push(self):
push = self.subparsers.add_parser(
'push',
description = 'Push local commits or tags to remote')
description = 'Push local commits or tags to remote for specified component',
aliases=mepoconfig.get_command_alias('push'))
push.add_argument(
'--tags',
action = 'store_true',
Expand All @@ -255,13 +295,31 @@ def __push(self):
nargs = '+',
help = 'Component to push to remote')

def __push_all(self):
push_all = self.subparsers.add_parser(
'push-all',
description = 'Push local commits or tags to remote for all components',
aliases=mepoconfig.get_command_alias('push-all'))
push_all.add_argument(
'--tags',
action = 'store_true',
help = 'push tags')

def __save(self):
save = self.subparsers.add_parser(
'save',
description = 'Save current state in a yaml config file')
description = 'Save current state in a yaml config file',
aliases=mepoconfig.get_command_alias('save'))
save.add_argument(
'config_file',
metavar = 'config-file',
nargs = '?',
default = 'components-new.yaml',
help = 'default: %(default)s')

def __config(self):
config = self.subparsers.add_parser(
'config',
description = "Runs config commands.",
aliases=mepoconfig.get_command_alias('config'))
MepoConfigArgParser(config)
Loading

0 comments on commit fec4dd4

Please sign in to comment.