1# Copyright 2015 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 gn command."""
6
7import os
8
9import cr
10
11
12class GnCommand(cr.Command):
13  """The implementation of the gn command.
14
15  The gn command is meant for running the gn tool without having to manually
16  specify an out directory.
17  """
18
19  def __init__(self):
20    super(GnCommand, self).__init__()
21    self.help = 'Run gn with the currently selected out directory'
22    self.description = ("""
23        Runs the gn command with the currently selected out directory as the
24        second argument.
25        """)
26
27  def AddArguments(self, subparsers):
28    parser = super(GnCommand, self).AddArguments(subparsers)
29    self.ConsumeArgs(parser, 'gn')
30    return parser
31
32  def Run(self):
33    out_path = os.path.join(cr.context['CR_SRC'],
34                            cr.context['CR_OUT_FULL'])
35    args = cr.context.remains
36    if args:
37      cr.Host.Execute('gn', args[0], out_path, *args[1:])
38    else:
39      cr.Host.Execute('gn')
40