26 lines
523 B
Go
26 lines
523 B
Go
|
|
package cmd
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AutoDetectInfo automatically determines whether the path is a file or directory
|
||
|
|
func AutoDetectInfo(target string) error {
|
||
|
|
absPath, err := filepath.Abs(target)
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("error resolving path: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
fileInfo, err := os.Stat(absPath)
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("error accessing %s: %w", absPath, err)
|
||
|
|
}
|
||
|
|
|
||
|
|
if fileInfo.IsDir() {
|
||
|
|
return DirInfoCommand([]string{absPath})
|
||
|
|
}
|
||
|
|
return FileInfoCommand([]string{absPath})
|
||
|
|
}
|