Skip to content

Commit

Permalink
Merge pull request #13 from Pisyukaev:accept-changes-in-all-files
Browse files Browse the repository at this point in the history
Add option to accept changes in all files
  • Loading branch information
Pisyukaev authored Nov 15, 2023
2 parents 38a31f9 + 98bdec2 commit 6b30b3f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/commands/addString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export function builder(yargs: Argv) {
desc: 'Sorted keys of strings by asc or desc',
type: 'string'
})
.option('accept', {
alias: 'y',
desc: 'Accept add in all files',
type: 'boolean',
default: false
})
.usage(
`\nExample:\n $0 ${command} --key key.of.string --value "locale string"`
);
Expand All @@ -40,12 +46,14 @@ export async function handler({
key,
value,
directory,
sort
sort,
accept
}: ArgumentsCamelCase<{
key: string;
value: string;
directory: string;
sort?: 'asc' | 'desc';
accept: boolean;
}>) {
modificationFile(add({ key, directory, value, sort }), directory);
modificationFile(add({ key, directory, value, sort, accept }), directory);
}
13 changes: 11 additions & 2 deletions src/commands/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,36 @@ export function builder(yargs: Argv) {
alias: 's',
desc: 'Sorted keys of strings by asc or desc',
type: 'string'
})
.option('accept', {
alias: 'y',
desc: 'Accept change in all files',
type: 'boolean',
default: false
});
}

export async function handler({
oldkey: oldKeyValue,
newkey: newKeyValue,
directory,
sort
sort,
accept
}: ArgumentsCamelCase<{
oldkey: string;
newkey: string;
directory: string;
sort?: 'asc' | 'desc';
accept: boolean;
}>) {
console.log(oldKeyValue, newKeyValue);

modificationFile(
change({
oldKey: oldKeyValue,
newKey: newKeyValue,
sort
sort,
accept
}),
directory
);
Expand Down
12 changes: 10 additions & 2 deletions src/commands/delString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export function builder(yargs: Argv) {
desc: 'Sorted keys of strings by asc or desc',
type: 'string'
})
.option('accept', {
alias: 'y',
desc: 'Accept delete in all files',
type: 'boolean',
default: false
})
.usage(
`\nExample:\n ${command} --key key.of.string --directory src/locales`
);
Expand All @@ -33,11 +39,13 @@ export function builder(yargs: Argv) {
export async function handler({
key: keyValue,
directory,
sort
sort,
accept
}: ArgumentsCamelCase<{
key: string;
directory: string;
sort?: 'asc' | 'desc';
accept: boolean;
}>) {
modificationFile(del({ keyValue, sort }), directory);
modificationFile(del({ keyValue, sort, accept }), directory);
}
6 changes: 4 additions & 2 deletions src/modifiers/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function add(options: {
value: string;
directory: string;
sort?: 'asc' | 'desc';
accept: boolean;
}) {
let REPLACE_ALL = false;
let NEED_REPLACE = false;
Expand All @@ -18,14 +19,15 @@ export function add(options: {
filePath: string;
jsonXml: XmlJson;
}) {
const { key, value, sort: sortDirection } = options;
const { key, value, sort: sortDirection, accept } = options;

const {
resources: { string }
} = jsonXml;

const hasKey = checkKeyExist(key, string);

if (!REPLACE_ALL && hasKey) {
if (!accept && !REPLACE_ALL && hasKey) {
const answer = await hasConflict(filePath);

switch (answer) {
Expand Down
5 changes: 3 additions & 2 deletions src/modifiers/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function change(options: {
oldKey: string;
newKey: string;
sort?: 'asc' | 'desc';
accept: boolean;
}) {
let REPLACE_ALL = false;
let NEED_REPLACE = false;
Expand All @@ -17,14 +18,14 @@ export function change(options: {
filePath: string;
jsonXml: XmlJson;
}) {
const { oldKey, newKey, sort: sortDirection } = options;
const { oldKey, newKey, sort: sortDirection, accept } = options;
const {
resources: { string }
} = jsonXml;

const hasKey = checkKeyValueExist(oldKey, string);

if (!REPLACE_ALL && hasKey) {
if (!accept && !REPLACE_ALL && hasKey) {
const answer = await hasConflict(filePath);

switch (answer) {
Expand Down
10 changes: 7 additions & 3 deletions src/modifiers/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { checkKeyValueExist } from '../utils/files';
import { deleteAnswer } from '../utils/queries';
import { sort } from './sort';

export function del(options: { keyValue: string; sort?: 'asc' | 'desc' }) {
export function del(options: {
keyValue: string;
sort?: 'asc' | 'desc';
accept: boolean;
}) {
let DELETE_ALL = false;
let NEED_DELETE = false;

Expand All @@ -13,14 +17,14 @@ export function del(options: { keyValue: string; sort?: 'asc' | 'desc' }) {
filePath: string;
jsonXml: XmlJson;
}) {
const { keyValue, sort: sortDirection } = options;
const { keyValue, sort: sortDirection, accept } = options;
const {
resources: { string }
} = jsonXml;

const hasKeyValue = checkKeyValueExist(keyValue, string);

if (!DELETE_ALL && hasKeyValue) {
if (!accept && !DELETE_ALL && hasKeyValue) {
const answer = await deleteAnswer(filePath);

switch (answer) {
Expand Down

0 comments on commit 6b30b3f

Please sign in to comment.