Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,25 @@ func (c *cli) CmdList(args ...string) error {
sort.Sort(ByDate(list.Mirrors))

w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprint(w, "Identifier ")
w.Init(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprint(w, "IDENTIFIER")
if *score == true {
fmt.Fprint(w, "\tSCORE")
}
if *http == true {
fmt.Fprint(w, "\tHTTP ")
fmt.Fprint(w, "\tHTTP")
}
if *rsync == true {
fmt.Fprint(w, "\tRSYNC ")
fmt.Fprint(w, "\tRSYNC")
}
if *ftp == true {
fmt.Fprint(w, "\tFTP ")
fmt.Fprint(w, "\tFTP")
}
if *location == true {
fmt.Fprint(w, "\tLOCATION ")
fmt.Fprint(w, "\tLOCATION")
}
if *state == true {
fmt.Fprint(w, "\tSTATE\tSINCE")
fmt.Fprint(w, "\tSTATE\tSINCE\tREASON")
}
fmt.Fprint(w, "\n")

Expand All @@ -210,34 +210,36 @@ func (c *cli) CmdList(args ...string) error {
if err != nil {
log.Fatal("list error:", err)
}
fmt.Fprintf(w, "%s ", mirror.Name)
fmt.Fprintf(w, "%s", mirror.Name)
if *score == true {
fmt.Fprintf(w, "\t%d ", mirror.Score)
fmt.Fprintf(w, "\t%d", mirror.Score)
}
if *http == true {
fmt.Fprintf(w, "\t%s ", mirror.HttpURL)
fmt.Fprintf(w, "\t%s", mirror.HttpURL)
}
if *rsync == true {
fmt.Fprintf(w, "\t%s ", mirror.RsyncURL)
fmt.Fprintf(w, "\t%s", mirror.RsyncURL)
}
if *ftp == true {
fmt.Fprintf(w, "\t%s ", mirror.FtpURL)
fmt.Fprintf(w, "\t%s", mirror.FtpURL)
}
if *location == true {
countries := strings.Split(mirror.CountryCodes, " ")
countryCode := "/"
if len(countries) >= 1 {
countryCode = countries[0]
}
fmt.Fprintf(w, "\t%s (%s) ", countryCode, mirror.ContinentCode)
fmt.Fprintf(w, "\t%s (%s)", countryCode, mirror.ContinentCode)
}
if *state == true {
if mirror.Enabled == false {
fmt.Fprintf(w, "\tdisabled")
} else {
fmt.Fprintf(w, "\t%s", StatusString(mirror))
status := "disabled"
reason := ""
if mirror.Enabled == true {
status = StatusString(mirror)
reason = ReasonString(mirror)
}
fmt.Fprintf(w, " \t(%s)", stateSince.Format(time.RFC1123))
since := stateSince.Format(time.RFC1123)
fmt.Fprintf(w, "\t%s\t(%s)\t%s", status, since, reason)
}
fmt.Fprint(w, "\n")
}
Expand Down Expand Up @@ -296,6 +298,31 @@ func StatusString(m *rpc.Mirror) string {
return fmt.Sprintf("%s/%s", http, https)
}

func ReasonString(m *rpc.Mirror) string {
var http string
var https string

http = m.HttpDownReason
https = m.HttpsDownReason

if http == https {
return http
}
if IsHTTPOnly(m) {
return http
}
if IsHTTPSOnly(m) {
return https
}
if http == "" {
return https
}
if https == "" {
return http
}
return fmt.Sprintf("%s / %s", http, https)
}

func (c *cli) CmdAdd(args ...string) error {
cmd := SubCmd("add", "[OPTIONS] IDENTIFIER", "Add a new mirror")
http := cmd.String("http", "", "HTTP base URL")
Expand Down Expand Up @@ -900,7 +927,7 @@ func (c *cli) CmdExport(args ...string) error {
}

w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)

for _, m := range list.Mirrors {
if *disabled == false {
Expand Down Expand Up @@ -1035,7 +1062,7 @@ func (c *cli) CmdStats(args ...string) error {

// Format the results
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)

// Sort keys and count requests
var keys []string
Expand All @@ -1055,7 +1082,7 @@ func (c *cli) CmdStats(args ...string) error {
fmt.Fprintf(w, "\t\n")
}

fmt.Fprintf(w, "Total download requests: \t%d\n", requests)
fmt.Fprintf(w, "Total download requests:\t%d\n", requests)
w.Flush()
} else if cmd.Arg(0) == "mirror" {
// Mirror stats
Expand All @@ -1073,7 +1100,7 @@ func (c *cli) CmdStats(args ...string) error {

// Format the results
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)

fmt.Fprintf(w, "Identifier:\t%s\n", name)
if !reply.Mirror.Enabled {
Expand Down
Loading