1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""A module for the info implementation of Command.""" 6 7import cr 8 9 10class InfoCommand(cr.Command): 11 """The cr info command implementation.""" 12 13 def __init__(self): 14 super(InfoCommand, self).__init__() 15 self.help = 'Print information about the cr environment' 16 17 def AddArguments(self, subparsers): 18 parser = super(InfoCommand, self).AddArguments(subparsers) 19 parser.add_argument( 20 '-s', '--short', dest='_short', 21 action='store_true', default=False, 22 help='Short form results, useful for scripting.' 23 ) 24 self.ConsumeArgs(parser, 'the environment') 25 return parser 26 27 def EarlyArgProcessing(self): 28 if getattr(cr.context.args, '_short', False): 29 self.requires_build_dir = False 30 31 def Run(self): 32 if cr.context.remains: 33 for var in cr.context.remains: 34 if getattr(cr.context.args, '_short', False): 35 val = cr.context.Find(var) 36 if val is None: 37 val = '' 38 print val 39 else: 40 print var, '=', cr.context.Find(var) 41 else: 42 cr.base.client.PrintInfo() 43 44