|
19 | 19 | use Magento\Config\Console\Command\ConfigShow\ValueProcessor;
|
20 | 20 |
|
21 | 21 | /**
|
22 |
| - * Command provides possibility to show system configuration. |
| 22 | + * Command provides possibility to show saved system configuration. |
23 | 23 | */
|
24 | 24 | class ConfigShowCommand extends Command
|
25 | 25 | {
|
@@ -74,7 +74,7 @@ class ConfigShowCommand extends Command
|
74 | 74 | private $scopeCode;
|
75 | 75 |
|
76 | 76 | /**
|
77 |
| - * The path of configuration. |
| 77 | + * The configuration path. |
78 | 78 | *
|
79 | 79 | * @var string
|
80 | 80 | */
|
@@ -108,67 +108,86 @@ protected function configure()
|
108 | 108 | $this->addArgument(
|
109 | 109 | self::INPUT_ARGUMENT_PATH,
|
110 | 110 | InputArgument::OPTIONAL,
|
111 |
| - 'Configuration path for example group/section/field_name' |
| 111 | + 'Configuration path, for example section_id/group_id/field_id' |
112 | 112 | );
|
113 | 113 | $this->addOption(
|
114 | 114 | self::INPUT_OPTION_SCOPE,
|
115 | 115 | null,
|
116 | 116 | InputOption::VALUE_OPTIONAL,
|
117 |
| - 'Scope for configuration, if not set use \'default\'', |
| 117 | + 'Scope for configuration, if not specified, then \'default\' scope will be used', |
118 | 118 | ScopeConfigInterface::SCOPE_TYPE_DEFAULT
|
119 | 119 | );
|
120 | 120 | $this->addOption(
|
121 | 121 | self::INPUT_OPTION_SCOPE_CODE,
|
122 | 122 | null,
|
123 | 123 | InputOption::VALUE_OPTIONAL,
|
124 |
| - 'Scope code for configuration, empty string by default', |
| 124 | + 'Scope code (required only if scope is not `default`)', |
125 | 125 | ''
|
126 | 126 | );
|
127 | 127 | $this->setName('config:show')
|
128 |
| - ->setDescription('Shows configuration value for given path'); |
| 128 | + ->setDescription( |
| 129 | + 'Shows configuration value for given path. If path is not specified, all saved values will be shown' |
| 130 | + ); |
129 | 131 | parent::configure();
|
130 | 132 | }
|
131 | 133 |
|
132 | 134 | /**
|
133 | 135 | * Displays configuration value for given configuration path.
|
134 | 136 | *
|
135 |
| - * Shows error message if configuration for given path doesn't exists |
| 137 | + * Shows error message if configuration for given path doesn't exist |
136 | 138 | * or scope/scope-code doesn't pass validation.
|
137 | 139 | *
|
138 | 140 | * {@inheritdoc}
|
139 | 141 | */
|
140 | 142 | protected function execute(InputInterface $input, OutputInterface $output)
|
141 | 143 | {
|
142 |
| - $this->scope = $input->getOption(self::INPUT_OPTION_SCOPE); |
143 |
| - $this->scopeCode = $input->getOption(self::INPUT_OPTION_SCOPE_CODE); |
144 |
| - $this->inputPath = $input->getArgument(self::INPUT_ARGUMENT_PATH); |
145 |
| - |
146 | 144 | try {
|
| 145 | + $this->scope = $input->getOption(self::INPUT_OPTION_SCOPE); |
| 146 | + $this->scopeCode = $input->getOption(self::INPUT_OPTION_SCOPE_CODE); |
| 147 | + $this->inputPath = $input->getArgument(self::INPUT_ARGUMENT_PATH); |
| 148 | + |
147 | 149 | $this->scopeValidator->isValid($this->scope, $this->scopeCode);
|
148 | 150 | $configPath = $this->pathResolver->resolve($this->inputPath, $this->scope, $this->scopeCode);
|
149 | 151 | $configValue = $this->configSource->get($configPath);
|
150 |
| - } catch (LocalizedException $e) { |
151 |
| - $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
152 |
| - return Cli::RETURN_FAILURE; |
153 |
| - } |
154 | 152 |
|
155 |
| - if (empty($configValue)) { |
156 |
| - $output->writeln(sprintf( |
157 |
| - '<error>%s</error>', |
158 |
| - __('Configuration for path: "%1" doesn\'t exist', $this->inputPath)->render() |
159 |
| - )); |
| 153 | + if (empty($configValue)) { |
| 154 | + $output->writeln(sprintf( |
| 155 | + '<error>%s</error>', |
| 156 | + __('Configuration for path: "%1" doesn\'t exist', $this->inputPath)->render() |
| 157 | + )); |
| 158 | + return Cli::RETURN_FAILURE; |
| 159 | + } |
| 160 | + |
| 161 | + $this->outputResult($output, $configValue, $this->inputPath); |
| 162 | + return Cli::RETURN_SUCCESS; |
| 163 | + } catch (\Exception $e) { |
| 164 | + $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
160 | 165 | return Cli::RETURN_FAILURE;
|
161 | 166 | }
|
162 |
| - |
163 |
| - $this->outputResult($output, $configValue, $this->inputPath); |
164 |
| - return Cli::RETURN_SUCCESS; |
165 | 167 | }
|
166 | 168 |
|
167 | 169 | /**
|
168 | 170 | * Outputs single configuration value or list of values if array given.
|
169 | 171 | *
|
170 | 172 | * @param OutputInterface $output an OutputInterface instance
|
171 |
| - * @param mixed $configValue single value or array of values |
| 173 | + * @param mixed $configValue can be string when $configPath is a path for concreate field. |
| 174 | + * In other cases $configValue should be an array |
| 175 | + * ```php |
| 176 | + * [ |
| 177 | + * 'section' => |
| 178 | + * [ |
| 179 | + * 'group1' => |
| 180 | + * [ |
| 181 | + * 'field1' => 'value1', |
| 182 | + * 'field2' => 'value2' |
| 183 | + * ], |
| 184 | + * 'group2' => |
| 185 | + * [ |
| 186 | + * 'field1' => 'value3' |
| 187 | + * ] |
| 188 | + * ] |
| 189 | + * ] |
| 190 | + * ``` |
172 | 191 | * @param string $configPath base configuration path
|
173 | 192 | * @return void
|
174 | 193 | */
|
|
0 commit comments