-
Notifications
You must be signed in to change notification settings - Fork 11
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
stdbin: adding mkdir #240
stdbin: adding mkdir #240
Conversation
Signed-off-by: i4k <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
==========================================
- Coverage 57.05% 56.95% -0.11%
==========================================
Files 26 27 +1
Lines 4403 4416 +13
==========================================
+ Hits 2512 2515 +3
- Misses 1651 1660 +9
- Partials 240 241 +1
Continue to review full report at Codecov.
|
@@ -7,8 +7,9 @@ buildargs = -ldflags "-X main.VersionString=$(version)" -v | |||
all: build test install | |||
|
|||
build: | |||
go build $(buildargs) -o ./cmd/nash/nash ./cmd/nash | |||
go build $(buildargs) -o ./cmd/nashfmt/nashfmt ./cmd/nashfmt | |||
cd cmd/nash && go build $(buildargs) |
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.
this change was needed because on windows the generated binaries must have .exe extensions.
Signed-off-by: i4k <[email protected]>
stdbin/mkdir/main.go
Outdated
} | ||
err := mkdirs(os.Args[1:]) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %s\n", err.Error()) |
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.
No need to call err.Error
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.
LGTM, just small crap because I'm annoying as hell =D
|
||
func mkdirs(dirnames []string) error { | ||
for _, d := range dirnames { | ||
if err := os.MkdirAll(d, 0644); err != nil { |
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.
cant you pass os.ModeDir here instead of 0644 ?
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.
always creating all dirs seems nice, I always do it =).
another thing very common is to ignore if the dir already exists, in the end I always use "-p" for this. What you think about it being the default ?
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.
yes, makes sense. That's what I commonly do also.
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.
cant you pass os.ModeDir here instead of 0644
0644 are the permission bits here, not the file mode. Sorry, did I misunderstand you?
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.
From the name I thought the os.ModeDir would be an integer with the permission bits (indicating the default permissions for directories). My mistake =)
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.
👍
stdbin/mkdir/mkdir_test.go
Outdated
if s, err := os.Stat(testdir); err != nil { | ||
t.Fatal(err) | ||
} else if s.Mode()&os.ModeDir != os.ModeDir { | ||
t.Errorf("Invalid directory mode: %v", s.Mode()) |
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.
Why Errorf instead of Fatalf since all other checks results on Fatal ?
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'm idiot =)
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.
auheauheauheuaheauheauhe yeah like no one else does this kind of thing =P
stdbin/mkdir/mkdir_test.go
Outdated
defer os.RemoveAll(tmpDir) | ||
for _, p := range testDirs { | ||
testdir := filepath.FromSlash(path.Join(tmpDir, p)) | ||
err = mkdirs([]string{testdir}) |
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.
Isn't a good idea to test with arrays bigger than one too ? Also, what happens if the array is empty ? (can test it on the function or on the final cmd)
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.
yes, there are missing test cases. I made this in a rush... =/
thanks
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.
Thanks for working on this =). We can add an TODO too ;-)
@@ -23,6 +24,7 @@ install: build | |||
cp -p ./cmd/nashfmt/nashfmt $(NASHROOT)/bin | |||
rm -rf $(NASHROOT)/stdlib | |||
cp -pr ./stdlib $(NASHROOT)/stdlib | |||
cp -pr ./stdbin/mkdir/mkdir $(NASHROOT)/bin/mkdir |
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.
this install still only works on unix, I wll address this in the windows branch soon.
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.
thanks, I dont even have an env to test this kind of stuff =P (nor the patience)
Signed-off-by: i4k <[email protected]>
Signed-off-by: i4k <[email protected]>
@katcipis Did you take a look at changes made? |
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.
LGTM
This PR starts a long road to address #230.
As I'm using a lot of windows nowadays... I'll start scratching my itches, by adding the programs I'm missing in windows. The work for the stdbin build system and integrated tests could come up in another PR.
Another PR could be created to copy our programs from c0defellas/enzo to here also.
p.s.: the name of the branch is
add-stdbin-pwd
becausepwd
was my initial target for this development, but soon realized I was unable to create the stdbin directory in windows without right-click in explorer ... Then mkdir priority escalated very fast =P