diff --git a/main.go b/main.go index d6d6221..3a6006a 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main import ( + "fmt" "github.com/rwinkhart/MUTN/src/cli" "github.com/rwinkhart/MUTN/src/offline" "os" + "strings" ) func main() { @@ -17,6 +19,17 @@ func main() { } else if argsCount == 1 { + // initial entry reader shortcut + // TODO Do not use file extensions for entries! This will allow doing this check more efficiently than otherwise possible. + if strings.HasPrefix(args[0], "/") { + if isFile, _ := offline.TargetIsFile(offline.EntryRoot+args[0], true); isFile { + fmt.Println("It's a file!") + } else { + fmt.Println("It's a directory!") + } + os.Exit(0) + } + switch args[0] { case "help", "--help", "-h": diff --git a/src/offline/targetChecks.go b/src/offline/targetChecks.go new file mode 100644 index 0000000..6671176 --- /dev/null +++ b/src/offline/targetChecks.go @@ -0,0 +1,25 @@ +package offline + +import ( + "fmt" + "os" +) + +// TargetIsFile TargetStatusCheck checks if the targetLocation is a file, directory, or is inaccessible +// returns: isFile, isAccessible +func TargetIsFile(targetLocation string, errorOnFail bool) (bool, bool) { + targetInfo, err := os.Stat(targetLocation) + if err != nil { + if errorOnFail { + fmt.Println(AnsiError + "Failed to access " + targetLocation + " - ensure it exists and has the correct permissions" + AnsiReset) + os.Exit(1) + } else { + return false, false + } + } + if targetInfo.IsDir() { + return false, true + } else { + return true, true + } +}