mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
fix(all): update all code to latest version
* add new APIs * remove old ones * add latest json files
This commit is contained in:
31
gen/dfareporting2d1-cli/Cargo.toml
Normal file
31
gen/dfareporting2d1-cli/Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
# DO NOT EDIT !
|
||||
# This file was generated automatically from 'src/mako/Cargo.toml.mako'
|
||||
# DO NOT EDIT !
|
||||
[package]
|
||||
|
||||
name = "google-dfareporting2d1-cli"
|
||||
version = "0.0.1+20150326"
|
||||
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
|
||||
description = "A complete library to interact with dfareporting (protocol v2.1)"
|
||||
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/dfareporting2d1-cli"
|
||||
homepage = "https://developers.google.com/doubleclick-advertisers/reporting/"
|
||||
documentation = "http://byron.github.io/google-apis-rs/google_dfareporting2d1_cli"
|
||||
license = "MIT"
|
||||
keywords = ["dfareporting", "google", "cli"]
|
||||
|
||||
[[bin]]
|
||||
name = "dfareporting2d1"
|
||||
|
||||
[dependencies]
|
||||
hyper = "*"
|
||||
mime = "*"
|
||||
yup-oauth2 = "*"
|
||||
docopt = "*"
|
||||
docopt_macros = "*"
|
||||
rustc-serialize = "*"
|
||||
yup-hyper-mock = "*"
|
||||
serde = ">= 0.3.0"
|
||||
serde_macros = "*"
|
||||
|
||||
[dependencies.google-dfareporting2d1]
|
||||
path = "../dfareporting2d1"
|
||||
30
gen/dfareporting2d1-cli/LICENSE.md
Normal file
30
gen/dfareporting2d1-cli/LICENSE.md
Normal file
@@ -0,0 +1,30 @@
|
||||
<!---
|
||||
DO NOT EDIT !
|
||||
This file was generated automatically from 'src/mako/LICENSE.md.mako'
|
||||
DO NOT EDIT !
|
||||
-->
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright © `2015` `Sebastian Thiel`
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the “Software”), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
4
gen/dfareporting2d1-cli/README.md
Normal file
4
gen/dfareporting2d1-cli/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# HELLO DFAREPORTING:V2.1
|
||||
|
||||
|
||||
Include information about application secret files, and how we automatically write a default one.
|
||||
209
gen/dfareporting2d1-cli/mkdocs.yml
Normal file
209
gen/dfareporting2d1-cli/mkdocs.yml
Normal file
@@ -0,0 +1,209 @@
|
||||
site_name: dfareporting v0.0.1+20150326
|
||||
site_url: http://byron.github.io/google-apis-rs/google-dfareporting2d1-cli
|
||||
site_description: Write integrating applications with bcore
|
||||
|
||||
repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/dfareporting2d1-cli
|
||||
|
||||
docs_dir: docs
|
||||
site_dir: build_html
|
||||
|
||||
pages:
|
||||
- ['index.md', 'Home']
|
||||
- ['account-active-ad-summaries_get.md', 'Account Active Ad Summaries', 'Get']
|
||||
- ['account-permission-groups_get.md', 'Account Permission Groups', 'Get']
|
||||
- ['account-permission-groups_list.md', 'Account Permission Groups', 'List']
|
||||
- ['account-permissions_get.md', 'Account Permissions', 'Get']
|
||||
- ['account-permissions_list.md', 'Account Permissions', 'List']
|
||||
- ['account-user-profiles_get.md', 'Account User Profiles', 'Get']
|
||||
- ['account-user-profiles_insert.md', 'Account User Profiles', 'Insert']
|
||||
- ['account-user-profiles_list.md', 'Account User Profiles', 'List']
|
||||
- ['account-user-profiles_patch.md', 'Account User Profiles', 'Patch']
|
||||
- ['account-user-profiles_update.md', 'Account User Profiles', 'Update']
|
||||
- ['accounts_get.md', 'Accounts', 'Get']
|
||||
- ['accounts_list.md', 'Accounts', 'List']
|
||||
- ['accounts_patch.md', 'Accounts', 'Patch']
|
||||
- ['accounts_update.md', 'Accounts', 'Update']
|
||||
- ['ads_get.md', 'Ads', 'Get']
|
||||
- ['ads_insert.md', 'Ads', 'Insert']
|
||||
- ['ads_list.md', 'Ads', 'List']
|
||||
- ['ads_patch.md', 'Ads', 'Patch']
|
||||
- ['ads_update.md', 'Ads', 'Update']
|
||||
- ['advertiser-groups_delete.md', 'Advertiser Groups', 'Delete']
|
||||
- ['advertiser-groups_get.md', 'Advertiser Groups', 'Get']
|
||||
- ['advertiser-groups_insert.md', 'Advertiser Groups', 'Insert']
|
||||
- ['advertiser-groups_list.md', 'Advertiser Groups', 'List']
|
||||
- ['advertiser-groups_patch.md', 'Advertiser Groups', 'Patch']
|
||||
- ['advertiser-groups_update.md', 'Advertiser Groups', 'Update']
|
||||
- ['advertisers_get.md', 'Advertisers', 'Get']
|
||||
- ['advertisers_insert.md', 'Advertisers', 'Insert']
|
||||
- ['advertisers_list.md', 'Advertisers', 'List']
|
||||
- ['advertisers_patch.md', 'Advertisers', 'Patch']
|
||||
- ['advertisers_update.md', 'Advertisers', 'Update']
|
||||
- ['browsers_list.md', 'Browsers', 'List']
|
||||
- ['campaign-creative-associations_insert.md', 'Campaign Creative Associations', 'Insert']
|
||||
- ['campaign-creative-associations_list.md', 'Campaign Creative Associations', 'List']
|
||||
- ['campaigns_get.md', 'Campaigns', 'Get']
|
||||
- ['campaigns_insert.md', 'Campaigns', 'Insert']
|
||||
- ['campaigns_list.md', 'Campaigns', 'List']
|
||||
- ['campaigns_patch.md', 'Campaigns', 'Patch']
|
||||
- ['campaigns_update.md', 'Campaigns', 'Update']
|
||||
- ['change-logs_get.md', 'Change Logs', 'Get']
|
||||
- ['change-logs_list.md', 'Change Logs', 'List']
|
||||
- ['cities_list.md', 'Cities', 'List']
|
||||
- ['connection-types_get.md', 'Connection Types', 'Get']
|
||||
- ['connection-types_list.md', 'Connection Types', 'List']
|
||||
- ['content-categories_delete.md', 'Content Categories', 'Delete']
|
||||
- ['content-categories_get.md', 'Content Categories', 'Get']
|
||||
- ['content-categories_insert.md', 'Content Categories', 'Insert']
|
||||
- ['content-categories_list.md', 'Content Categories', 'List']
|
||||
- ['content-categories_patch.md', 'Content Categories', 'Patch']
|
||||
- ['content-categories_update.md', 'Content Categories', 'Update']
|
||||
- ['countries_get.md', 'Countries', 'Get']
|
||||
- ['countries_list.md', 'Countries', 'List']
|
||||
- ['creative-assets_insert.md', 'Creative Assets', 'Insert']
|
||||
- ['creative-field-values_delete.md', 'Creative Field Values', 'Delete']
|
||||
- ['creative-field-values_get.md', 'Creative Field Values', 'Get']
|
||||
- ['creative-field-values_insert.md', 'Creative Field Values', 'Insert']
|
||||
- ['creative-field-values_list.md', 'Creative Field Values', 'List']
|
||||
- ['creative-field-values_patch.md', 'Creative Field Values', 'Patch']
|
||||
- ['creative-field-values_update.md', 'Creative Field Values', 'Update']
|
||||
- ['creative-fields_delete.md', 'Creative Fields', 'Delete']
|
||||
- ['creative-fields_get.md', 'Creative Fields', 'Get']
|
||||
- ['creative-fields_insert.md', 'Creative Fields', 'Insert']
|
||||
- ['creative-fields_list.md', 'Creative Fields', 'List']
|
||||
- ['creative-fields_patch.md', 'Creative Fields', 'Patch']
|
||||
- ['creative-fields_update.md', 'Creative Fields', 'Update']
|
||||
- ['creative-groups_get.md', 'Creative Groups', 'Get']
|
||||
- ['creative-groups_insert.md', 'Creative Groups', 'Insert']
|
||||
- ['creative-groups_list.md', 'Creative Groups', 'List']
|
||||
- ['creative-groups_patch.md', 'Creative Groups', 'Patch']
|
||||
- ['creative-groups_update.md', 'Creative Groups', 'Update']
|
||||
- ['creatives_get.md', 'Creatives', 'Get']
|
||||
- ['creatives_insert.md', 'Creatives', 'Insert']
|
||||
- ['creatives_list.md', 'Creatives', 'List']
|
||||
- ['creatives_patch.md', 'Creatives', 'Patch']
|
||||
- ['creatives_update.md', 'Creatives', 'Update']
|
||||
- ['dimension-values_query.md', 'Dimension Values', 'Query']
|
||||
- ['directory-site-contacts_get.md', 'Directory Site Contacts', 'Get']
|
||||
- ['directory-site-contacts_list.md', 'Directory Site Contacts', 'List']
|
||||
- ['directory-sites_get.md', 'Directory Sites', 'Get']
|
||||
- ['directory-sites_insert.md', 'Directory Sites', 'Insert']
|
||||
- ['directory-sites_list.md', 'Directory Sites', 'List']
|
||||
- ['event-tags_delete.md', 'Event Tags', 'Delete']
|
||||
- ['event-tags_get.md', 'Event Tags', 'Get']
|
||||
- ['event-tags_insert.md', 'Event Tags', 'Insert']
|
||||
- ['event-tags_list.md', 'Event Tags', 'List']
|
||||
- ['event-tags_patch.md', 'Event Tags', 'Patch']
|
||||
- ['event-tags_update.md', 'Event Tags', 'Update']
|
||||
- ['files_get.md', 'Files', 'Get']
|
||||
- ['files_list.md', 'Files', 'List']
|
||||
- ['floodlight-activities_delete.md', 'Floodlight Activities', 'Delete']
|
||||
- ['floodlight-activities_generatetag.md', 'Floodlight Activities', 'Generatetag']
|
||||
- ['floodlight-activities_get.md', 'Floodlight Activities', 'Get']
|
||||
- ['floodlight-activities_insert.md', 'Floodlight Activities', 'Insert']
|
||||
- ['floodlight-activities_list.md', 'Floodlight Activities', 'List']
|
||||
- ['floodlight-activities_patch.md', 'Floodlight Activities', 'Patch']
|
||||
- ['floodlight-activities_update.md', 'Floodlight Activities', 'Update']
|
||||
- ['floodlight-activity-groups_delete.md', 'Floodlight Activity Groups', 'Delete']
|
||||
- ['floodlight-activity-groups_get.md', 'Floodlight Activity Groups', 'Get']
|
||||
- ['floodlight-activity-groups_insert.md', 'Floodlight Activity Groups', 'Insert']
|
||||
- ['floodlight-activity-groups_list.md', 'Floodlight Activity Groups', 'List']
|
||||
- ['floodlight-activity-groups_patch.md', 'Floodlight Activity Groups', 'Patch']
|
||||
- ['floodlight-activity-groups_update.md', 'Floodlight Activity Groups', 'Update']
|
||||
- ['floodlight-configurations_get.md', 'Floodlight Configurations', 'Get']
|
||||
- ['floodlight-configurations_list.md', 'Floodlight Configurations', 'List']
|
||||
- ['floodlight-configurations_patch.md', 'Floodlight Configurations', 'Patch']
|
||||
- ['floodlight-configurations_update.md', 'Floodlight Configurations', 'Update']
|
||||
- ['inventory-items_get.md', 'Inventory Items', 'Get']
|
||||
- ['inventory-items_list.md', 'Inventory Items', 'List']
|
||||
- ['landing-pages_delete.md', 'Landing Pages', 'Delete']
|
||||
- ['landing-pages_get.md', 'Landing Pages', 'Get']
|
||||
- ['landing-pages_insert.md', 'Landing Pages', 'Insert']
|
||||
- ['landing-pages_list.md', 'Landing Pages', 'List']
|
||||
- ['landing-pages_patch.md', 'Landing Pages', 'Patch']
|
||||
- ['landing-pages_update.md', 'Landing Pages', 'Update']
|
||||
- ['metros_list.md', 'Metros', 'List']
|
||||
- ['mobile-carriers_get.md', 'Mobile Carriers', 'Get']
|
||||
- ['mobile-carriers_list.md', 'Mobile Carriers', 'List']
|
||||
- ['operating-system-versions_get.md', 'Operating System Versions', 'Get']
|
||||
- ['operating-system-versions_list.md', 'Operating System Versions', 'List']
|
||||
- ['operating-systems_get.md', 'Operating Systems', 'Get']
|
||||
- ['operating-systems_list.md', 'Operating Systems', 'List']
|
||||
- ['order-documents_get.md', 'Order Documents', 'Get']
|
||||
- ['order-documents_list.md', 'Order Documents', 'List']
|
||||
- ['orders_get.md', 'Orders', 'Get']
|
||||
- ['orders_list.md', 'Orders', 'List']
|
||||
- ['placement-groups_get.md', 'Placement Groups', 'Get']
|
||||
- ['placement-groups_insert.md', 'Placement Groups', 'Insert']
|
||||
- ['placement-groups_list.md', 'Placement Groups', 'List']
|
||||
- ['placement-groups_patch.md', 'Placement Groups', 'Patch']
|
||||
- ['placement-groups_update.md', 'Placement Groups', 'Update']
|
||||
- ['placement-strategies_delete.md', 'Placement Strategies', 'Delete']
|
||||
- ['placement-strategies_get.md', 'Placement Strategies', 'Get']
|
||||
- ['placement-strategies_insert.md', 'Placement Strategies', 'Insert']
|
||||
- ['placement-strategies_list.md', 'Placement Strategies', 'List']
|
||||
- ['placement-strategies_patch.md', 'Placement Strategies', 'Patch']
|
||||
- ['placement-strategies_update.md', 'Placement Strategies', 'Update']
|
||||
- ['placements_generatetags.md', 'Placements', 'Generatetags']
|
||||
- ['placements_get.md', 'Placements', 'Get']
|
||||
- ['placements_insert.md', 'Placements', 'Insert']
|
||||
- ['placements_list.md', 'Placements', 'List']
|
||||
- ['placements_patch.md', 'Placements', 'Patch']
|
||||
- ['placements_update.md', 'Placements', 'Update']
|
||||
- ['platform-types_get.md', 'Platform Types', 'Get']
|
||||
- ['platform-types_list.md', 'Platform Types', 'List']
|
||||
- ['postal-codes_get.md', 'Postal Codes', 'Get']
|
||||
- ['postal-codes_list.md', 'Postal Codes', 'List']
|
||||
- ['projects_get.md', 'Projects', 'Get']
|
||||
- ['projects_list.md', 'Projects', 'List']
|
||||
- ['regions_list.md', 'Regions', 'List']
|
||||
- ['remarketing-list-shares_get.md', 'Remarketing List Shares', 'Get']
|
||||
- ['remarketing-list-shares_patch.md', 'Remarketing List Shares', 'Patch']
|
||||
- ['remarketing-list-shares_update.md', 'Remarketing List Shares', 'Update']
|
||||
- ['remarketing-lists_get.md', 'Remarketing Lists', 'Get']
|
||||
- ['remarketing-lists_insert.md', 'Remarketing Lists', 'Insert']
|
||||
- ['remarketing-lists_list.md', 'Remarketing Lists', 'List']
|
||||
- ['remarketing-lists_patch.md', 'Remarketing Lists', 'Patch']
|
||||
- ['remarketing-lists_update.md', 'Remarketing Lists', 'Update']
|
||||
- ['reports_compatible-fields-query.md', 'Reports', 'Compatible Fields Query']
|
||||
- ['reports_delete.md', 'Reports', 'Delete']
|
||||
- ['reports_files-get.md', 'Reports', 'Files Get']
|
||||
- ['reports_files-list.md', 'Reports', 'Files List']
|
||||
- ['reports_get.md', 'Reports', 'Get']
|
||||
- ['reports_insert.md', 'Reports', 'Insert']
|
||||
- ['reports_list.md', 'Reports', 'List']
|
||||
- ['reports_patch.md', 'Reports', 'Patch']
|
||||
- ['reports_run.md', 'Reports', 'Run']
|
||||
- ['reports_update.md', 'Reports', 'Update']
|
||||
- ['sites_get.md', 'Sites', 'Get']
|
||||
- ['sites_insert.md', 'Sites', 'Insert']
|
||||
- ['sites_list.md', 'Sites', 'List']
|
||||
- ['sites_patch.md', 'Sites', 'Patch']
|
||||
- ['sites_update.md', 'Sites', 'Update']
|
||||
- ['sizes_get.md', 'Sizes', 'Get']
|
||||
- ['sizes_insert.md', 'Sizes', 'Insert']
|
||||
- ['sizes_list.md', 'Sizes', 'List']
|
||||
- ['subaccounts_get.md', 'Subaccounts', 'Get']
|
||||
- ['subaccounts_insert.md', 'Subaccounts', 'Insert']
|
||||
- ['subaccounts_list.md', 'Subaccounts', 'List']
|
||||
- ['subaccounts_patch.md', 'Subaccounts', 'Patch']
|
||||
- ['subaccounts_update.md', 'Subaccounts', 'Update']
|
||||
- ['targetable-remarketing-lists_get.md', 'Targetable Remarketing Lists', 'Get']
|
||||
- ['targetable-remarketing-lists_list.md', 'Targetable Remarketing Lists', 'List']
|
||||
- ['user-profiles_get.md', 'User Profiles', 'Get']
|
||||
- ['user-profiles_list.md', 'User Profiles', 'List']
|
||||
- ['user-role-permission-groups_get.md', 'User Role Permission Groups', 'Get']
|
||||
- ['user-role-permission-groups_list.md', 'User Role Permission Groups', 'List']
|
||||
- ['user-role-permissions_get.md', 'User Role Permissions', 'Get']
|
||||
- ['user-role-permissions_list.md', 'User Role Permissions', 'List']
|
||||
- ['user-roles_delete.md', 'User Roles', 'Delete']
|
||||
- ['user-roles_get.md', 'User Roles', 'Get']
|
||||
- ['user-roles_insert.md', 'User Roles', 'Insert']
|
||||
- ['user-roles_list.md', 'User Roles', 'List']
|
||||
- ['user-roles_patch.md', 'User Roles', 'Patch']
|
||||
- ['user-roles_update.md', 'User Roles', 'Update']
|
||||
|
||||
theme: readthedocs
|
||||
|
||||
copyright: Copyright © 2015, `Sebastian Thiel`
|
||||
|
||||
454
gen/dfareporting2d1-cli/src/cmn.rs
Normal file
454
gen/dfareporting2d1-cli/src/cmn.rs
Normal file
@@ -0,0 +1,454 @@
|
||||
// COPY OF 'src/rust/cli/cmn.rs'
|
||||
// DO NOT EDIT
|
||||
use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token};
|
||||
use rustc_serialize::json;
|
||||
use mime::Mime;
|
||||
|
||||
use std::fs;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::string::ToString;
|
||||
use std::io::{Write, Read, stdout};
|
||||
|
||||
use std::default::Default;
|
||||
|
||||
const FIELD_SEP: char = '.';
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct FieldCursor(Vec<String>);
|
||||
|
||||
impl ToString for FieldCursor {
|
||||
fn to_string(&self) -> String {
|
||||
self.0.connect(".")
|
||||
}
|
||||
}
|
||||
|
||||
impl FieldCursor {
|
||||
pub fn set(&mut self, value: &str) -> Result<(), CLIError> {
|
||||
if value.len() == 0 {
|
||||
return Err(CLIError::Field(FieldError::Empty))
|
||||
}
|
||||
|
||||
let mut first_is_field_sep = false;
|
||||
let mut char_count: usize = 0;
|
||||
let mut last_c = FIELD_SEP;
|
||||
let mut num_conscutive_field_seps = 0;
|
||||
|
||||
let mut field = String::new();
|
||||
let mut fields = self.0.clone();
|
||||
|
||||
let push_field = |fs: &mut Vec<String>, f: &mut String| {
|
||||
if f.len() > 0 {
|
||||
fs.push(f.clone());
|
||||
f.truncate(0);
|
||||
}
|
||||
};
|
||||
|
||||
for (cid, c) in value.chars().enumerate() {
|
||||
char_count += 1;
|
||||
|
||||
if c == FIELD_SEP {
|
||||
if cid == 0 {
|
||||
first_is_field_sep = true;
|
||||
}
|
||||
num_conscutive_field_seps += 1;
|
||||
if cid > 0 && last_c == FIELD_SEP {
|
||||
if fields.pop().is_none() {
|
||||
return Err(CLIError::Field(FieldError::PopOnEmpty(value.to_string())))
|
||||
}
|
||||
} else {
|
||||
push_field(&mut fields, &mut field);
|
||||
}
|
||||
} else {
|
||||
num_conscutive_field_seps = 0;
|
||||
if cid == 1 {
|
||||
if first_is_field_sep {
|
||||
fields.truncate(0);
|
||||
}
|
||||
}
|
||||
field.push(c);
|
||||
}
|
||||
|
||||
last_c = c;
|
||||
}
|
||||
|
||||
push_field(&mut fields, &mut field);
|
||||
|
||||
if char_count == 1 && first_is_field_sep {
|
||||
fields.truncate(0);
|
||||
}
|
||||
if char_count > 1 && num_conscutive_field_seps == 1 {
|
||||
return Err(CLIError::Field(FieldError::TrailingFieldSep(value.to_string())))
|
||||
}
|
||||
|
||||
self.0 = fields;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn num_fields(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap: bool)
|
||||
-> (&'a str, Option<&'a str>) {
|
||||
let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string(),for_hashmap));
|
||||
match kv.find('=') {
|
||||
None => {
|
||||
add_err();
|
||||
return (kv, None)
|
||||
},
|
||||
Some(pos) => {
|
||||
let key = &kv[..pos];
|
||||
if kv.len() <= pos + 1 {
|
||||
add_err();
|
||||
return (key, None)
|
||||
}
|
||||
(key, Some(&kv[pos+1..]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> {
|
||||
match fs::File::open(file_path) {
|
||||
Ok(f) => Some(f),
|
||||
Err(io_err) => {
|
||||
err.issues.push(CLIError::Input(InputError::IOError((file_path.to_string(), io_err))));
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option<Mime> {
|
||||
match mime.parse() {
|
||||
Ok(m) => Some(m),
|
||||
Err(_) => {
|
||||
err.issues.push(CLIError::Input(InputError::Mime(mime.to_string())));
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// May panic if we can't open the file - this is anticipated, we can't currently communicate this
|
||||
// kind of error: TODO: fix this architecture :)
|
||||
pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> {
|
||||
if !flag || arg == "-" {
|
||||
Box::new(stdout())
|
||||
} else {
|
||||
Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError,
|
||||
arg_name: &'static str,
|
||||
arg_type: &'static str) -> T
|
||||
where T: FromStr + Default,
|
||||
<T as FromStr>::Err: fmt::Display {
|
||||
match FromStr::from_str(arg) {
|
||||
Err(perr) => {
|
||||
err.issues.push(
|
||||
CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr)))
|
||||
);
|
||||
Default::default()
|
||||
},
|
||||
Ok(v) => v,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JsonTokenStorage {
|
||||
pub program_name: &'static str,
|
||||
pub db_dir: String,
|
||||
}
|
||||
|
||||
impl JsonTokenStorage {
|
||||
fn path(&self, scope_hash: u64) -> PathBuf {
|
||||
Path::new(&self.db_dir).join(&format!("{}-token-{}.json", self.program_name, scope_hash))
|
||||
}
|
||||
}
|
||||
|
||||
impl TokenStorage for JsonTokenStorage {
|
||||
type Error = io::Error;
|
||||
|
||||
// NOTE: logging might be interesting, currently we swallow all errors
|
||||
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> {
|
||||
match token {
|
||||
None => {
|
||||
match fs::remove_file(self.path(scope_hash)) {
|
||||
Err(err) =>
|
||||
match err.kind() {
|
||||
io::ErrorKind::NotFound => None,
|
||||
_ => Some(err)
|
||||
},
|
||||
Ok(_) => None
|
||||
}
|
||||
}
|
||||
Some(token) => {
|
||||
let json_token = json::encode(&token).unwrap();
|
||||
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
|
||||
Ok(mut f) => {
|
||||
match f.write(json_token.as_bytes()) {
|
||||
Ok(_) => None,
|
||||
Err(io_err) => Some(io_err),
|
||||
}
|
||||
},
|
||||
Err(io_err) => Some(io_err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> {
|
||||
match fs::File::open(&self.path(scope_hash)) {
|
||||
Ok(mut f) => {
|
||||
let mut json_string = String::new();
|
||||
match f.read_to_string(&mut json_string) {
|
||||
Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())),
|
||||
Err(io_err) => Err(io_err),
|
||||
}
|
||||
},
|
||||
Err(io_err) => {
|
||||
match io_err.kind() {
|
||||
io::ErrorKind::NotFound => Ok(None),
|
||||
_ => Err(io_err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ApplicationSecretError {
|
||||
DecoderError((String, json::DecoderError)),
|
||||
FormatError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for ApplicationSecretError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
ApplicationSecretError::DecoderError((ref path, ref err))
|
||||
=> writeln!(f, "Could not decode file at '{}' with error: {}",
|
||||
path, err),
|
||||
ApplicationSecretError::FormatError(ref path)
|
||||
=> writeln!(f, "'installed' field is unset in secret file at '{}'",
|
||||
path),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigurationError {
|
||||
DirectoryCreationFailed((String, io::Error)),
|
||||
DirectoryUnset,
|
||||
HomeExpansionFailed(String),
|
||||
Secret(ApplicationSecretError),
|
||||
IOError((String, io::Error)),
|
||||
}
|
||||
|
||||
impl fmt::Display for ConfigurationError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
ConfigurationError::DirectoryCreationFailed((ref dir, ref err))
|
||||
=> writeln!(f, "Directory '{}' could not be created with error: {}", dir, err),
|
||||
ConfigurationError::DirectoryUnset
|
||||
=> writeln!(f, "--config-dir was unset or empty"),
|
||||
ConfigurationError::HomeExpansionFailed(ref dir)
|
||||
=> writeln!(f, "Couldn't find HOME directory of current user, failed to expand '{}'", dir),
|
||||
ConfigurationError::Secret(ref err)
|
||||
=> writeln!(f, "Secret -> {}", err),
|
||||
ConfigurationError::IOError((ref path, ref err))
|
||||
=> writeln!(f, "IO operation failed on path '{}' with error: {}", path, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InputError {
|
||||
IOError((String, io::Error)),
|
||||
Mime(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for InputError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
InputError::IOError((ref file_path, ref io_err))
|
||||
=> writeln!(f, "Failed to open '{}' for reading with error: {}", file_path, io_err),
|
||||
InputError::Mime(ref mime)
|
||||
=> writeln!(f, "'{}' is not a known mime-type", mime),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FieldError {
|
||||
PopOnEmpty(String),
|
||||
TrailingFieldSep(String),
|
||||
Unknown(String),
|
||||
Empty,
|
||||
}
|
||||
|
||||
|
||||
impl fmt::Display for FieldError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
FieldError::PopOnEmpty(ref field)
|
||||
=> writeln!(f, "'{}': Cannot move up on empty field cursor", field),
|
||||
FieldError::TrailingFieldSep(ref field)
|
||||
=> writeln!(f, "'{}': Single field separator may not be last character", field),
|
||||
FieldError::Unknown(ref field)
|
||||
=> writeln!(f, "Field '{}' does not exist", field),
|
||||
FieldError::Empty
|
||||
=> writeln!(f, "Field names must not be empty"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CLIError {
|
||||
Configuration(ConfigurationError),
|
||||
ParseError((&'static str, &'static str, String, String)),
|
||||
UnknownParameter(String),
|
||||
InvalidKeyValueSyntax(String, bool),
|
||||
Input(InputError),
|
||||
Field(FieldError),
|
||||
}
|
||||
|
||||
impl fmt::Display for CLIError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
|
||||
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
|
||||
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
|
||||
CLIError::ParseError((arg_name, type_name, ref value, ref err_desc))
|
||||
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}",
|
||||
arg_name, value, type_name, err_desc),
|
||||
CLIError::UnknownParameter(ref param_name)
|
||||
=> writeln!(f, "Parameter '{}' is unknown.", param_name),
|
||||
CLIError::InvalidKeyValueSyntax(ref kv, is_hashmap) => {
|
||||
let hashmap_info = if is_hashmap { "hashmap " } else { "" };
|
||||
writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InvalidOptionsError {
|
||||
pub issues: Vec<CLIError>,
|
||||
pub exit_code: i32,
|
||||
}
|
||||
|
||||
impl fmt::Display for InvalidOptionsError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
for issue in &self.issues {
|
||||
try!(issue.fmt(f));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl InvalidOptionsError {
|
||||
pub fn single(err: CLIError, exit_code: i32) -> InvalidOptionsError {
|
||||
InvalidOptionsError {
|
||||
issues: vec![err],
|
||||
exit_code: exit_code,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new() -> InvalidOptionsError {
|
||||
InvalidOptionsError {
|
||||
issues: Vec::new(),
|
||||
exit_code: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
|
||||
let trdir = dir.trim();
|
||||
if trdir.len() == 0 {
|
||||
return Err(CLIError::Configuration(ConfigurationError::DirectoryUnset))
|
||||
}
|
||||
|
||||
let expanded_config_dir =
|
||||
if trdir.as_bytes()[0] == b'~' {
|
||||
match env::var("HOME").ok().or(env::var("UserProfile").ok()) {
|
||||
None => return Err(CLIError::Configuration(ConfigurationError::HomeExpansionFailed(trdir.to_string()))),
|
||||
Some(mut user) => {
|
||||
user.push_str(&trdir[1..]);
|
||||
user
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trdir.to_string()
|
||||
};
|
||||
|
||||
if let Err(err) = fs::create_dir(&expanded_config_dir) {
|
||||
if err.kind() != io::ErrorKind::AlreadyExists {
|
||||
return Err(CLIError::Configuration(
|
||||
ConfigurationError::DirectoryCreationFailed((expanded_config_dir, err))))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(expanded_config_dir)
|
||||
}
|
||||
|
||||
pub fn application_secret_from_directory(dir: &str,
|
||||
secret_basename: &str,
|
||||
json_app_secret: &str)
|
||||
-> Result<ApplicationSecret, CLIError> {
|
||||
let secret_path = Path::new(dir).join(secret_basename);
|
||||
let secret_str = || secret_path.as_path().to_str().unwrap().to_string();
|
||||
let secret_io_error = |io_err: io::Error| {
|
||||
Err(CLIError::Configuration(ConfigurationError::IOError(
|
||||
(secret_str(), io_err)
|
||||
)))
|
||||
};
|
||||
|
||||
for _ in 0..2 {
|
||||
match fs::File::open(&secret_path) {
|
||||
Err(mut err) => {
|
||||
if err.kind() == io::ErrorKind::NotFound {
|
||||
// Write our built-in one - user may adjust the written file at will
|
||||
|
||||
err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) {
|
||||
Err(cfe) => cfe,
|
||||
Ok(mut f) => {
|
||||
match f.write(json_app_secret.as_bytes()) {
|
||||
Err(io_err) => io_err,
|
||||
Ok(_) => continue,
|
||||
}
|
||||
}
|
||||
};
|
||||
// fall through to IO error handling
|
||||
}
|
||||
return secret_io_error(err)
|
||||
},
|
||||
Ok(mut f) => {
|
||||
let mut json_encoded_secret = String::new();
|
||||
if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) {
|
||||
return secret_io_error(io_err)
|
||||
}
|
||||
match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) {
|
||||
Err(json_decode_error) => return Err(CLIError::Configuration(
|
||||
ConfigurationError::Secret(ApplicationSecretError::DecoderError(
|
||||
(secret_str(), json_decode_error)
|
||||
)))),
|
||||
Ok(console_secret) => match console_secret.installed {
|
||||
Some(secret) => return Ok(secret),
|
||||
None => return Err(
|
||||
CLIError::Configuration(
|
||||
ConfigurationError::Secret(
|
||||
ApplicationSecretError::FormatError(secret_str())
|
||||
)))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unreachable!();
|
||||
}
|
||||
22209
gen/dfareporting2d1-cli/src/main.rs
Normal file
22209
gen/dfareporting2d1-cli/src/main.rs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user