Skip to content

Commit

Permalink
feat(cli): align sync command with configuration schema
Browse files Browse the repository at this point in the history
  • Loading branch information
gu-stav committed Dec 24, 2024
1 parent 0b0e3d9 commit 10fd107
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/commands/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseOptions } from '../../options.js';
import { Command } from 'commander';
import { Command, Option } from 'commander';
import ansi from 'ansi-colors';

import {
Expand All @@ -21,7 +21,7 @@ import {
} from '../../client/TolgeeClient.js';

type Options = BaseOptions & {
backup?: string;
backup?: string | false;
removeUnused?: boolean;
continueOnWarning?: boolean;
yes?: boolean;
Expand Down Expand Up @@ -209,20 +209,28 @@ export default (config: Schema) =>
.description(
'Synchronizes the keys in your code project and in the Tolgee project, by creating missing keys and optionally deleting unused ones. For a dry-run, use `tolgee compare`.'
)
.option(
'-B, --backup <path>',
'Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.'
.addOption(
new Option(
'-B, --backup <path>',
'Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.'
).default(config.sync?.backup ?? false)
)
.option(
'--continue-on-warning',
'Set this flag to continue the sync if warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.'
.addOption(
new Option(
'--continue-on-warning',
'Set this flag to continue the sync if warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.'
).default(config.sync?.continueOnWarning ?? false)
)
.option(
'-Y, --yes',
'Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.'
.addOption(
new Option(
'-Y, --yes',
'Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.'
).default(config.sync?.yes ?? false)
)
.option(
'--remove-unused',
'Also delete unused keys from the Tolgee project.'
.addOption(
new Option(
'--remove-unused',
'Delete unused keys from the Tolgee project.'
).default(config.sync?.removeUnused ?? false)
)
.action(syncHandler(config));
18 changes: 18 additions & 0 deletions src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ export interface Schema {
*/
delimiter?: string | null;
};
sync?: {
/**
* Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.
*/
backup?: string;
/**
* Continue the sync regardless of whether warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.
*/
continueOnWarning?: boolean;
/**
* Delete unused keys from the Tolgee project
*/
removeUnused?: boolean;
/**
* Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.
*/
yes?: boolean;
}
}
export interface FileMatch {
path: Path;
Expand Down

0 comments on commit 10fd107

Please sign in to comment.