-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add Rename Option to Copy Command #126
Conversation
"skipFiles": ["<node_internals>/**"], | ||
"type": "pwa-node" | ||
"type": "node" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pwa-node
is no longer necessary as node
debugger is no longer in preview. See this post for details.
"configurations": [ | ||
{ | ||
"name": "Run Tests", | ||
"request": "launch", | ||
"runtimeArgs": ["run", "test"], | ||
"runtimeExecutable": "npm", | ||
"cwd": "${workspaceFolder}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to add cwd
in order to run the debugger with tests (was not referencing correct tests). Let me know if this wasn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... I think this is okay for a new feature (with a few comments on the implementation), but it also needs docs, and a bit of clarity on how the matching works - is it only filenames?
So if we have a/test.txt and b/test.txt, and rename:test.txt renamed.txt, that means both a/test.txt and b/test.txt will become renamed.txt?
Would rename:"a/test.txt" actually work? There could be a test for that.
Thanks for the PR!
src/bluehawk/actions/copy.test.ts
Outdated
output: outputPath, | ||
rootPath, | ||
waitForListeners: true, | ||
rename: '{"test.bin":"renamed.bin"}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected the JSON to be parsed into an object before passing to the actual action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point made this change
src/bluehawk/actions/copy.ts
Outdated
|
||
// function to check if object has a new name specified | ||
const getRename = (fileName: string) => { | ||
if (rename && renameObj && (renameObj as any)[fileName] !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch out for casting to any
. This could be avoided if the parsing of the input were done in the interface layer (CLI) rather than action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated type of rename to a Record<String, String>
to avoid any
type cast. Good catch!
…file # Conflicts: # src/bluehawk/index.ts
docs/docs/cli.md
Outdated
@@ -38,6 +38,10 @@ ignore patterns that omit matched files from output. | |||
By default, this command generates output files that omit all `state`. | |||
However, you can use the `--state` flag to generate output files that | |||
include content from a single state that you specify. | |||
If you would like to rename files as you copy them, use | |||
the `--rename` flag. The `--rename` flag takes a JSON | |||
string as an argument. Keys are filenames that are to be renamed, and values are the new names of those files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string as an argument. Keys are filenames that are to be renamed, and values are the new names of those files. | |
string as an argument. The JSON must represent an object whose keys are filenames that are to be renamed and values are the new names of those files. |
Wondering if we should be explicit about the fact that specific paths would probably be ignored? i.e. this only works on filenames?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated docs with suggestion and added sentence explicitly stating that path keys/values are not supported at this time.
src/cli/commandModules/copy.ts
Outdated
@@ -9,6 +9,7 @@ import { | |||
CopyArgs, | |||
copy, | |||
} from "../.."; | |||
import { DOCS } from "../../bluehawk/const"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we do this anywhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed project + docs links as per slack discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Alek, thanks!
Description
Adds a
--rename
option to thecopy
command.Use Case
Hey team, I ran into a use case where I'd like to be able to rename a file as I copy it.
My application has two files:
make_collection.py
insert.py
Both
make_collection.py
andinsert.py
have about five states with roughly the same structure. I'd like to add a new state that has the same structure formake_collection.py
but a new structure forinsert.py
. I'd like to put my new code in a file namedinsert_<new_state>.py
, as it is hard to place the logic I need ininsert.py
throughstate
tags.I'd like to be able to rename the file as I copy it so my test runner can find it and so that I can source it into docs without changing paths.
Behavior
The
--rename
option takes a JSON string as an argument. Keys are filenames that are to be renamed, and values are the new names of those files. For example, the following options rename any file nametest.txt
totest_new.txt
Let me know your thoughts on this option!