Accept both -f and --force in the web terminal (#13683)
* Accept both -f and --force in the web terminal This aligns the behavior of the web terminal with the `vault write ...` command to make it a bit more user friendly. * Add changelog * Use === instead of ==
This commit is contained in:
parent
fc7deabfd7
commit
3773ade7c6
|
@ -0,0 +1,4 @@
|
||||||
|
```release-note:improvement
|
||||||
|
ui: The integrated web terminal now accepts both `-f` and `--force` as aliases
|
||||||
|
for `-force` for the `write` commmand.
|
||||||
|
```
|
|
@ -71,7 +71,7 @@ export default Component.extend({
|
||||||
let [method, flagArray, path, dataArray] = serviceArgs;
|
let [method, flagArray, path, dataArray] = serviceArgs;
|
||||||
|
|
||||||
if (dataArray || flagArray) {
|
if (dataArray || flagArray) {
|
||||||
var { data, flags } = extractDataAndFlags(dataArray, flagArray);
|
var { data, flags } = extractDataAndFlags(method, dataArray, flagArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
let inputError = logErrorFromInput(path, method, flags, dataArray);
|
let inputError = logErrorFromInput(path, method, flags, dataArray);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { parse } from 'shell-quote';
|
||||||
const supportedCommands = ['read', 'write', 'list', 'delete'];
|
const supportedCommands = ['read', 'write', 'list', 'delete'];
|
||||||
const uiCommands = ['api', 'clearall', 'clear', 'fullscreen', 'refresh'];
|
const uiCommands = ['api', 'clearall', 'clear', 'fullscreen', 'refresh'];
|
||||||
|
|
||||||
export function extractDataAndFlags(data, flags) {
|
export function extractDataAndFlags(method, data, flags) {
|
||||||
return data.concat(flags).reduce(
|
return data.concat(flags).reduce(
|
||||||
(accumulator, val) => {
|
(accumulator, val) => {
|
||||||
// will be "key=value" or "-flag=value" or "foo=bar=baz"
|
// will be "key=value" or "-flag=value" or "foo=bar=baz"
|
||||||
|
@ -16,6 +16,10 @@ export function extractDataAndFlags(data, flags) {
|
||||||
let flagName = item.replace(/^-/, '');
|
let flagName = item.replace(/^-/, '');
|
||||||
if (flagName === 'wrap-ttl') {
|
if (flagName === 'wrap-ttl') {
|
||||||
flagName = 'wrapTTL';
|
flagName = 'wrapTTL';
|
||||||
|
} else if (method === 'write') {
|
||||||
|
if (flagName === 'f' || flagName === '-force') {
|
||||||
|
flagName = 'force';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
accumulator.flags[flagName] = value || true;
|
accumulator.flags[flagName] = value || true;
|
||||||
return accumulator;
|
return accumulator;
|
||||||
|
|
|
@ -125,6 +125,7 @@ module('Unit | Lib | console helpers', function () {
|
||||||
|
|
||||||
const testExtractCases = [
|
const testExtractCases = [
|
||||||
{
|
{
|
||||||
|
method: 'read',
|
||||||
name: 'data fields',
|
name: 'data fields',
|
||||||
input: [
|
input: [
|
||||||
[
|
[
|
||||||
|
@ -144,6 +145,7 @@ module('Unit | Lib | console helpers', function () {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
method: 'read',
|
||||||
name: 'repeated data and a flag',
|
name: 'repeated data and a flag',
|
||||||
input: [['allowed_domains=example.com', 'allowed_domains=foo.example.com'], ['-wrap-ttl=2h']],
|
input: [['allowed_domains=example.com', 'allowed_domains=foo.example.com'], ['-wrap-ttl=2h']],
|
||||||
expected: {
|
expected: {
|
||||||
|
@ -156,6 +158,7 @@ module('Unit | Lib | console helpers', function () {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
method: 'read',
|
||||||
name: 'data with more than one equals sign',
|
name: 'data with more than one equals sign',
|
||||||
input: [['foo=bar=baz', 'foo=baz=bop', 'some=value=val'], []],
|
input: [['foo=bar=baz', 'foo=baz=bop', 'some=value=val'], []],
|
||||||
expected: {
|
expected: {
|
||||||
|
@ -167,6 +170,7 @@ module('Unit | Lib | console helpers', function () {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
method: 'read',
|
||||||
name: 'data with empty values',
|
name: 'data with empty values',
|
||||||
input: [[`foo=`, 'some=thing'], []],
|
input: [[`foo=`, 'some=thing'], []],
|
||||||
expected: {
|
expected: {
|
||||||
|
@ -177,11 +181,44 @@ module('Unit | Lib | console helpers', function () {
|
||||||
flags: {},
|
flags: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
method: 'write',
|
||||||
|
name: 'write with force flag',
|
||||||
|
input: [[], ['-force']],
|
||||||
|
expected: {
|
||||||
|
data: {},
|
||||||
|
flags: {
|
||||||
|
force: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'write',
|
||||||
|
name: 'write with force short flag',
|
||||||
|
input: [[], ['-f']],
|
||||||
|
expected: {
|
||||||
|
data: {},
|
||||||
|
flags: {
|
||||||
|
force: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'write',
|
||||||
|
name: 'write with GNU style force flag',
|
||||||
|
input: [[], ['--force']],
|
||||||
|
expected: {
|
||||||
|
data: {},
|
||||||
|
flags: {
|
||||||
|
force: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
testExtractCases.forEach(function (testCase) {
|
testExtractCases.forEach(function (testCase) {
|
||||||
test(`#extractDataAndFlags: ${testCase.name}`, function (assert) {
|
test(`#extractDataAndFlags: ${testCase.name}`, function (assert) {
|
||||||
let { data, flags } = extractDataAndFlags(...testCase.input);
|
let { data, flags } = extractDataAndFlags(testCase.method, ...testCase.input);
|
||||||
assert.deepEqual(data, testCase.expected.data, 'has expected data');
|
assert.deepEqual(data, testCase.expected.data, 'has expected data');
|
||||||
assert.deepEqual(flags, testCase.expected.flags, 'has expected flags');
|
assert.deepEqual(flags, testCase.expected.flags, 'has expected flags');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue