@@ -10,13 +10,15 @@ import (
1010 "google.golang.org/grpc"
1111 "google.golang.org/grpc/credentials/insecure"
1212 "log"
13+ "strconv"
1314 "time"
1415)
1516
1617const (
1718 //serverIP = "localhost:50051" // local dev
1819 serverIP = "cli2cloud.com:50051" // production
1920 randomPasswordLength = 16
21+ defaultDelayLength = 3
2022)
2123
2224type stringFlag struct {
@@ -34,7 +36,7 @@ func (sf *stringFlag) String() string {
3436 return sf .value
3537}
3638
37- func sendPipedMessages (c proto.Cli2CloudClient , ctx context.Context , password * string ) error {
39+ func sendPipedMessages (c proto.Cli2CloudClient , ctx context.Context , password * string , delay time. Duration ) error {
3840 stream , err := c .Publish (ctx )
3941 if err != nil {
4042 return err
@@ -63,8 +65,8 @@ func sendPipedMessages(c proto.Cli2CloudClient, ctx context.Context, password *s
6365 }
6466
6567 fmt .Printf ("Share and monitor it live from https://cli2cloud.com/%s%s\n \n " , clientId .Id , keyURLSuffix )
66- // Wait 2 seconds for user to copy the client ID
67- time .Sleep (2 * time .Second )
68+ // Wait delay seconds for user to copy the client ID
69+ time .Sleep (delay * time .Second )
6870
6971 // Create a messages stream which is reading from both Stdout and Stdin
7072 streamMessages := make (chan string )
@@ -97,10 +99,14 @@ func sendPipedMessages(c proto.Cli2CloudClient, ctx context.Context, password *s
9799 return err
98100}
99101
100- func parseFlags () * string {
102+ func parseFlags () ( * string , time. Duration ) {
101103 var passwordFlag stringFlag
102104 flag .Var (& passwordFlag , "encrypt" , "Password to encrypt your data with." )
103105 generatePassword := flag .Bool ("encrypt-random" , false , "Generate a random password to encrypt your data." )
106+
107+ var delayFlag stringFlag
108+ flag .Var (& delayFlag , "delay" , "Delay before printing the command output to copy the client ID." )
109+
104110 flag .Parse ()
105111
106112 if passwordFlag .set && passwordFlag .value == "" {
@@ -124,11 +130,21 @@ func parseFlags() *string {
124130 fmt .Printf ("Your password: %s\n " , * password )
125131 }
126132
127- return password
133+ var delay int
134+ if delayFlag .set {
135+ delay , err = strconv .Atoi (delayFlag .value )
136+ if err != nil || delay < 0 {
137+ log .Fatal ("Delay parameter argument is non parseable " , err )
138+ }
139+ } else {
140+ delay = defaultDelayLength
141+ }
142+
143+ return password , time .Duration (delay )
128144}
129145
130146func main () {
131- password := parseFlags ()
147+ password , delay := parseFlags ()
132148
133149 conn , err := grpc .Dial (serverIP , grpc .WithTransportCredentials (insecure .NewCredentials ()))
134150 if err != nil {
@@ -139,7 +155,7 @@ func main() {
139155 ctx , cancel := context .WithCancel (context .Background ())
140156 defer cancel ()
141157
142- if err := sendPipedMessages (client , ctx , password ); err != nil {
158+ if err := sendPipedMessages (client , ctx , password , delay ); err != nil {
143159 log .Fatal ("Error while sending to server." , err )
144160 }
145161
0 commit comments