Added --help parameter + README

This commit is contained in:
Óscar M. Lage 2024-10-25 09:36:05 +02:00
parent d4836c1d95
commit b8859acc28
2 changed files with 68 additions and 0 deletions

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# Medialog
```
Usage: go run main.go [--media ediatype] [--update]
Description:
This command allows you to manage multimedia files and update their data in the system.
Options:
--media <mediatype> Specifies the type of media to process.
Possible values are:
- movies: Processes movie files.
- series: Processes series files.
- books: Processes book files.
- games: Processes game files.
- music: Processes music files.
If not specified, all media types will be processed.
--update Runs in update mode to refresh existing media entries.
This option is optional and requires no value.
-h, --help Displays this help message and exits.
Usage examples:
go run main.go --media movies Processes only movie files.
go run main.go --update Updates all multimedia files.
go run main.go --media series --update Processes and updates series files.
```

40
main.go
View File

@ -9,6 +9,7 @@ import (
"hugo-medialog/internal/music" "hugo-medialog/internal/music"
"hugo-medialog/internal/series" "hugo-medialog/internal/series"
"hugo-medialog/utils" "hugo-medialog/utils"
"os"
) )
func main() { func main() {
@ -18,8 +19,18 @@ func main() {
// --media parameter // --media parameter
media := flag.String("media", "", "Specify the media type to process: movies, series, books, games, or music") media := flag.String("media", "", "Specify the media type to process: movies, series, books, games, or music")
update := flag.Bool("update", false, "Run in update mode to update existing entries") update := flag.Bool("update", false, "Run in update mode to update existing entries")
// Define custom help option
help := flag.Bool("help", false, "Display this help message")
flag.BoolVar(help, "h", false, "Display this help message") // support -h as well
flag.Parse() flag.Parse()
// Show help message if -h or --help is specified
if *help {
printHelp()
os.Exit(0)
}
if *media == "" { if *media == "" {
processAll(*update) processAll(*update)
} else { } else {
@ -36,6 +47,8 @@ func main() {
processMusic(*update) processMusic(*update)
default: default:
fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media) fmt.Printf("Invalid media type: %s. Please use movies, series, books, games, or music.\n", *media)
printHelp()
os.Exit(1)
} }
} }
} }
@ -107,3 +120,30 @@ func processMusic(update bool) {
fmt.Printf("Error processing music: %v\n", err) fmt.Printf("Error processing music: %v\n", err)
} }
} }
func printHelp() {
fmt.Println(`Usage: go run main.go [--media mediatype] [--update]
Description:
This command allows you to manage multimedia files and update their data in the system.
Options:
--media <mediatype> Specifies the type of media to process.
Possible values are:
- movies: Processes movie files.
- series: Processes series files.
- books: Processes book files.
- games: Processes game files.
- music: Processes music files.
If not specified, all media types will be processed.
--update Runs in update mode to refresh existing media entries.
This option is optional and requires no value.
-h, --help Displays this help message and exits.
Usage examples:
go run main.go --media movies Processes only movie files.
go run main.go --update Updates all multimedia files.
go run main.go --media series --update Processes and updates series files.`)
}