python/mach/mach/commands/settings.py
author Gregory Szorc <gps@mozilla.com>
Fri, 05 Oct 2012 12:13:18 -0700
changeset 112939 d04782dc009156e114f27da3a468321a99edc47b
parent 112938 python/mach/mach/settings.py@15c2bcb1a982e748f9f88be3976096cf5d31b07c
child 114436 c0977caba1d634ef3725dc024d7e6be03628ffbc
permissions -rw-r--r--
Bug 794509 - Part 2: Move mach command modules into a mach.commands sub-module; r=jhammel This patch on its own will break mach. Part 3 will refactor mach's loader to discover and load modules using a modified module finding method.

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import print_function, unicode_literals

from textwrap import TextWrapper

from mozbuild.base import MozbuildObject
from mach.base import CommandProvider
from mach.base import Command

@CommandProvider
class Settings(MozbuildObject):
    """Interact with settings for mach.

    Currently, we only provide functionality to view what settings are
    available. In the future, this module will be used to modify settings, help
    people create configs via a wizard, etc.
    """
    @Command('settings-list', help='Show available config settings.')
    def list_settings(self):
        """List available settings in a concise list."""
        for section in sorted(self.settings):
            for option in sorted(self.settings[section]):
                short, full = self.settings.option_help(section, option)
                print('%s.%s -- %s' % (section, option, short))

    @Command('settings-create',
        help='Print a new settings file with usage info.')
    def create(self):
        """Create an empty settings file with full documentation."""
        wrapper = TextWrapper(initial_indent='# ', subsequent_indent='# ')

        for section in sorted(self.settings):
            print('[%s]' % section)
            print('')

            for option in sorted(self.settings[section]):
                short, full = self.settings.option_help(section, option)

                print(wrapper.fill(full))
                print(';%s =' % option)
                print('')