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

Update the search-replace command to follow the VIP-CLI style guide #2079

Merged
merged 15 commits into from
Nov 21, 2024
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: 2 additions & 2 deletions src/bin/vip-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ void command( {
)
.option(
'in-place',
'Perform a search and replace operation on a local SQL file, save the results to the file, then import the updated file.'
'Overwrite the local input file with the results of the search and replace operation prior to import.'
)
.option(
'output',
'Create a local copy of the imported file with the completed search and replace operations. Ignored if the command includes --in-place, or excludes a --search-replace operation. Accepts a local file path.'
'The local file path to save a copy of the results from the search and replace operation when the --search-replace option is passed. Ignored when used with the --in-place option.'
)
.examples( examples )
.argv( process.argv, async ( arg, opts ) => {
Expand Down
28 changes: 17 additions & 11 deletions src/bin/vip-search-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,39 @@ const debug = debugLib( '@automattic/vip:bin:vip-search-replace' );
const examples = [
// `search-replace` flag
{
usage: 'vip search-replace <file.sql> --search-replace="from,to"',
usage: 'vip search-replace file.sql --search-replace="from,to"',
description:
'Replace instances of <from> with <to> in the provided <file.sql>\n' +
' * Ensure there are no spaces between your search-replace parameters',
'Search for every instance of the value "from" in the local input file named "file.sql" and replace it with the value "to".\n' +
' * Results of the operation output to STDOUT by default.',
},
// `in-place` flag
{
usage: 'vip search-replace <file.sql> --search-replace="from,to" --in-place',
description: 'Perform Search and Replace explicitly on the provided input <file.sql> file',
usage: 'vip search-replace file.sql --search-replace="from,to" --in-place',
description:
'Perform the search and replace operation on the local input file "file.sql" and overwrite the file with the results.',
},
// `output` flag
{
usage: 'vip search-replace <file.sql> --search-replace="from,to" --output="<output.sql>"',
usage: 'vip search-replace file.sql --search-replace="from,to" --output=output-file.sql',
description:
'Search and Replace to the specified output <output.sql> file\n' +
' * Has no effect when the `in-place` flag is used',
'Perform the search and replace operation and save the results to a local clone of the input file named "output-file.sql".',
yolih marked this conversation as resolved.
Show resolved Hide resolved
},
];

command( {
requiredArgs: 1,
} )
.option( 'search-replace', 'Specify the <from> and <to> pairs to be replaced' )
.option( 'in-place', 'Perform the search and replace explicitly on the input file' )
.option(
'search-replace',
'A comma-separated pair of strings that specify the values to search for and replace (e.g. --search-replace="from,to").'
)
.option(
'in-place',
'Overwrite the local input file with the results of the search and replace operation.'
)
.option(
'output',
'Create a local copy of the file with the completed search and replace operations. Ignored if the command includes --in-place. Accepts a local file path. Defaults to STDOUT.'
'The local file path used to save a copy of the results from the search and replace operation. Ignored when used with the --in-place option.'
)
.examples( examples )
.argv( process.argv, async ( arg, opt ) => {
Expand Down
5 changes: 4 additions & 1 deletion src/bin/vip.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const runCmd = async function () {
.command( 'export', 'Export a copy of data associated with an environment.' )
.command( 'import', 'Import media or SQL database files to an environment.' )
.command( 'logs', 'Get logs from your VIP applications' )
.command( 'search-replace', 'Perform search and replace tasks on files' )
.command(
'search-replace',
'Search for a string in a local SQL file and replace it with a new string.'
)
.command( 'slowlogs', 'Retrieve MySQL slow query logs from an environment.' )
.command( 'db', "Access an environment's database." )
.command( 'sync', 'Sync the database from production to a non-production environment.' )
Expand Down