From 8827135715c2b540d2e48cd005ad04d1b4e992e7 Mon Sep 17 00:00:00 2001 From: Serhii Polishchuk Date: Wed, 17 Aug 2016 19:26:51 +0300 Subject: [PATCH 1/2] Move certificationy console command to bin directory --- README.md | 12 ++++++------ certificationy.php => bin/certificationy | 11 +++++++++-- composer.json | 5 ++++- 3 files changed, 19 insertions(+), 9 deletions(-) rename certificationy.php => bin/certificationy (75%) mode change 100644 => 100755 diff --git a/README.md b/README.md index 6b09623..7e91fa5 100644 --- a/README.md +++ b/README.md @@ -15,28 +15,28 @@ This is the CLI tool to train on certifications. ## Using Composer ``` $ composer create-project certificationy/certificationy-cli -$ php certificationy.php +$ bin/certificationy ``` ## More run options ### Select the number of questions ``` -$ php certificationy.php start --number=10 +$ bin/certificationy start --number=10 ``` The default value is 20. ### List categories ``` -$ php certificationy.php start --list [-l] +$ bin/certificationy start --list [-l] ``` Will list all the categories available ### Only questions from certain categories ``` -$ php certificationy.php start "Automated tests" "Bundles" +$ bin/certificationy start "Automated tests" "Bundles" ``` Will only get the questions from the categories "Automated tests" and "Bundles" @@ -45,14 +45,14 @@ Use the category list from [List categories](#list-categories) ### Show if a question has multiple choices ``` -$ php certificationy.php start --show-multiple-choice +$ bin/certificationy start --show-multiple-choice ``` ![Multiple choices](https://cloud.githubusercontent.com/assets/795661/3308225/721b5324-f679-11e3-8d9d-62ba32cd8e32.png "Multiple choices") ### And all combined ``` -$ php certificationy.php start --number=5 --show-multiple-choice "Automated tests" "Bundles" +$ bin/certificationy start --number=5 --show-multiple-choice "Automated tests" "Bundles" ``` * 5 questions diff --git a/certificationy.php b/bin/certificationy old mode 100644 new mode 100755 similarity index 75% rename from certificationy.php rename to bin/certificationy index 730abc7..c09dd14 --- a/certificationy.php +++ b/bin/certificationy @@ -11,7 +11,14 @@ * file that was distributed with this source code. */ -require __DIR__ . '/vendor/autoload.php'; +$autoloadFiles = array(__DIR__.'/../vendor/autoload.php', + __DIR__.'/../../../autoload.php'); + +foreach ($autoloadFiles as $autoloadFile) { + if (file_exists($autoloadFile)) { + require_once $autoloadFile; + } +} use Certificationy\Cli\Command\StartCommand; use KevinGH\Amend\Command; @@ -24,7 +31,7 @@ $application = new Application(APPLICATION_NAME, VERSION); -$config = Yaml::parse(file_get_contents('config.yml')); +$config = Yaml::parse(file_get_contents(__DIR__.'/../config.yml')); $updateCommand = new Command('self-update'); $updateCommand->setManifestUri($config['manifest_uri']); $application->add($updateCommand); diff --git a/composer.json b/composer.json index de10837..0f4487a 100644 --- a/composer.json +++ b/composer.json @@ -42,5 +42,8 @@ "branch-alias": { "dev-master": "1.0.x-dev" } - } + }, + "bin": [ + "bin/certificationy" + ] } From 11e0fed40dd87640186956f4ad5e89a4cbcd1fad Mon Sep 17 00:00:00 2001 From: Alex Moshta Date: Wed, 17 Aug 2016 20:25:09 +0300 Subject: [PATCH 2/2] added options for custom config --- Command/StartCommand.php | 14 +++++++++----- README.md | 7 +++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Command/StartCommand.php b/Command/StartCommand.php index dda7530..103aed8 100644 --- a/Command/StartCommand.php +++ b/Command/StartCommand.php @@ -48,6 +48,7 @@ protected function configure() ->addOption("training", null, InputOption::VALUE_NONE, "Training mode: the solution is displayed after each question") ->addOption('show-multiple-choice', null, InputOption::VALUE_OPTIONAL, 'Should we tell you when the question is multiple choice?', true) ->addArgument('categories', InputArgument::IS_ARRAY, 'Which categories do you want (separate multiple with a space)', array()) + ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom config', null) ; } @@ -56,15 +57,16 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $config = $this->path($input->getOption('config')); if ($input->getOption('list')) { - $output->writeln(Loader::getCategories($this->path())); + $output->writeln(Loader::getCategories($config)); return ; } $categories = $input->getArgument('categories'); $number = $input->getOption('number'); - $set = Loader::init($number, $categories, $this->path()); + $set = Loader::init($number, $categories, $config); if ($set->getQuestions()) { $output->writeln( @@ -166,11 +168,13 @@ protected function displayResults(Set $set, OutputInterface $output) /** * Returns configuration file path * - * @return String $path The configuration filepath + * @param null|string $config + * + * @return String $path The configuration filepath */ - protected function path() + protected function path($config = null) { - return dirname(__DIR__).DIRECTORY_SEPARATOR.'config.yml'; + return $config ? $config : dirname(__DIR__).DIRECTORY_SEPARATOR.('config.yml'); } } diff --git a/README.md b/README.md index 7e91fa5..f2bd0f6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,13 @@ $ bin/certificationy start --show-multiple-choice ![Multiple choices](https://cloud.githubusercontent.com/assets/795661/3308225/721b5324-f679-11e3-8d9d-62ba32cd8e32.png "Multiple choices") +### Set custom configuration file +``` +$ bin/certificationy start --config=../config.yml +``` + +Will set custom config file + ### And all combined ``` $ bin/certificationy start --number=5 --show-multiple-choice "Automated tests" "Bundles"