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 2 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
2 changes: 1 addition & 1 deletion src/bin/vip-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ 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.'
'Perform a search and replace operation on the local input file, and save the results to the file prior to import.'
yolih marked this conversation as resolved.
Show resolved Hide resolved
)
.option(
'output',
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 and save the results to the local input file "file.sql".',
yolih marked this conversation as resolved.
Show resolved Hide resolved
},
// `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',
'Pass a string value to search for and a string value to replace it with. Separate the values by a comma only; no spaces (e.g. --search-replace="from,to").'
yolih marked this conversation as resolved.
Show resolved Hide resolved
)
.option(
'in-place',
'Save the results of a search and replace operation to the local input file.'
yolih marked this conversation as resolved.
Show resolved Hide resolved
)
.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.'
'Save the results of the search and replace operation to a clone of the local input file. Ignored if the command includes --in-place. Accepts a local file path.'
)
.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