Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 490929f

Browse files
committed
Change configure command to be options so it can be customised how it's configured.
1 parent de9cdbb commit 490929f

File tree

1 file changed

+56
-35
lines changed

1 file changed

+56
-35
lines changed

src/Meanbee/Magedbm/Command/ConfigureCommand.php

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ protected function configure()
1818
{
1919
$this
2020
->setName('configure')
21-
->setDescription('Configure with Amazon Credentials')
22-
->addArgument(
23-
'key',
24-
InputArgument::REQUIRED,
25-
'AWS Key'
21+
->setDescription('Configure with Amazon Credentials.')
22+
->addOption(
23+
'--key',
24+
'-k',
25+
InputOption::VALUE_REQUIRED,
26+
'AWS Access Key ID'
2627
)
27-
->addArgument(
28-
'secret',
29-
InputArgument::REQUIRED,
30-
'AWS Secret'
28+
->addOption(
29+
'--secret',
30+
'-s',
31+
InputOption::VALUE_REQUIRED,
32+
'AWS Secret Access Key'
3133
)
32-
->addArgument(
34+
->addOption(
3335
'region',
34-
InputArgument::REQUIRED,
35-
'Default Region'
36+
'-r',
37+
InputOption::VALUE_REQUIRED,
38+
'Default AWS Region'
3639
)
37-
->addArgument(
40+
->addOption(
3841
'bucket',
39-
InputArgument::REQUIRED,
40-
'Default Bucket'
42+
'-b',
43+
InputOption::VALUE_REQUIRED,
44+
'Default AWS S3 Bucket'
4145
)
4246
->addOption(
4347
'--force',
@@ -83,28 +87,45 @@ protected function execute(InputInterface $input, OutputInterface $output)
8387
exit;
8488
}
8589

86-
$credentials = array(
87-
'default' => array(
88-
'aws_access_key_id' => $input->getArgument('key'),
89-
'aws_secret_access_key' => $input->getArgument('secret')
90-
)
91-
);
92-
$config = array(
93-
'default' => array(
94-
'region' => $input->getArgument('region')
95-
)
96-
);
97-
$magedbmconfig = array(
98-
'default' => array(
99-
'bucket' => $input->getArgument('bucket')
100-
)
101-
);
90+
if ($input->getOption('key') && $input->getOption('secret')) {
91+
$credentials = array(
92+
'default' => array(
93+
'aws_access_key_id' => $input->getOption('key'),
94+
'aws_secret_access_key' => $input->getOption('secret')
95+
)
96+
);
10297

103-
$writer->writeToFile($this->getAwsCredentialsPath(), $credentials);
104-
$writer->writeToFile($this->getAwsConfigPath(), $config);
105-
$writer->writeToFile($this->getAppConfigPath(), $magedbmconfig);
98+
$writer->writeToFile($this->getAwsCredentialsPath(), $credentials);
99+
$this->getOutput()->writeln('<info>Successfully configured AWS credentials.</info>');
100+
} elseif (!file_exists($this->getAwsCredentialsPath())) {
101+
$this->getOutput()->writeln('<error>No AWS credentials were found, nor provided.</error>');
102+
}
103+
104+
if ($input->getOption('region')) {
105+
$config = array(
106+
'default' => array(
107+
'region' => $input->getOption('region')
108+
)
109+
);
110+
111+
$writer->writeToFile($this->getAwsConfigPath(), $config);
112+
$this->getOutput()->writeln('<info>Successfully configured AWS region config.</info>');
113+
} else if (!file_exists($this->getAwsConfigPath())) {
114+
$this->getOutput()->writeln('<error>No AWS config was found, nor provided.</error>');
115+
}
116+
117+
if ($input->getOption('bucket')) {
118+
$magedbmconfig = array(
119+
'default' => array(
120+
'bucket' => $input->getOption('bucket')
121+
)
122+
);
106123

107-
$this->getOutput()->writeln('<info>Successfully configured.</info>');
124+
$writer->writeToFile($this->getAppConfigPath(), $magedbmconfig);
125+
$this->getOutput()->writeln('<info>Successfully configured magedbm config.</info>');
126+
} elseif (!file_exists($this->getAppConfigPath())) {
127+
$this->getOutput()->writeln('<error>No MageDBM was found, nor provided.</error>');
128+
}
108129
}
109130

110131
/**

0 commit comments

Comments
 (0)