@@ -151,6 +151,11 @@ func (cmd *InitCommand) Run() error {
151151 }
152152 }
153153
154+ deviceName , err := promptForDeviceName (cmd .io )
155+ if err != nil {
156+ return err
157+ }
158+
154159 fmt .Fprint (cmd .io .Output (), "Setting up your account..." )
155160 cmd .progressPrinter .Start ()
156161
@@ -161,7 +166,7 @@ func (cmd *InitCommand) Run() error {
161166 }
162167
163168 credential := credentials .CreateKey ()
164- _ , err = client .Credentials ().Create (credential , "" )
169+ _ , err = client .Credentials ().Create (credential , deviceName )
165170 if err != nil {
166171 cmd .progressPrinter .Stop ()
167172 return err
@@ -235,19 +240,9 @@ func (cmd *InitCommand) Run() error {
235240 return nil
236241 }
237242
238- deviceName := ""
239- question := "What is the name of this device?"
240- hostName , err := os .Hostname ()
241- if err == nil {
242- deviceName , err = ui .AskWithDefault (cmd .io , question , hostName )
243- if err != nil {
244- return err
245- }
246- } else {
247- deviceName , err = ui .Ask (cmd .io , question )
248- if err != nil {
249- return err
250- }
243+ deviceName , err := promptForDeviceName (cmd .io )
244+ if err != nil {
245+ return err
251246 }
252247
253248 // Only prompt for a passphrase when the user hasn't used --force.
@@ -286,3 +281,21 @@ func (cmd *InitCommand) Run() error {
286281 return errors .New ("invalid option" )
287282 }
288283}
284+
285+ func promptForDeviceName (io ui.IO ) (string , error ) {
286+ deviceName := ""
287+ question := "What is the name of this device?"
288+ hostName , err := os .Hostname ()
289+ if err == nil {
290+ deviceName , err = ui .AskWithDefault (io , question , hostName )
291+ if err != nil {
292+ return "" , err
293+ }
294+ } else {
295+ deviceName , err = ui .Ask (io , question )
296+ if err != nil {
297+ return "" , err
298+ }
299+ }
300+ return deviceName , nil
301+ }
0 commit comments