MCPcopy Create free account
hub / github.com/Code-Hex/pget / parseURLs

Method parseURLs

pget.go:171–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169}
170
171func (pget *Pget) parseURLs() error {
172
173 // find url in args
174 for _, argv := range pget.args {
175 if govalidator.IsURL(argv) {
176 pget.URLs = append(pget.URLs, argv)
177 }
178 }
179
180 if len(pget.URLs) < 1 {
181 fmt.Fprintf(stdout, "Please input url separate with space or newline\n")
182 fmt.Fprintf(stdout, "Start download with ^D\n")
183
184 // scanning url from stdin
185 scanner := bufio.NewScanner(os.Stdin)
186 for scanner.Scan() {
187 scan := scanner.Text()
188 urls := strings.Split(scan, " ")
189 for _, url := range urls {
190 if govalidator.IsURL(url) {
191 pget.URLs = append(pget.URLs, url)
192 }
193 }
194 }
195
196 if err := scanner.Err(); err != nil {
197 return errors.Wrap(err, "failed to parse url from stdin")
198 }
199
200 if len(pget.URLs) < 1 {
201 return errors.New("urls not found in the arguments passed")
202 }
203 }
204
205 return nil
206}

Callers 1

ReadyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected