Skip to content

Commit

Permalink
client: --remotes flag for reading the list of remotes from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
tgulacsi committed Apr 5, 2020
1 parent 007d648 commit 59d2071
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"bufio"
"bytes"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -269,6 +271,8 @@ var clientHelp = `
--hostname, Optionally set the 'Host' header (defaults to the host
found in the server url).
--remotes, a file to read remotes from (one per line).
` + commonHelp

func client(args []string, envPrefix string) {
Expand All @@ -284,6 +288,7 @@ func client(args []string, envPrefix string) {
pid := flags.Bool("pid", false, "")
hostname := flags.String("hostname", "", "")
verbose := flags.Bool("v", false, "")
flagRemotes := flags.String("remotes", "", "")
flags.Usage = func() {
fmt.Print(clientHelp)
os.Exit(1)
Expand All @@ -292,12 +297,42 @@ func client(args []string, envPrefix string) {
flags.Parse(args)
//pull out options, put back remaining args
args = flags.Args()
if len(args) < 2 {
log.Fatalf("A server and least one remote is required")
switch len(args) {
case 0:
log.Fatalf("A server is required")
case 1:
if *flagRemotes == "" {
log.Fatalf("A server and least one remote is required")
}
}
if *auth == "" {
*auth = os.Getenv("AUTH")
}
remotes := args[1:]
var remotesFn string
if *flagRemotes != "" {
remotesFn = *flagRemotes
} else if len(remotes) == 1 && (remotes[0] == "-" || remotes[0] == "") {
remotes = remotes[:0]
remotesFn = "-"
}
if remotesFn != "" {
fh := os.Stdin
if remotesFn != "-" {
var err error
if fh, err = os.Open(remotesFn); err != nil {
log.Fatal(err)
}
}
scanner := bufio.NewScanner(fh)
for scanner.Scan() {
line := bytes.TrimSpace(scanner.Bytes())
if len(line) != 0 {
remotes = append(remotes, string(line))
}
}
fh.Close()
}
c, err := chclient.NewClient(&chclient.Config{
Fingerprint: *fingerprint,
Auth: *auth,
Expand All @@ -306,7 +341,7 @@ func client(args []string, envPrefix string) {
MaxRetryInterval: *maxRetryInterval,
HTTPProxy: *proxy,
Server: args[0],
Remotes: args[1:],
Remotes: remotes,
HostHeader: *hostname,
})
if err != nil {
Expand Down

0 comments on commit 59d2071

Please sign in to comment.