require 'commander/blank' require 'commander/command' module Analytics module Command # A class called from CLI's 'init' argument, # which generates the project's configuration file depending on the user's input. class Init include Helpers::Terminal # Entry point of this class - the only public method in it. def perform lang = lang_selection analytics_path = analytics_path_selection src_path = src_path_selection config = { language: lang, analyticsFilesPath: analytics_path, sourcePath: src_path } Analytics::IO::Config.write(config) prompt.ok('Configuration file is properly created. You\'re good to go!') end ## The following methods are used to retrieve project information, ## in order to create analytitcs.yml configuration file. private # Prompts a user to select a programming language. def lang_selection languages = { 'Swift' => 'swift', 'Objective-C' => 'objc', 'Both' => 'swift-objc' } prompt.select('Select lang:', languages) end # Prompts a user to select a path to which the generated # analytics files will be saved. def analytics_path_selection prompt.ask('Where would You like to store analytics files? (Press enter to use default path)', default: './Common/Analytics/') end # Prompts a user to select a path in which he'll hold a source json file, # from which the analytics files will be generated. def src_path_selection prompt.ask('Where would You like to store json file from which analytics files will be generated? (Press enter to use default path)', default: 'analytics-source.json') end end end end