@@ -406,47 +406,44 @@ module Program =
406
406
}
407
407
408
408
let move ( config : Config.MoveConfig ) ( library : Library.Library ) =
409
- let moveSingleFile source target =
409
+ let moveSingleFile source target : Result < Audiobook.AudiobookSource , string > =
410
410
result {
411
411
let targetFilename =
412
412
if target |> IO.File.hasExtension then target
413
413
else IO.Path.combine ( target, ( source |> IO.File.fileName))
414
414
let targetFolderName = targetFilename |> IO.Directory.directoryName
415
415
do ! IO.Directory.create targetFolderName
416
416
do ! IO.File.move source targetFilename
417
+ return Audiobook.AudiobookSource.SingleFile targetFilename
417
418
}
418
419
419
420
/// Moves all source files to the target.
420
421
/// Checks whether the target is an existing file. If it is the process is aborted.
421
422
/// Makes sure that the target directory exists.
422
- let moveMultipleFiles ( sources : string list ) target =
423
+ let moveMultipleFiles ( sources : string list ) target : Result < Audiobook.AudiobookSource , string > =
423
424
result {
424
425
if target |> IO.File.exists then
425
426
return ! Error " Cannot move an audio book consisting of multiple files to a file location."
426
427
else
427
428
do printfn " test"
428
429
let basePath = IO.findLargestCommonPath sources
429
- return ! sources |> List.traverseResultM ( fun s ->
430
- result {
431
- // remove the SeparatorChar because it confuses `Path.combine` because it thinks
432
- // relative path is an absolute path otherwise
430
+ let! singles = sources |> List.traverseResultM ( fun s ->
433
431
let relativePath = s.Substring( basePath.Length). TrimStart( IO.Path.DirectorySeparatorChar)
434
432
let targetFilename = IO.Path.combine ( target, relativePath)
435
- return ! moveSingleFile s targetFilename
436
- }) |> Result.map ( fun _ -> ())
433
+ moveSingleFile s targetFilename)
434
+ return Audiobook.mergeSource singles |> Audiobook.AudiobookSource.MultiFile
437
435
}
438
436
439
- let move ( source : Audiobook.AudiobookSource ) target =
440
- result {
441
- return ! match source with
442
- | Audiobook.AudiobookSource.SingleFile file -> moveSingleFile file target
443
- | Audiobook.AudiobookSource.MultiFile files -> moveMultipleFiles files target
444
- }
437
+ let move ( source : Audiobook.AudiobookSource ) target : Result < Audiobook.AudiobookSource , string > =
438
+ match source with
439
+ | Audiobook.AudiobookSource.SingleFile file -> moveSingleFile file target
440
+ | Audiobook.AudiobookSource.MultiFile files -> moveMultipleFiles files target
445
441
446
442
result {
447
443
let! book = library |> Library.findById config.Id
448
- do ! move book.Source config.Target
449
- return ()
444
+ let! updatedSource = move book.Source config.Target
445
+ let updatedBook = { book with Source = updatedSource }
446
+ return ! library |> Library.updateBook updatedBook
450
447
}
451
448
452
449
let identify ( config : Config.IdConfig ) ( library : Library.Library ) =
@@ -499,8 +496,22 @@ module Program =
499
496
return ! f library
500
497
}
501
498
499
+ let addConfigEntriesToToCliArguments ( argv : string []) =
500
+ match GlobalConfig.tryLoad () with
501
+ | Some config ->
502
+ let containsLibraryArgument =
503
+ argv
504
+ |> Array.filter ( fun a -> a = " -l" || a = " --library-file" || a = " --library" )
505
+ |> Array.length > 0
506
+ if containsLibraryArgument then argv
507
+ else Array.append [| " -l" ; config.LibraryFile |] argv
508
+ | None ->
509
+ argv
510
+
511
+
502
512
[<EntryPoint>]
503
513
let main argv =
514
+ let argv = addConfigEntriesToToCliArguments argv
504
515
505
516
let r = result {
506
517
let parser , results = parseCommandLineArguments argv
@@ -542,7 +553,7 @@ module Program =
542
553
| Config.Details detailsConfig ->
543
554
return ! ( runOnExisting ( listDetails detailsConfig))
544
555
| Config.Move moveConfig ->
545
- return ! ( runOnExisting ( move moveConfig))
556
+ return ! ( runOnExistingAndSave ( move moveConfig))
546
557
| Config.Id idConfig ->
547
558
return ! ( runOnExisting (( identify idConfig) >> Ok))
548
559
| Config.Version ->
0 commit comments