mirror of
https://github.com/docker/compose.git
synced 2025-05-29 10:50:15 +02:00
Merge pull request #1578 from aanand/fix-migrate-help
Fix 'docker-compose help migrate-to-labels'
This commit is contained in:
commit
c8751980f9
@ -33,12 +33,7 @@ class DocoptCommand(object):
|
|||||||
if command is None:
|
if command is None:
|
||||||
raise SystemExit(getdoc(self))
|
raise SystemExit(getdoc(self))
|
||||||
|
|
||||||
command = command.replace('-', '_')
|
handler = self.get_handler(command)
|
||||||
|
|
||||||
if not hasattr(self, command):
|
|
||||||
raise NoSuchCommand(command, self)
|
|
||||||
|
|
||||||
handler = getattr(self, command)
|
|
||||||
docstring = getdoc(handler)
|
docstring = getdoc(handler)
|
||||||
|
|
||||||
if docstring is None:
|
if docstring is None:
|
||||||
@ -47,6 +42,14 @@ class DocoptCommand(object):
|
|||||||
command_options = docopt_full_help(docstring, options['ARGS'], options_first=True)
|
command_options = docopt_full_help(docstring, options['ARGS'], options_first=True)
|
||||||
return options, handler, command_options
|
return options, handler, command_options
|
||||||
|
|
||||||
|
def get_handler(self, command):
|
||||||
|
command = command.replace('-', '_')
|
||||||
|
|
||||||
|
if not hasattr(self, command):
|
||||||
|
raise NoSuchCommand(command, self)
|
||||||
|
|
||||||
|
return getattr(self, command)
|
||||||
|
|
||||||
|
|
||||||
class NoSuchCommand(Exception):
|
class NoSuchCommand(Exception):
|
||||||
def __init__(self, command, supercommand):
|
def __init__(self, command, supercommand):
|
||||||
|
@ -131,10 +131,8 @@ class TopLevelCommand(Command):
|
|||||||
|
|
||||||
Usage: help COMMAND
|
Usage: help COMMAND
|
||||||
"""
|
"""
|
||||||
command = options['COMMAND']
|
handler = self.get_handler(options['COMMAND'])
|
||||||
if not hasattr(self, command):
|
raise SystemExit(getdoc(handler))
|
||||||
raise NoSuchCommand(command, self)
|
|
||||||
raise SystemExit(getdoc(getattr(self, command)))
|
|
||||||
|
|
||||||
def kill(self, project, options):
|
def kill(self, project, options):
|
||||||
"""
|
"""
|
||||||
@ -486,6 +484,24 @@ class TopLevelCommand(Command):
|
|||||||
"""
|
"""
|
||||||
Recreate containers to add labels
|
Recreate containers to add labels
|
||||||
|
|
||||||
|
If you're coming from Compose 1.2 or earlier, you'll need to remove or
|
||||||
|
migrate your existing containers after upgrading Compose. This is
|
||||||
|
because, as of version 1.3, Compose uses Docker labels to keep track
|
||||||
|
of containers, and so they need to be recreated with labels added.
|
||||||
|
|
||||||
|
If Compose detects containers that were created without labels, it
|
||||||
|
will refuse to run so that you don't end up with two sets of them. If
|
||||||
|
you want to keep using your existing containers (for example, because
|
||||||
|
they have data volumes you want to preserve) you can migrate them with
|
||||||
|
the following command:
|
||||||
|
|
||||||
|
docker-compose migrate-to-labels
|
||||||
|
|
||||||
|
Alternatively, if you're not worried about keeping them, you can
|
||||||
|
remove them - Compose will just create new ones.
|
||||||
|
|
||||||
|
docker rm -f myapp_web_1 myapp_db_1 ...
|
||||||
|
|
||||||
Usage: migrate-to-labels
|
Usage: migrate-to-labels
|
||||||
"""
|
"""
|
||||||
legacy.migrate_project_to_labels(project)
|
legacy.migrate_project_to_labels(project)
|
||||||
|
@ -11,6 +11,7 @@ import mock
|
|||||||
|
|
||||||
from compose.cli import main
|
from compose.cli import main
|
||||||
from compose.cli.main import TopLevelCommand
|
from compose.cli.main import TopLevelCommand
|
||||||
|
from compose.cli.docopt_command import NoSuchCommand
|
||||||
from compose.cli.errors import ComposeFileNotFound
|
from compose.cli.errors import ComposeFileNotFound
|
||||||
from compose.service import Service
|
from compose.service import Service
|
||||||
|
|
||||||
@ -101,6 +102,22 @@ class CLITestCase(unittest.TestCase):
|
|||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
command.dispatch(['-h'], None)
|
command.dispatch(['-h'], None)
|
||||||
|
|
||||||
|
def test_command_help(self):
|
||||||
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
TopLevelCommand().dispatch(['help', 'up'], None)
|
||||||
|
|
||||||
|
self.assertIn('Usage: up', str(ctx.exception))
|
||||||
|
|
||||||
|
def test_command_help_dashes(self):
|
||||||
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
|
TopLevelCommand().dispatch(['help', 'migrate-to-labels'], None)
|
||||||
|
|
||||||
|
self.assertIn('Usage: migrate-to-labels', str(ctx.exception))
|
||||||
|
|
||||||
|
def test_command_help_nonexistent(self):
|
||||||
|
with self.assertRaises(NoSuchCommand):
|
||||||
|
TopLevelCommand().dispatch(['help', 'nonexistent'], None)
|
||||||
|
|
||||||
def test_setup_logging(self):
|
def test_setup_logging(self):
|
||||||
main.setup_logging()
|
main.setup_logging()
|
||||||
self.assertEqual(logging.getLogger().level, logging.DEBUG)
|
self.assertEqual(logging.getLogger().level, logging.DEBUG)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user