mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
dvc: use our errors in the argparser
Fixes #1037 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+3
-6
@@ -26,6 +26,7 @@ from dvc.command.install import CmdInstall
|
||||
from dvc.command.root import CmdRoot
|
||||
from dvc.command.lock import CmdLock, CmdUnlock
|
||||
from dvc.command.pipeline import CmdPipelineShow
|
||||
from dvc.logger import Logger
|
||||
from dvc import VERSION
|
||||
|
||||
|
||||
@@ -41,7 +42,7 @@ def _fix_subparsers(subparsers):
|
||||
|
||||
class DvcParser(argparse.ArgumentParser):
|
||||
def error(self, message):
|
||||
sys.stderr.write('error: %s\n' % message)
|
||||
sys.stderr.write('{}{}\n'.format(Logger.error_prefix(), message))
|
||||
self.print_help()
|
||||
sys.exit(2)
|
||||
|
||||
@@ -784,11 +785,7 @@ def parse_args(argv=None):
|
||||
cwd = os.curdir
|
||||
path = os.path.join(cwd, 'Dvcfile')
|
||||
if not os.path.exists(path):
|
||||
msg = "error: default target '{}' does not exist.\n"
|
||||
sys.stderr.write(msg.format(path))
|
||||
sys.stderr.flush()
|
||||
repro_parser.print_help()
|
||||
sys.exit(2)
|
||||
parser.error("default target '{}' does not exist.".format(path))
|
||||
args.targets = ['Dvcfile']
|
||||
|
||||
return args
|
||||
|
||||
+19
-5
@@ -82,9 +82,25 @@ class Logger(object):
|
||||
|
||||
return (str_exc, str_tb)
|
||||
|
||||
@staticmethod
|
||||
def _prefix(msg, typ):
|
||||
return Logger.colorize('{}: '.format(msg), typ)
|
||||
|
||||
@staticmethod
|
||||
def error_prefix():
|
||||
return Logger._prefix('Error', 'error')
|
||||
|
||||
@staticmethod
|
||||
def warning_prefix():
|
||||
return Logger._prefix('Warning', 'warn')
|
||||
|
||||
@staticmethod
|
||||
def debug_prefix():
|
||||
return Logger._prefix('Debug', 'debug')
|
||||
|
||||
@staticmethod
|
||||
def error(msg, exc=None):
|
||||
prefix = Logger.colorize('Error: ', 'error')
|
||||
prefix = Logger.error_prefix()
|
||||
str_exc, str_tb = Logger.parse_exc(exc)
|
||||
if Logger.logger().getEffectiveLevel() == logging.DEBUG and exc:
|
||||
str_tb = str_tb if str_tb else traceback.format_exc()
|
||||
@@ -93,13 +109,11 @@ class Logger(object):
|
||||
|
||||
@staticmethod
|
||||
def warn(msg):
|
||||
prefix = Logger.colorize('Warning: ', 'warn')
|
||||
return Logger.logger().warn(prefix + msg)
|
||||
return Logger.logger().warn(Logger.warning_prefix() + msg)
|
||||
|
||||
@staticmethod
|
||||
def debug(msg):
|
||||
prefix = Logger.colorize('Debug: ', 'debug')
|
||||
return Logger.logger().debug(prefix + msg)
|
||||
return Logger.logger().debug(Logger.debug_prefix() + msg)
|
||||
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
|
||||
Reference in New Issue
Block a user