diff --git a/atomicapp/cli/main.py b/atomicapp/cli/main.py index 443692cc..531c0cdc 100644 --- a/atomicapp/cli/main.py +++ b/atomicapp/cli/main.py @@ -52,9 +52,10 @@ def print_app_location(app_path): def cli_genanswers(args): argdict = args.__dict__ + location = argdict['answers'] nm = NuleculeManager(app_spec=argdict['app_spec'], destination='none') - nm.genanswers(**argdict) + nm.genanswers(location=location, **argdict) Utils.rm_dir(nm.app_path) # clean up files sys.exit(0) @@ -350,6 +351,11 @@ def create_parser(self): # === "genanswers" SUBPARSER === gena_subparser = toplevel_subparsers.add_parser( "genanswers", parents=[globals_parser]) + gena_subparser.add_argument( + "-a", + "--answers", + dest="answers", + help="Path to %s" % ANSWERS_FILE) gena_subparser.add_argument( "app_spec", nargs='?', diff --git a/atomicapp/nulecule/main.py b/atomicapp/nulecule/main.py index 1ce88b8d..084d6a57 100644 --- a/atomicapp/nulecule/main.py +++ b/atomicapp/nulecule/main.py @@ -131,7 +131,7 @@ def unpack(self, update=False, return Nulecule.load_from_path( self.app_path, dryrun=dryrun, config=config) - def genanswers(self, dryrun=False, answers_format=None, **kwargs): + def genanswers(self, dryrun=False, answers_format=None, location=None, **kwargs): """ Renders artifacts and then generates an answer file. Finally copies answer file to the current working directory. @@ -147,10 +147,19 @@ def genanswers(self, dryrun=False, answers_format=None, **kwargs): self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT # Check to make sure an answers.conf file doesn't exist already - answers_file = os.path.join(os.getcwd(), ANSWERS_FILE) + if location is None: + answers_file = os.path.join(os.getcwd(), ANSWERS_FILE) + else: + answers_file = os.path.join(location, ANSWERS_FILE) + if os.path.exists(answers_file): raise NuleculeException( - "Can't generate answers.conf over existing file") + "Can't generate %s over existing file" % answers_file) + + answers_folder = os.path.dirname(answers_file) + if not os.path.isdir(answers_folder): + raise NuleculeException( + "Directory %s does not exist." % answers_folder) # Call unpack to get the app code self.nulecule = self.unpack(update=False, dryrun=dryrun, config=self.answers)