Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept both -f and --force in the web terminal #13683

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/13683.txt
Original file line number Diff line number Diff line change
@@ -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.
```
2 changes: 1 addition & 1 deletion ui/app/components/console/ui-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default Component.extend({
let [method, flagArray, path, dataArray] = serviceArgs;

if (dataArray || flagArray) {
var { data, flags } = extractDataAndFlags(dataArray, flagArray);
var { data, flags } = extractDataAndFlags(method, dataArray, flagArray);
}

let inputError = logErrorFromInput(path, method, flags, dataArray);
Expand Down
6 changes: 5 additions & 1 deletion ui/app/lib/console-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parse } from 'shell-quote';
const supportedCommands = ['read', 'write', 'list', 'delete'];
const uiCommands = ['api', 'clearall', 'clear', 'fullscreen', 'refresh'];

export function extractDataAndFlags(data, flags) {
export function extractDataAndFlags(method, data, flags) {
return data.concat(flags).reduce(
(accumulator, val) => {
// will be "key=value" or "-flag=value" or "foo=bar=baz"
Expand All @@ -16,6 +16,10 @@ export function extractDataAndFlags(data, flags) {
let flagName = item.replace(/^-/, '');
if (flagName === 'wrap-ttl') {
flagName = 'wrapTTL';
} else if (method === 'write') {
if (flagName === 'f' || flagName === '-force') {
flagName = 'force';
}
}
accumulator.flags[flagName] = value || true;
return accumulator;
Expand Down
39 changes: 38 additions & 1 deletion ui/tests/unit/lib/console-helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ module('Unit | Lib | console helpers', function () {

const testExtractCases = [
{
method: 'read',
name: 'data fields',
input: [
[
Expand All @@ -144,6 +145,7 @@ module('Unit | Lib | console helpers', function () {
},
},
{
method: 'read',
name: 'repeated data and a flag',
input: [['allowed_domains=example.com', 'allowed_domains=foo.example.com'], ['-wrap-ttl=2h']],
expected: {
Expand All @@ -156,6 +158,7 @@ module('Unit | Lib | console helpers', function () {
},
},
{
method: 'read',
name: 'data with more than one equals sign',
input: [['foo=bar=baz', 'foo=baz=bop', 'some=value=val'], []],
expected: {
Expand All @@ -167,6 +170,7 @@ module('Unit | Lib | console helpers', function () {
},
},
{
method: 'read',
name: 'data with empty values',
input: [[`foo=`, 'some=thing'], []],
expected: {
Expand All @@ -177,11 +181,44 @@ module('Unit | Lib | console helpers', function () {
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) {
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(flags, testCase.expected.flags, 'has expected flags');
});
Expand Down