-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update cli with common parser for all commands. leverage argparse for…
… command parsing. help messages and usage needs to be fixed
- Loading branch information
1 parent
e2901e4
commit c73d16a
Showing
11 changed files
with
180 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from datmo.cli.driver.parser import Parser | ||
from datmo.util.exceptions import ClassMethodNotFound | ||
|
||
|
||
class BaseCommand(object): | ||
def __init__(self, home, cli_helper): | ||
self.home = home | ||
self.cli_helper = cli_helper | ||
self.parser = Parser(prog="datmo", usage=""" | ||
datmo COMMAND [SUBCOMMANDS] ARGS | ||
Datmo is a command line utility to enable tracking of data science projects. | ||
It uses many of the tools you are already familiar with and combines them into a snapshot | ||
which allows you to keep track of 5 components at once | ||
1) Source Code | ||
2) Dependency Environment | ||
3) Large Files | ||
4) Configurations | ||
5) Metrics | ||
command: | ||
""") | ||
# self.parser.add_argument("-v", "--verbose", action="store_true", | ||
# help="run in verbose mode") | ||
self.subparsers = self.parser.add_subparsers(title="commands", dest="command") | ||
|
||
def parse(self, args): | ||
self.args = self.parser.parse_args(args) | ||
|
||
def execute(self): | ||
""" | ||
Calls the method if it exists on this object, otherwise | ||
call a default method name (module name) | ||
Raises | ||
------ | ||
ClassMethodNotFound | ||
If the Class method is not found | ||
""" | ||
command_args = vars(self.args).copy() | ||
# use command name if it exists, | ||
# otherwise use the module name | ||
|
||
if "subcommand" in command_args: | ||
method = getattr(self, getattr(self.args, "subcommand", self.args.command)) | ||
else: | ||
method = getattr(self, getattr(self.args, "command", self.args.command)) | ||
|
||
# remove extraneous options that the method should need to care about | ||
if "command" in command_args: | ||
del command_args["command"] | ||
if "subcommand" in command_args: | ||
del command_args["subcommand"] | ||
|
||
if method is None: | ||
raise ClassMethodNotFound("Method %s.%s not found" % (self.args.command, method)) | ||
|
||
method(**command_args) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from datmo.util.i18n import get as _ | ||
from datmo.cli.command.base import BaseCommand | ||
from datmo.controller.project import ProjectController | ||
|
||
|
||
class ProjectCommand(BaseCommand): | ||
# NOTE: dal_driver is not passed into the project because it is created | ||
# first by ProjectController and then passed down to all other Controllers | ||
def __init__(self, home, cli_helper): | ||
super(ProjectCommand, self).__init__(home, cli_helper) | ||
init_parser = self.subparsers.add_parser("init", help="Initialize project") | ||
init_parser.add_argument("--name") | ||
init_parser.add_argument("--description", default=None) | ||
self.project_controller = ProjectController(home=home) | ||
|
||
def init(self, name, description): | ||
self.cli_helper.echo(_('setup.init_project', {"name":name, "path": self.home})) | ||
self.project_controller.init(name, description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.