feat(cmd): make current directory the default output directory in command line tools

This commit is contained in:
vsariola
2021-04-10 16:10:27 +03:00
parent f713133a0a
commit 9a6d92eefd
2 changed files with 18 additions and 2 deletions

View File

@ -56,10 +56,18 @@ func main() {
fmt.Print(contents)
return nil
}
dir, name := filepath.Split(filename)
_, name := filepath.Split(filename)
var dir string
if *directory != "" {
dir = *directory
}
if dir == "" {
var err error
dir, err = os.Getwd()
if err != nil {
return fmt.Errorf("could not get working directory, specify the output directory explicitly: %v", err)
}
}
name = strings.TrimSuffix(name, filepath.Ext(name)) + extension
f := filepath.Join(dir, name)
if dir != "" {