Replace options with args for directories input
This commit is contained in:
10
README.md
10
README.md
@@ -65,25 +65,25 @@ go build -o photorg
|
||||
### Основной синтаксис
|
||||
|
||||
```bash
|
||||
./photorg -source <исходная_директория> -dest <целевая_директория> [опции]
|
||||
./photorg <исходная_директория> <целевая_директория> [опции]
|
||||
```
|
||||
|
||||
### Параметры
|
||||
|
||||
- `-source` - исходная директория для сканирования (обязательный)
|
||||
- `-dest` - целевая директория для организации файлов (обязательный)
|
||||
- `исходная_директория` - исходная директория для сканирования (обязательный позиционный аргумент)
|
||||
- `целевая_директория` - целевая директория для организации файлов (обязательный позиционный аргумент)
|
||||
- `-dry-run` - режим предварительного просмотра без фактического перемещения файлов
|
||||
|
||||
### Примеры использования
|
||||
|
||||
#### Предварительный просмотр
|
||||
```bash
|
||||
./photorg -source /home/user/Pictures -dest /home/user/Organized -dry-run
|
||||
./photorg /home/user/Pictures /home/user/Organized -dry-run
|
||||
```
|
||||
|
||||
#### Организация фотографий
|
||||
```bash
|
||||
./photorg -source /home/user/Pictures -dest /home/user/Organized
|
||||
./photorg /home/user/Pictures /home/user/Organized
|
||||
```
|
||||
|
||||
## Структура результата
|
||||
|
15
main.go
15
main.go
@@ -31,17 +31,24 @@ type FileInfo struct {
|
||||
func main() {
|
||||
var config Config
|
||||
|
||||
flag.StringVar(&config.SourceDir, "source", "", "Source directory to scan for photos")
|
||||
flag.StringVar(&config.DestDir, "dest", "", "Destination directory to organize photos")
|
||||
flag.BoolVar(&config.DryRun, "dry-run", false, "Show what would be done without actually moving files")
|
||||
flag.Parse()
|
||||
|
||||
if config.SourceDir == "" || config.DestDir == "" {
|
||||
fmt.Println("Usage: photorg -source <source_dir> -dest <dest_dir> [-dry-run]")
|
||||
// Получаем позиционные аргументы
|
||||
args := flag.Args()
|
||||
if len(args) != 2 {
|
||||
fmt.Println("Usage: photorg <source_dir> <dest_dir> [-dry-run]")
|
||||
fmt.Println("\nArguments:")
|
||||
fmt.Println(" source_dir Source directory to scan for photos")
|
||||
fmt.Println(" dest_dir Destination directory to organize photos")
|
||||
fmt.Println("\nOptions:")
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
config.SourceDir = args[0]
|
||||
config.DestDir = args[1]
|
||||
|
||||
if err := validateDirectories(config.SourceDir, config.DestDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user