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

Using sed to change filepath #70

Closed
nathanmalishev opened this issue Jan 24, 2020 · 1 comment
Closed

Using sed to change filepath #70

nathanmalishev opened this issue Jan 24, 2020 · 1 comment

Comments

@nathanmalishev
Copy link

nathanmalishev commented Jan 24, 2020

Hey there,
This isn't an issue but i was hoping to get some advice.
I currently have a golang repository consisting of lots of lambda functions. Currently when i make a change to one lambda function, i have to rebuild them all.

build: clean
		@for dir in `ls handler`; do \
			echo 'building...' $$dir; \
			CGO_ENABLED=0 GOOS=linux go build -o dist/handler/$$dir gitlab.com/repo/code/handler/$$dir; \
		done
		echo "All built"

gomon:
	reflex -R '^node_modules/' -R '^output/' -r '\.go' -s -- sh -c 'make build'

File structure being

-/
   -handler/
       -apiHandler1/
       -apiHandler2/

I think I am extremely close, in rebuilding just one file when it's changed. But am having trouble getting sed to work. When i try my variations with sed, i often get
sed: 1: "s|[^/]+|g": unterminated substitute in regular expression

{} has the output of handler/approvedGet/approvedGet.go, but i need handler/approvedGet/ without the file name. For the command
CGO_ENABLED=0 GOOS=linux go build -o dist/handler/approvedGet/approvedGet.go gitlab.com/repo/code/handler/approvedGet/

A sed like sed "s|[^/]+|g" would work but i'm having trouble getting it to execute.

I'm hoping to get to the point where i have both {} and another variable in the command without the filename, so i can easily rebuild just the files & packages that have been changed.
Something like would be ideal

gomon:
	reflex -R '^node_modules/' -R '^output/' -r '\.go' -s -- 
        sh -c 'CGO_ENABLED=0 GOOS=linux go build -o dist/handler/{} gitlab.com/repo/code/{}_withoutfilename'

Thanks

@cespare
Copy link
Owner

cespare commented Jan 24, 2020

Hey @nathanmalishev, happy to help. I'm going to close the issue since it's not a problem with reflex.

CGO_ENABLED=0 GOOS=linux go build -o dist/handler/handler/approvedGet/approvedGet.go gitlab.com/code/olp_api/handler/approvedGet/

This command confuses me. Why do you want to build a binary that's named approvedGet.go?

For doing what you want, would it be possible to use the dirname command? This might be simpler than using sed for this. Here's a demo:

reflex -r '\.txt$' -- bash -c 'echo subs={} basename=$(basename {}) dirname=$(dirname {})'

If I run

mkdir x/y
touch x/y/z.txt

then reflex prints

[00] subs=x/y/z.txt basename=z.txt dirname=x/y

@cespare cespare closed this as completed Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants