Skip to content
Snippets Groups Projects
Commit 628d09b9 authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'hotfix/roundPrintFix' into 'release'

Fix print statements and clean up code

See merge request !521
parents d84350a2 2df46096
No related branches found
No related tags found
No related merge requests found
......@@ -147,45 +147,11 @@ var rootCmd = &cobra.Command{
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
jww.INFO.Printf("Result of sending message \"%s\" to \"%v\":",
msg.Payload, msg.Recipient)
// Construct the callback function which prints out the rounds' results
f := func(allRoundsSucceeded, timedOut bool,
rounds map[id.Round]api.RoundResult) {
// Done as string slices for easy and human readable printing
successfulRounds := make([]string, 0)
failedRounds := make([]string, 0)
timedOutRounds := make([]string, 0)
for _, r := range roundIDs {
// Group all round reports into a category based on their
// result (successful, failed, or timed out)
if result, exists := rounds[r]; exists {
if result == api.Succeeded {
successfulRounds = append(successfulRounds, strconv.Itoa(int(r)))
} else if result == api.Failed {
failedRounds = append(failedRounds, strconv.Itoa(int(r)))
} else {
timedOutRounds = append(timedOutRounds, strconv.Itoa(int(r)))
}
}
}
// Print out all rounds ressults, if they are populated
if len(successfulRounds) > 0 {
jww.INFO.Printf("Round(s) %v successful", strings.Join(successfulRounds, ","))
}
if len(failedRounds) > 0 {
jww.ERROR.Printf("Round(s) %v failed", strings.Join(failedRounds, ","))
}
if len(timedOutRounds) > 0 {
jww.ERROR.Printf("Round(s) %v timed out (no network "+
"resolution could be found)", strings.Join(timedOutRounds, ","))
}
printRoundResults(allRoundsSucceeded, timedOut, rounds, roundIDs, msg)
}
// Have the client report back the round results
......@@ -231,6 +197,46 @@ var rootCmd = &cobra.Command{
},
}
// Helper function which prints the round resuls
func printRoundResults(allRoundsSucceeded, timedOut bool,
rounds map[id.Round]api.RoundResult, roundIDs []id.Round, msg message.Send) {
// Done as string slices for easy and human readable printing
successfulRounds := make([]string, 0)
failedRounds := make([]string, 0)
timedOutRounds := make([]string, 0)
for _, r := range roundIDs {
// Group all round reports into a category based on their
// result (successful, failed, or timed out)
if result, exists := rounds[r]; exists {
if result == api.Succeeded {
successfulRounds = append(successfulRounds, strconv.Itoa(int(r)))
} else if result == api.Failed {
failedRounds = append(failedRounds, strconv.Itoa(int(r)))
} else {
timedOutRounds = append(timedOutRounds, strconv.Itoa(int(r)))
}
}
}
jww.INFO.Printf("Result of sending message \"%s\" to \"%v\":",
msg.Payload, msg.Recipient)
// Print out all rounds results, if they are populated
if len(successfulRounds) > 0 {
jww.INFO.Printf("\tRound(s) %v successful", strings.Join(successfulRounds, ","))
}
if len(failedRounds) > 0 {
jww.ERROR.Printf("\tRound(s) %v failed", strings.Join(failedRounds, ","))
}
if len(timedOutRounds) > 0 {
jww.ERROR.Printf("\tRound(s) %v timed " +
"\n\tout (no network resolution could be found)", strings.Join(timedOutRounds, ","))
}
}
func createClient() *api.Client {
initLog(viper.GetBool("verbose"), viper.GetString("log"))
jww.INFO.Printf(Version())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment