diff --git a/Mage/Config.php b/Mage/Config.php
index 85ed1b9..454d681 100644
--- a/Mage/Config.php
+++ b/Mage/Config.php
@@ -6,14 +6,16 @@ class Mage_Config
public function loadEnvironment($environment)
{
- if ($environment != '') {
- $this->_environment = yaml_parse_file('.mage/config/environment/' . $environment . '.yaml');
+ if (($environment != '') && file_exists('.mage/config/environment/' . $environment . '.yaml')) {
+ $this->_environment = @yaml_parse_file('.mage/config/environment/' . $environment . '.yaml');
}
}
public function loadSCM()
{
- $this->_scm = yaml_parse_file('.mage/config/scm.yaml');
+ if (file_exists('.mage/config/scm.yaml')) {
+ $this->_scm = @yaml_parse_file('.mage/config/scm.yaml');
+ }
}
public function getEnvironment()
diff --git a/Mage/Console.php b/Mage/Console.php
index 0dca4b8..9f643b7 100644
--- a/Mage/Console.php
+++ b/Mage/Console.php
@@ -22,6 +22,9 @@ class Mage_Console
} else if ($this->_args[0] == 'add') {
$this->_action = 'add';
+
+ } else if ($this->_args[0] == 'init') {
+ $this->_action = 'init';
}
foreach ($this->_args as $argument) {
@@ -76,6 +79,11 @@ class Mage_Console
$task->run($config);
break;
+ case 'init';
+ $task = new Mage_Task_Init;
+ $task->run();
+ break;
+
case 'add';
switch ($this->_args[1]) {
case 'environment':
diff --git a/Mage/Task/Add.php b/Mage/Task/Add.php
index 4a6a7fd..2cd3d42 100644
--- a/Mage/Task/Add.php
+++ b/Mage/Task/Add.php
@@ -10,7 +10,7 @@ class Mage_Task_Add
// Check if there is already an environment with the same name
if (file_exists($environmentConfigFile)) {
- Mage_Console::output('Error!! Already exists an environment called ' . $environmentName . '');
+ Mage_Console::output('Error!! Already exists an environment called ' . $environmentName . '', 1, 2);
} else {
$baseConfig = '#' . $environmentName . PHP_EOL
. 'user: dummy' . PHP_EOL
@@ -25,13 +25,10 @@ class Mage_Task_Add
if ($result) {
Mage_Console::output('Success!! Environment config file for ' . $environmentName . ' created successfully at ' . $environmentConfigFile . '');
- Mage_Console::output('So please! Review and adjust its configuration.', 2);
+ Mage_Console::output('So please! Review and adjust its configuration.', 2, 2);
} else {
- Mage_Console::output('Error!! Unable to create config file for environment called ' . $environmentName . '');
+ Mage_Console::output('Error!! Unable to create config file for environment called ' . $environmentName . '', 1, 2);
}
}
-
- Mage_Console::output('');
}
-
}
\ No newline at end of file
diff --git a/Mage/Task/Init.php b/Mage/Task/Init.php
new file mode 100644
index 0000000..b440ed8
--- /dev/null
+++ b/Mage/Task/Init.php
@@ -0,0 +1,31 @@
+Magallanes');
+
+ // Check if there is already a config dir
+ if (file_exists($configDir)) {
+ Mage_Console::output('Error!! Already exists .mage directory.', 1, 2);
+ } else {
+ $results = array();
+ $results[] = mkdir($configDir);
+ $results[] = mkdir($configDir . '/logs');
+ $results[] = mkdir($configDir . '/tasks');
+ $results[] = mkdir($configDir . '/config');
+ $results[] = mkdir($configDir . '/config/environment');
+ $results[] = file_put_contents($configDir . '/config/global.yaml', '#global settings' . PHP_EOL . PHP_EOL);
+ $results[] = file_put_contents($configDir . '/config/scm.yaml', '#scm settings' . PHP_EOL . PHP_EOL);
+
+ if (!in_array(false, $results)) {
+ Mage_Console::output('Success!! The configuration for Magallanes has been generated at .mage directory.');
+ Mage_Console::output('Please!! Review and adjust the configuration.', 2, 2);
+ } else {
+ Mage_Console::output('Error!! Unable to generate the configuration.', 1, 2);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/bin/mage.php b/bin/mage.php
index 10aab3d..e2824e4 100644
--- a/bin/mage.php
+++ b/bin/mage.php
@@ -1,14 +1,13 @@
parse();
$console->run();
-
Mage_Console::output('Finished Magallanes', 0, 2);