Skip to content

Commit

Permalink
Added an "init" command
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed May 30, 2014
1 parent 0266b04 commit 6a24da9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,35 @@ versioned in your repository with your source, compiled to HTML and published to

You can [download it manually](http://mnapoli.fr/Couscous/couscous.phar) or install it through CLI:

```
```bash
# Download couscous.phar
wget http://mnapoli.fr/Couscous/couscous.phar

# Move it to /usr/local/bin
chmod +x couscous.phar
sudo mv couscous.phar /usr/local/bin/couscous
```

If you don't want to install it globally, you can also just download the phar in the current directory
and later run it with `php couscous.phar` instead of just `couscous`.


### Init

You have two options to start using Couscous:

- automatically init the project with default files
- write the files yourself

To init your project automatically, just run:

```bash
couscous init
```

The next sections explain how to create the files manually (and customize them).
You can read them now or jump to the "Preview" section and read them later.


### Configuration

Expand Down
5 changes: 3 additions & 2 deletions bin/couscous
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

use Couscous\CLI\DeployCommand;
use Couscous\CLI\GenerateCommand;
use Couscous\CLI\PreviewCommand;
use Couscous\CLI\InitCommand;use Couscous\CLI\PreviewCommand;
use Symfony\Component\Console\Application;

require_once __DIR__ . '/../vendor/autoload.php';

$application = new Application('Couscous', '1.0');
$application = new Application('Couscous', '0.2.0');

$application->add(new InitCommand);
$application->add(new GenerateCommand);
$application->add(new PreviewCommand());
$application->add(new DeployCommand());
Expand Down
62 changes: 62 additions & 0 deletions src/CLI/InitCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Couscous\CLI;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Initialize the directory for Couscous.
*
* @author Matthieu Napoli <[email protected]>
*/
class InitCommand extends Command
{
protected function configure()
{
$this
->setName('init')
->setDescription('Initialize the directory for Couscous');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
if (! file_exists(getcwd() . '/couscous.yml')) {
$output->writeln('<comment>Creating a new default couscous.yml file.</comment>');
touch(getcwd() . '/couscous.yml');
}

if (! file_exists(getcwd() . '/website')) {
$output->writeln('<comment>Creating a new default website/ directory.</comment>');
mkdir(getcwd() . '/website');
}

if (! file_exists(getcwd() . '/website/page.twig')) {
$output->writeln('<comment>Importing the default template.</comment>');
$template = <<<HTML
<!DOCTYPE html>
<html>
<head>
<title>Documentation</title>
</head>
<body>
{{ content|raw }}
</body>
</html>
HTML;
file_put_contents(getcwd() . '/website/page.twig', $template);
mkdir(getcwd() . '/website/public');
}

if (! file_exists(getcwd() . '/README.md')) {
$output->writeln('<comment>Creating a new default README.md file.</comment>');
$readme = <<<HTML
Welcome!
HTML;
file_put_contents(getcwd() . '/README.md', $readme);
}

$output->writeln('<comment>The current directory is ready to work with Couscous.</comment>');
}
}

0 comments on commit 6a24da9

Please sign in to comment.