// DO NOT EDIT ! // This file was generated automatically from 'src/mako/cli/main.rs.mako' // DO NOT EDIT ! #![feature(plugin, exit_status)] #![plugin(docopt_macros)] #![allow(unused_variables, unused_imports, dead_code, unused_mut)] extern crate docopt; extern crate yup_oauth2 as oauth2; extern crate yup_hyper_mock as mock; extern crate rustc_serialize; extern crate serde; extern crate hyper; extern crate mime; extern crate google_cloudsearch1 as api; use std::env; use std::io::{self, Write}; docopt!(Options derive Debug, " Usage: cloudsearch1 --help All documentation details can be found at http://byron.github.io/google-apis-rs/google_cloudsearch1_cli/index.html Configuration: --config-dir A directory into which we will store our persistent data. Defaults to a user-writable directory that we will create during the first invocation. [default: ~/.google-service-cli] --debug Output all server communication to standard error. `tx` and `rx` are placed into the same stream. --debug-auth Output all communication related to authentication to standard error. `tx` and `rx` are placed into the same stream. "); mod cmn; use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg, input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError}; use std::default::Default; use std::str::FromStr; use oauth2::{Authenticator, DefaultAuthenticatorDelegate}; use rustc_serialize::json; struct Engine { opt: Options, hub: api::Cloudsearch>, } impl Engine { fn _doit(&self, dry_run: bool) -> (Option, Option) { let mut err = InvalidOptionsError::new(); let mut call_result: Option; let mut err_opt: Option = None; else { unreachable!(); } if dry_run { if err.issues.len() > 0 { err_opt = Some(err); } } (call_result, err_opt) } // Please note that this call will fail if any part of the opt can't be handled fn new(opt: Options) -> Result { let (config_dir, secret) = { let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) { Err(e) => return Err(InvalidOptionsError::single(e, 3)), Ok(p) => p, }; match cmn::application_secret_from_directory(&config_dir, "cloudsearch1-secret.json", "{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") { Ok(secret) => (config_dir, secret), Err(e) => return Err(InvalidOptionsError::single(e, 4)) } }; let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate, if opt.flag_debug_auth { hyper::Client::with_connector(mock::TeeConnector { connector: hyper::net::HttpConnector(None) }) } else { hyper::Client::new() }, JsonTokenStorage { program_name: "cloudsearch1", db_dir: config_dir.clone(), }, None); let client = if opt.flag_debug { hyper::Client::with_connector(mock::TeeConnector { connector: hyper::net::HttpConnector(None) }) } else { hyper::Client::new() }; let engine = Engine { opt: opt, hub: api::Cloudsearch::new(client, auth), }; match engine._doit(true) { (_, Some(err)) => Err(err), _ => Ok(engine), } } // Execute the call with all the bells and whistles, informing the caller only if there was an error. // The absense of one indicates success. fn doit(&self) -> Option { self._doit(false).0 } } fn main() { let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); let debug = opts.flag_debug; match Engine::new(opts) { Err(err) => { writeln!(io::stderr(), "{}", err).ok(); env::set_exit_status(err.exit_code); }, Ok(engine) => { if let Some(err) = engine.doit() { if debug { writeln!(io::stderr(), "{:?}", err).ok(); } else { writeln!(io::stderr(), "{}", err).ok(); } env::set_exit_status(1); } } } }