Skip to content

Commit eb69f50

Browse files
committed
Add support for Go flags and refactor variables in youtube_test
1 parent 38f7c3e commit eb69f50

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For various reasons, you may prefer not to use your Google account but you would
99
1. Download the executable from the release section or build it yourself
1010
1. Open a Terminal (cmd.exe on Windows)
1111
1. Navigate to the location of the *dplaylist(.exe)* executable
12-
1. Execute it by passing your text file as an argument: `./dplaylist hip-hop.txt`
12+
1. Execute it by passing your text file as an argument: `./dplaylist -file=hip-hop.txt`
1313
1. The link is generated in the console
1414

1515
### Valid ID

main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ package main
22

33
import (
44
"bufio"
5+
"flag"
56
"log"
67
"os"
78

89
"github.com/dlmw/dplaylist/youtube"
910
)
1011

12+
var filePath string
13+
14+
func init() {
15+
const (
16+
filePathShort = "f"
17+
filePathLong = "file"
18+
filePathDefault = "youtube.txt"
19+
filePathUsage = "The path of the file containing YouTube IDs. " + filePathShort + " and " + filePathLong + " are equivalent."
20+
)
21+
22+
flag.StringVar(&filePath, filePathLong, filePathDefault, filePathUsage)
23+
flag.StringVar(&filePath, filePathShort, filePathDefault, filePathUsage)
24+
}
25+
1126
func main() {
12-
filePath := os.Args[1]
27+
flag.Parse()
1328
lines, err := readLines(filePath)
1429
if err != nil {
1530
panic(err)

youtube/youtube_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"testing"
77
)
88

9-
var videoIDs []string = []string{"dQw4w9WgXcQ", "TYgOlqinH7A", "mOYZaiDZ7BM"}
9+
var videoIDs = []string{"dQw4w9WgXcQ", "TYgOlqinH7A", "mOYZaiDZ7BM"}
1010

11-
var youtubeLongLinkExample string = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
12-
var youtubeShortLinkExample string = "https://youtu.be/dQw4w9WgXcQ"
11+
var youtubeLongLinkExample = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
12+
var youtubeShortLinkExample = "https://youtu.be/dQw4w9WgXcQ"
1313

1414
func ExampleCreatePlaylist() {
1515
fmt.Println(CreatePlaylist(videoIDs))

0 commit comments

Comments
 (0)