-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: use dot to specify current dir with --outdir flag
Signed-off-by: luigidematteis <[email protected]>
- Loading branch information
1 parent
e8fb961
commit eb0783d
Showing
7 changed files
with
60 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// ResolveOutputDirectory determines the output directory based on user input. | ||
// It defaults to the user's home directory if `outDir` is empty. | ||
func ResolveOutputDirectory(outDir string) (string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", fmt.Errorf("Error while getting user home directory: %w", err) | ||
} | ||
|
||
logrus.Debug("Resolved home directory: ", homeDir) | ||
|
||
if outDir == "" { | ||
outDir = homeDir | ||
logrus.Debug("Empty outdir flag. Set outdir to: ", homeDir) | ||
} | ||
|
||
currentDir, err := os.Getwd() | ||
if err != nil { | ||
return "", fmt.Errorf("Error while getting current working directory: %w", err) | ||
} | ||
|
||
logrus.Debug("Resolved current directory: ", currentDir) | ||
|
||
if outDir == "." { | ||
outDir = currentDir | ||
logrus.Debug("Set output dir to current directory: ", currentDir) | ||
} | ||
|
||
return outDir, nil | ||
} |