Skip to content

Commit cb93c6c

Browse files
committed
Add --git and --branch options
1 parent 6bf0cf1 commit cb93c6c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

commands/NewCommand.php

+30
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ protected function configure()
2121
->setDescription('Create a new Apiato application')
2222
->addArgument('name', InputArgument::REQUIRED)
2323
->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release')
24+
->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a Git repository')
25+
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'The branch that should be created for a new repository', 'main')
2426
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists')
2527
->setHelp('This command only shows a message to welcome user and nothing more.');
2628
}
@@ -95,6 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
9597
);
9698
}
9799

100+
// TODO: Remove github checks if dont want to implement github support
101+
if ($input->getOption('git') || $input->getOption('github') !== false) {
102+
$this->createRepository($directory, $input, $output);
103+
}
104+
98105
$output->writeln(PHP_EOL . '<comment>Apiato ready! Build something amazing.</comment>');
99106
}
100107

@@ -116,6 +123,29 @@ protected function getVersion(InputInterface $input)
116123
return '';
117124
}
118125

126+
/**
127+
* Create a Git repository and commit the base Laravel skeleton.
128+
*
129+
* @param string $directory
130+
* @param \Symfony\Component\Console\Input\InputInterface $input
131+
* @param \Symfony\Component\Console\Output\OutputInterface $output
132+
* @return void
133+
*/
134+
protected function createRepository(string $directory, InputInterface $input, OutputInterface $output)
135+
{
136+
chdir($directory);
137+
138+
$branch = $input->getOption('branch') ?: 'main';
139+
140+
$commands = [
141+
"git init -q -b {$branch} .",
142+
'git add .',
143+
'git commit -q -m "Set up a fresh Apiato app"',
144+
];
145+
146+
$this->runCommands($commands, $input, $output);
147+
}
148+
119149
/**
120150
* Verify that the application does not already exist.
121151
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy