Create creates the configuration by requesting from stdin
(configPath string)
| 28 | |
| 29 | // Create creates the configuration by requesting from stdin |
| 30 | func Create(configPath string) (*Config, error) { |
| 31 | var config Config |
| 32 | fmt.Println("1. Please go to https://console.developers.google.com/") |
| 33 | fmt.Println("2. Create a new project") |
| 34 | fmt.Println("3. Go to library and activate the Google Drive API") |
| 35 | fmt.Println("4. Go to credentials and create an OAuth client ID") |
| 36 | fmt.Println("5. Set the application type to 'other'") |
| 37 | fmt.Println("6. Specify some name and click create") |
| 38 | fmt.Printf("7. Enter your generated client ID: ") |
| 39 | |
| 40 | if _, err := fmt.Scan(&config.ClientID); err != nil { |
| 41 | Log.Debugf("%v", err) |
| 42 | return nil, fmt.Errorf("Unable to read client id") |
| 43 | } |
| 44 | fmt.Printf("8. Enter your generated client secret: ") |
| 45 | if _, err := fmt.Scan(&config.ClientSecret); err != nil { |
| 46 | Log.Debugf("%v", err) |
| 47 | return nil, fmt.Errorf("Unable to read client secret") |
| 48 | } |
| 49 | |
| 50 | configJSON, err := json.Marshal(&config) |
| 51 | if nil != err { |
| 52 | Log.Debugf("%v", err) |
| 53 | return nil, fmt.Errorf("Could not generate config.json content") |
| 54 | } |
| 55 | |
| 56 | if err := ioutil.WriteFile(configPath, configJSON, 0766); nil != err { |
| 57 | Log.Debugf("%v", err) |
| 58 | return nil, fmt.Errorf("Could not generate config.json file") |
| 59 | } |
| 60 | |
| 61 | return &config, nil |
| 62 | } |