Skip to content

Commit

Permalink
Merge pull request #854 from CleverCloud/davlgd-elastic-plugins
Browse files Browse the repository at this point in the history
feat(addon): elastic plugins option support
  • Loading branch information
hsablonniere authored Nov 27, 2024
2 parents 4ecd4a3 + 081c23c commit 239bf82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/clever.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function run () {
}),
addonOptions: cliparse.option('option', {
metavar: 'option',
parser: Parsers.addonOptions,
description: 'Option to enable for the add-on. Multiple --option argument can be passed to enable multiple options',
}),
region: cliparse.option('region', {
Expand Down
10 changes: 7 additions & 3 deletions src/models/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,14 @@ export function parseAddonOptions (options) {
return {};
}

return options.split(',').reduce((options, option) => {
const [key, value] = option.split('=');
const pairs = options.split(/,(?=\w+=)/) || [];

return pairs.reduce((options, pair) => {
const [key, ...valueParts] = pair.split('=');
const value = valueParts.join('=');

if (value == null) {
throw new Error("Options are malformed. Usage is '--option name=enabled|disabled|true|false'");
throw new Error("Options are malformed. Usage is '--option name=enabled|disabled|true|false|plugin1,plugin2'");
}

let formattedValue = value;
Expand Down
11 changes: 11 additions & 0 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import * as Application from './models/application.js';
import ISO8601 from 'iso8601-duration';
import Duration from 'duration-js';

const addonOptionsRegex = /^\w+=.+$/;

export function addonOptions (options) {
for (const option of options) {
if (!option.match(addonOptionsRegex)) {
return cliparse.parsers.error('Invalid option: ' + option);
}
}
return cliparse.parsers.success(options.join(','));
}

export function flavor (flavor) {
const flavors = Application.listAvailableFlavors();
if (flavors.includes(flavor)) {
Expand Down

0 comments on commit 239bf82

Please sign in to comment.