mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(cmd): make current directory the default output directory in command line tools
This commit is contained in:
parent
f713133a0a
commit
9a6d92eefd
@ -68,7 +68,8 @@ func main() {
|
|||||||
fmt.Print(string(contents))
|
fmt.Print(string(contents))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dir, name := filepath.Split(filename)
|
_, name := filepath.Split(filename)
|
||||||
|
var dir string
|
||||||
if *outPath != "" {
|
if *outPath != "" {
|
||||||
// check if it's an already existing directory and the user just forgot trailing slash
|
// check if it's an already existing directory and the user just forgot trailing slash
|
||||||
if info, err := os.Stat(*outPath); err == nil && info.IsDir() {
|
if info, err := os.Stat(*outPath); err == nil && info.IsDir() {
|
||||||
@ -83,6 +84,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
name = strings.TrimSuffix(name, filepath.Ext(name)) + extension
|
||||||
f := filepath.Join(dir, name)
|
f := filepath.Join(dir, name)
|
||||||
original, err := ioutil.ReadFile(f)
|
original, err := ioutil.ReadFile(f)
|
||||||
|
@ -56,10 +56,18 @@ func main() {
|
|||||||
fmt.Print(contents)
|
fmt.Print(contents)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dir, name := filepath.Split(filename)
|
_, name := filepath.Split(filename)
|
||||||
|
var dir string
|
||||||
if *directory != "" {
|
if *directory != "" {
|
||||||
dir = *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
|
name = strings.TrimSuffix(name, filepath.Ext(name)) + extension
|
||||||
f := filepath.Join(dir, name)
|
f := filepath.Join(dir, name)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user