From f5f12c559448f73a08a812f4ac40bfc6dafcbabb Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 16 Apr 2015 22:44:40 +0200 Subject: [PATCH] feat(CLI): added first versions of all CLI That way, changes can be tracked. Also, we make it official. Future checkins will only be made if major changes were done, similar to how the APIs are handled. Related to #64 --- .gitignore | 1 - gen/adexchangebuyer1d3-cli/Cargo.toml | 30 + gen/adexchangebuyer1d3-cli/LICENSE.md | 30 + gen/adexchangebuyer1d3-cli/README.md | 4 + gen/adexchangebuyer1d3-cli/mkdocs.yml | 37 + gen/adexchangebuyer1d3-cli/src/cmn.rs | 439 + gen/adexchangebuyer1d3-cli/src/main.rs | 1742 ++ gen/adexchangeseller2-cli/Cargo.toml | 30 + gen/adexchangeseller2-cli/LICENSE.md | 30 + gen/adexchangeseller2-cli/README.md | 4 + gen/adexchangeseller2-cli/mkdocs.yml | 30 + gen/adexchangeseller2-cli/src/cmn.rs | 439 + gen/adexchangeseller2-cli/src/main.rs | 855 + gen/admin1_directory-cli/Cargo.toml | 30 + gen/admin1_directory-cli/LICENSE.md | 30 + gen/admin1_directory-cli/README.md | 4 + gen/admin1_directory-cli/mkdocs.yml | 83 + gen/admin1_directory-cli/src/cmn.rs | 439 + gen/admin1_directory-cli/src/main.rs | 4769 ++++ gen/admin1_reports-cli/Cargo.toml | 30 + gen/admin1_reports-cli/LICENSE.md | 30 + gen/admin1_reports-cli/README.md | 4 + gen/admin1_reports-cli/mkdocs.yml | 21 + gen/admin1_reports-cli/src/cmn.rs | 439 + gen/admin1_reports-cli/src/main.rs | 535 + gen/admin2_email_migration-cli/Cargo.toml | 30 + gen/admin2_email_migration-cli/LICENSE.md | 30 + gen/admin2_email_migration-cli/README.md | 4 + gen/admin2_email_migration-cli/mkdocs.yml | 17 + gen/admin2_email_migration-cli/src/cmn.rs | 439 + gen/admin2_email_migration-cli/src/main.rs | 224 + gen/adsense1d4-cli/Cargo.toml | 30 + gen/adsense1d4-cli/LICENSE.md | 30 + gen/adsense1d4-cli/README.md | 4 + gen/adsense1d4-cli/mkdocs.yml | 54 + gen/adsense1d4-cli/src/cmn.rs | 439 + gen/adsense1d4-cli/src/main.rs | 2158 ++ gen/adsensehost4d1-cli/Cargo.toml | 30 + gen/adsensehost4d1-cli/LICENSE.md | 30 + gen/adsensehost4d1-cli/README.md | 4 + gen/adsensehost4d1-cli/mkdocs.yml | 42 + gen/adsensehost4d1-cli/src/cmn.rs | 439 + gen/adsensehost4d1-cli/src/main.rs | 1906 ++ gen/analytics3-cli/Cargo.toml | 30 + gen/analytics3-cli/LICENSE.md | 30 + gen/analytics3-cli/README.md | 4 + gen/analytics3-cli/mkdocs.yml | 94 + gen/analytics3-cli/src/cmn.rs | 439 + gen/analytics3-cli/src/main.rs | 8003 +++++++ gen/androidenterprise1-cli/Cargo.toml | 29 + gen/androidenterprise1-cli/LICENSE.md | 30 + gen/androidenterprise1-cli/README.md | 4 + gen/androidenterprise1-cli/mkdocs.yml | 60 + gen/androidenterprise1-cli/src/cmn.rs | 439 + gen/androidenterprise1-cli/src/main.rs | 2573 ++ gen/androidpublisher2-cli/Cargo.toml | 30 + gen/androidpublisher2-cli/LICENSE.md | 30 + gen/androidpublisher2-cli/README.md | 4 + gen/androidpublisher2-cli/mkdocs.yml | 67 + gen/androidpublisher2-cli/src/cmn.rs | 439 + gen/androidpublisher2-cli/src/main.rs | 3207 +++ gen/appsactivity1-cli/Cargo.toml | 30 + gen/appsactivity1-cli/LICENSE.md | 30 + gen/appsactivity1-cli/README.md | 4 + gen/appsactivity1-cli/mkdocs.yml | 17 + gen/appsactivity1-cli/src/cmn.rs | 439 + gen/appsactivity1-cli/src/main.rs | 194 + gen/appstate1-cli/Cargo.toml | 30 + gen/appstate1-cli/LICENSE.md | 30 + gen/appstate1-cli/README.md | 4 + gen/appstate1-cli/mkdocs.yml | 21 + gen/appstate1-cli/src/cmn.rs | 439 + gen/appstate1-cli/src/main.rs | 391 + gen/audit1-cli/Cargo.toml | 30 + gen/audit1-cli/LICENSE.md | 30 + gen/audit1-cli/README.md | 4 + gen/audit1-cli/mkdocs.yml | 17 + gen/audit1-cli/src/cmn.rs | 439 + gen/audit1-cli/src/main.rs | 196 + gen/autoscaler1_beta2-cli/Cargo.toml | 30 + gen/autoscaler1_beta2-cli/LICENSE.md | 30 + gen/autoscaler1_beta2-cli/README.md | 4 + gen/autoscaler1_beta2-cli/mkdocs.yml | 26 + gen/autoscaler1_beta2-cli/src/cmn.rs | 439 + gen/autoscaler1_beta2-cli/src/main.rs | 824 + gen/bigquery2-cli/Cargo.toml | 30 + gen/bigquery2-cli/LICENSE.md | 30 + gen/bigquery2-cli/README.md | 4 + gen/bigquery2-cli/mkdocs.yml | 36 + gen/bigquery2-cli/src/cmn.rs | 439 + gen/bigquery2-cli/src/main.rs | 2008 ++ gen/blogger3-cli/Cargo.toml | 30 + gen/blogger3-cli/LICENSE.md | 30 + gen/blogger3-cli/README.md | 4 + gen/blogger3-cli/mkdocs.yml | 49 + gen/blogger3-cli/src/cmn.rs | 439 + gen/blogger3-cli/src/main.rs | 2581 ++ gen/books1-cli/Cargo.toml | 30 + gen/books1-cli/LICENSE.md | 30 + gen/books1-cli/README.md | 4 + gen/books1-cli/mkdocs.yml | 60 + gen/books1-cli/src/cmn.rs | 439 + gen/books1-cli/src/main.rs | 3186 +++ gen/calendar3-cli/Cargo.toml | 30 + gen/calendar3-cli/LICENSE.md | 30 + gen/calendar3-cli/README.md | 4 + gen/calendar3-cli/mkdocs.yml | 53 + gen/calendar3-cli/src/cmn.rs | 439 + gen/calendar3-cli/src/main.rs | 3987 ++++ gen/civicinfo2-cli/Cargo.toml | 30 + gen/civicinfo2-cli/LICENSE.md | 30 + gen/civicinfo2-cli/README.md | 4 + gen/civicinfo2-cli/mkdocs.yml | 21 + gen/civicinfo2-cli/src/cmn.rs | 439 + gen/civicinfo2-cli/src/main.rs | 395 + gen/cloudlatencytest2-cli/Cargo.toml | 29 + gen/cloudlatencytest2-cli/LICENSE.md | 30 + gen/cloudlatencytest2-cli/README.md | 4 + gen/cloudlatencytest2-cli/mkdocs.yml | 18 + gen/cloudlatencytest2-cli/src/cmn.rs | 439 + gen/cloudlatencytest2-cli/src/main.rs | 249 + gen/cloudmonitoring2_beta2-cli/Cargo.toml | 30 + gen/cloudmonitoring2_beta2-cli/LICENSE.md | 30 + gen/cloudmonitoring2_beta2-cli/README.md | 4 + gen/cloudmonitoring2_beta2-cli/mkdocs.yml | 22 + gen/cloudmonitoring2_beta2-cli/src/cmn.rs | 439 + gen/cloudmonitoring2_beta2-cli/src/main.rs | 572 + gen/cloudsearch1-cli/Cargo.toml | 29 + gen/cloudsearch1-cli/LICENSE.md | 30 + gen/cloudsearch1-cli/README.md | 4 + gen/cloudsearch1-cli/mkdocs.yml | 22 + gen/cloudsearch1-cli/src/cmn.rs | 439 + gen/cloudsearch1-cli/src/main.rs | 469 + gen/compute1-cli/Cargo.toml | 30 + gen/compute1-cli/LICENSE.md | 30 + gen/compute1-cli/README.md | 4 + gen/compute1-cli/mkdocs.yml | 162 + gen/compute1-cli/src/cmn.rs | 439 + gen/compute1-cli/src/main.rs | 9416 ++++++++ gen/container1_beta1-cli/Cargo.toml | 30 + gen/container1_beta1-cli/LICENSE.md | 30 + gen/container1_beta1-cli/README.md | 4 + gen/container1_beta1-cli/mkdocs.yml | 24 + gen/container1_beta1-cli/src/cmn.rs | 439 + gen/container1_beta1-cli/src/main.rs | 597 + gen/content2-cli/Cargo.toml | 30 + gen/content2-cli/LICENSE.md | 30 + gen/content2-cli/README.md | 4 + gen/content2-cli/mkdocs.yml | 57 + gen/content2-cli/src/cmn.rs | 439 + gen/content2-cli/src/main.rs | 3148 +++ gen/coordinate1-cli/Cargo.toml | 30 + gen/coordinate1-cli/LICENSE.md | 30 + gen/coordinate1-cli/README.md | 4 + gen/coordinate1-cli/mkdocs.yml | 28 + gen/coordinate1-cli/src/cmn.rs | 439 + gen/coordinate1-cli/src/main.rs | 1110 + gen/coordinate1/src/cmn.rs | 46 +- gen/customsearch1-cli/Cargo.toml | 30 + gen/customsearch1-cli/LICENSE.md | 30 + gen/customsearch1-cli/README.md | 4 + gen/customsearch1-cli/mkdocs.yml | 17 + gen/customsearch1-cli/src/cmn.rs | 439 + gen/customsearch1-cli/src/main.rs | 262 + gen/customsearch1/src/cmn.rs | 46 +- gen/dataflow1_b4-cli/Cargo.toml | 29 + gen/dataflow1_b4-cli/LICENSE.md | 30 + gen/dataflow1_b4-cli/README.md | 4 + gen/dataflow1_b4-cli/mkdocs.yml | 16 + gen/dataflow1_b4-cli/src/cmn.rs | 439 + gen/dataflow1_b4-cli/src/main.rs | 118 + gen/datastore1_beta2-cli/Cargo.toml | 30 + gen/datastore1_beta2-cli/LICENSE.md | 30 + gen/datastore1_beta2-cli/README.md | 4 + gen/datastore1_beta2-cli/mkdocs.yml | 22 + gen/datastore1_beta2-cli/src/cmn.rs | 439 + gen/datastore1_beta2-cli/src/main.rs | 653 + gen/deploymentmanager2_beta1-cli/Cargo.toml | 30 + gen/deploymentmanager2_beta1-cli/LICENSE.md | 30 + gen/deploymentmanager2_beta1-cli/README.md | 4 + gen/deploymentmanager2_beta1-cli/mkdocs.yml | 27 + gen/deploymentmanager2_beta1-cli/src/cmn.rs | 439 + gen/deploymentmanager2_beta1-cli/src/main.rs | 717 + gen/dfareporting2-cli/Cargo.toml | 30 + gen/dfareporting2-cli/LICENSE.md | 30 + gen/dfareporting2-cli/README.md | 4 + gen/dfareporting2-cli/mkdocs.yml | 183 + gen/dfareporting2-cli/src/cmn.rs | 439 + gen/dfareporting2-cli/src/main.rs | 19555 ++++++++++++++++ gen/discovery1-cli/Cargo.toml | 30 + gen/discovery1-cli/LICENSE.md | 30 + gen/discovery1-cli/README.md | 4 + gen/discovery1-cli/mkdocs.yml | 18 + gen/discovery1-cli/src/cmn.rs | 439 + gen/discovery1-cli/src/main.rs | 222 + gen/dns1_beta1-cli/Cargo.toml | 30 + gen/dns1_beta1-cli/LICENSE.md | 30 + gen/dns1_beta1-cli/README.md | 4 + gen/dns1_beta1-cli/mkdocs.yml | 25 + gen/dns1_beta1-cli/src/cmn.rs | 439 + gen/dns1_beta1-cli/src/main.rs | 654 + gen/doubleclickbidmanager1-cli/Cargo.toml | 30 + gen/doubleclickbidmanager1-cli/LICENSE.md | 30 + gen/doubleclickbidmanager1-cli/README.md | 4 + gen/doubleclickbidmanager1-cli/mkdocs.yml | 24 + gen/doubleclickbidmanager1-cli/src/cmn.rs | 439 + gen/doubleclickbidmanager1-cli/src/main.rs | 700 + gen/doubleclicksearch2-cli/Cargo.toml | 30 + gen/doubleclicksearch2-cli/LICENSE.md | 30 + gen/doubleclicksearch2-cli/README.md | 4 + gen/doubleclicksearch2-cli/mkdocs.yml | 26 + gen/doubleclicksearch2-cli/src/cmn.rs | 439 + gen/doubleclicksearch2-cli/src/main.rs | 903 + gen/drive2-cli/Cargo.toml | 30 + gen/drive2-cli/LICENSE.md | 30 + gen/drive2-cli/README.md | 4 + gen/drive2-cli/mkdocs.yml | 75 + gen/drive2-cli/src/cmn.rs | 439 + gen/drive2-cli/src/main.rs | 6319 +++++ gen/fitness1-cli/Cargo.toml | 30 + gen/fitness1-cli/LICENSE.md | 30 + gen/fitness1-cli/README.md | 4 + gen/fitness1-cli/mkdocs.yml | 27 + gen/fitness1-cli/src/cmn.rs | 439 + gen/fitness1-cli/src/main.rs | 1014 + gen/freebase1-cli/Cargo.toml | 30 + gen/freebase1-cli/LICENSE.md | 30 + gen/freebase1-cli/README.md | 4 + gen/freebase1-cli/mkdocs.yml | 18 + gen/freebase1-cli/src/cmn.rs | 439 + gen/freebase1-cli/src/main.rs | 310 + gen/freebase1_sandbox-cli/Cargo.toml | 30 + gen/freebase1_sandbox-cli/LICENSE.md | 30 + gen/freebase1_sandbox-cli/README.md | 4 + gen/freebase1_sandbox-cli/mkdocs.yml | 18 + gen/freebase1_sandbox-cli/src/cmn.rs | 439 + gen/freebase1_sandbox-cli/src/main.rs | 310 + gen/fusiontables2-cli/Cargo.toml | 30 + gen/fusiontables2-cli/LICENSE.md | 30 + gen/fusiontables2-cli/README.md | 4 + gen/fusiontables2-cli/mkdocs.yml | 49 + gen/fusiontables2-cli/src/cmn.rs | 439 + gen/fusiontables2-cli/src/main.rs | 2836 +++ gen/games1-cli/Cargo.toml | 30 + gen/games1-cli/LICENSE.md | 30 + gen/games1-cli/README.md | 4 + gen/games1-cli/mkdocs.yml | 68 + gen/games1-cli/src/cmn.rs | 439 + gen/games1-cli/src/main.rs | 3366 +++ gen/games1/src/cmn.rs | 46 +- .../Cargo.toml | 30 + .../LICENSE.md | 30 + .../README.md | 4 + .../mkdocs.yml | 29 + .../src/cmn.rs | 439 + .../src/main.rs | 1483 ++ .../Cargo.toml | 30 + .../LICENSE.md | 30 + gen/gamesmanagement1_management-cli/README.md | 4 + .../mkdocs.yml | 43 + .../src/cmn.rs | 439 + .../src/main.rs | 1473 ++ gen/gan1_beta1-cli/Cargo.toml | 30 + gen/gan1_beta1-cli/LICENSE.md | 30 + gen/gan1_beta1-cli/README.md | 4 + gen/gan1_beta1-cli/mkdocs.yml | 26 + gen/gan1_beta1-cli/src/cmn.rs | 439 + gen/gan1_beta1-cli/src/main.rs | 947 + gen/genomics1_beta2-cli/Cargo.toml | 30 + gen/genomics1_beta2-cli/LICENSE.md | 30 + gen/genomics1_beta2-cli/README.md | 4 + gen/genomics1_beta2-cli/mkdocs.yml | 76 + gen/genomics1_beta2-cli/src/cmn.rs | 439 + gen/genomics1_beta2-cli/src/main.rs | 4467 ++++ gen/gmail1-cli/Cargo.toml | 30 + gen/gmail1-cli/LICENSE.md | 30 + gen/gmail1-cli/README.md | 4 + gen/gmail1-cli/mkdocs.yml | 46 + gen/gmail1-cli/src/cmn.rs | 439 + gen/gmail1-cli/src/main.rs | 2313 ++ gen/groupsmigration1-cli/Cargo.toml | 6 +- gen/groupsmigration1-cli/README.md | 5 +- gen/groupsmigration1-cli/src/cmn.rs | 437 + gen/groupsmigration1-cli/src/main.rs | 176 +- gen/groupsmigration1/README.md | 20 +- gen/groupsmigration1/src/cmn.rs | 46 +- gen/groupsmigration1/src/lib.rs | 55 +- gen/groupssettings1-cli/Cargo.toml | 30 + gen/groupssettings1-cli/LICENSE.md | 30 + gen/groupssettings1-cli/README.md | 4 + gen/groupssettings1-cli/mkdocs.yml | 19 + gen/groupssettings1-cli/src/cmn.rs | 439 + gen/groupssettings1-cli/src/main.rs | 461 + gen/identitytoolkit3-cli/Cargo.toml | 30 + gen/identitytoolkit3-cli/LICENSE.md | 30 + gen/identitytoolkit3-cli/README.md | 4 + gen/identitytoolkit3-cli/mkdocs.yml | 27 + gen/identitytoolkit3-cli/src/cmn.rs | 439 + gen/identitytoolkit3-cli/src/main.rs | 928 + gen/licensing1-cli/Cargo.toml | 30 + gen/licensing1-cli/LICENSE.md | 30 + gen/licensing1-cli/README.md | 4 + gen/licensing1-cli/mkdocs.yml | 23 + gen/licensing1-cli/src/cmn.rs | 439 + gen/licensing1-cli/src/main.rs | 543 + gen/logging1_beta3-cli/Cargo.toml | 29 + gen/logging1_beta3-cli/LICENSE.md | 30 + gen/logging1_beta3-cli/README.md | 4 + gen/logging1_beta3-cli/mkdocs.yml | 31 + gen/logging1_beta3-cli/src/cmn.rs | 439 + gen/logging1_beta3-cli/src/main.rs | 1052 + gen/manager1_beta2-cli/Cargo.toml | 30 + gen/manager1_beta2-cli/LICENSE.md | 30 + gen/manager1_beta2-cli/README.md | 4 + gen/manager1_beta2-cli/mkdocs.yml | 24 + gen/manager1_beta2-cli/src/cmn.rs | 439 + gen/manager1_beta2-cli/src/main.rs | 576 + gen/mapsengine1-cli/Cargo.toml | 30 + gen/mapsengine1-cli/LICENSE.md | 30 + gen/mapsengine1-cli/README.md | 4 + gen/mapsengine1-cli/mkdocs.yml | 93 + gen/mapsengine1-cli/src/cmn.rs | 439 + gen/mapsengine1-cli/src/main.rs | 5347 +++++ gen/mapsengine1/README.md | 20 +- gen/mapsengine1/src/cmn.rs | 46 +- gen/mapsengine1/src/lib.rs | 1710 +- gen/mirror1-cli/Cargo.toml | 30 + gen/mirror1-cli/LICENSE.md | 30 + gen/mirror1-cli/README.md | 4 + gen/mirror1-cli/mkdocs.yml | 40 + gen/mirror1-cli/src/cmn.rs | 439 + gen/mirror1-cli/src/main.rs | 2267 ++ gen/oauth2_v2-cli/Cargo.toml | 30 + gen/oauth2_v2-cli/LICENSE.md | 30 + gen/oauth2_v2-cli/README.md | 4 + gen/oauth2_v2-cli/mkdocs.yml | 20 + gen/oauth2_v2-cli/src/cmn.rs | 439 + gen/oauth2_v2-cli/src/main.rs | 327 + gen/pagespeedonline2-cli/Cargo.toml | 30 + gen/pagespeedonline2-cli/LICENSE.md | 30 + gen/pagespeedonline2-cli/README.md | 4 + gen/pagespeedonline2-cli/mkdocs.yml | 17 + gen/pagespeedonline2-cli/src/cmn.rs | 439 + gen/pagespeedonline2-cli/src/main.rs | 184 + gen/plus1-cli/Cargo.toml | 30 + gen/plus1-cli/LICENSE.md | 30 + gen/plus1-cli/README.md | 4 + gen/plus1-cli/mkdocs.yml | 28 + gen/plus1-cli/src/cmn.rs | 439 + gen/plus1-cli/src/main.rs | 1291 + gen/plusdomains1-cli/Cargo.toml | 30 + gen/plusdomains1-cli/LICENSE.md | 30 + gen/plusdomains1-cli/README.md | 4 + gen/plusdomains1-cli/mkdocs.yml | 36 + gen/plusdomains1-cli/src/cmn.rs | 439 + gen/plusdomains1-cli/src/main.rs | 1725 ++ gen/prediction1d6-cli/Cargo.toml | 30 + gen/prediction1d6-cli/LICENSE.md | 30 + gen/prediction1d6-cli/README.md | 4 + gen/prediction1d6-cli/mkdocs.yml | 24 + gen/prediction1d6-cli/src/cmn.rs | 439 + gen/prediction1d6-cli/src/main.rs | 583 + gen/pubsub1_beta2-cli/Cargo.toml | 29 + gen/pubsub1_beta2-cli/LICENSE.md | 30 + gen/pubsub1_beta2-cli/README.md | 4 + gen/pubsub1_beta2-cli/mkdocs.yml | 30 + gen/pubsub1_beta2-cli/src/cmn.rs | 439 + gen/pubsub1_beta2-cli/src/main.rs | 952 + gen/qpxexpress1-cli/Cargo.toml | 30 + gen/qpxexpress1-cli/LICENSE.md | 30 + gen/qpxexpress1-cli/README.md | 4 + gen/qpxexpress1-cli/mkdocs.yml | 17 + gen/qpxexpress1-cli/src/cmn.rs | 439 + gen/qpxexpress1-cli/src/main.rs | 228 + gen/replicapool1_beta2-cli/Cargo.toml | 30 + gen/replicapool1_beta2-cli/LICENSE.md | 30 + gen/replicapool1_beta2-cli/README.md | 4 + gen/replicapool1_beta2-cli/mkdocs.yml | 28 + gen/replicapool1_beta2-cli/src/cmn.rs | 439 + gen/replicapool1_beta2-cli/src/main.rs | 864 + gen/replicapoolupdater1_beta1-cli/Cargo.toml | 30 + gen/replicapoolupdater1_beta1-cli/LICENSE.md | 30 + gen/replicapoolupdater1_beta1-cli/README.md | 4 + gen/replicapoolupdater1_beta1-cli/mkdocs.yml | 25 + gen/replicapoolupdater1_beta1-cli/src/cmn.rs | 439 + gen/replicapoolupdater1_beta1-cli/src/main.rs | 666 + gen/reseller1_sandbox-cli/Cargo.toml | 30 + gen/reseller1_sandbox-cli/LICENSE.md | 30 + gen/reseller1_sandbox-cli/README.md | 4 + gen/reseller1_sandbox-cli/mkdocs.yml | 30 + gen/reseller1_sandbox-cli/src/cmn.rs | 439 + gen/reseller1_sandbox-cli/src/main.rs | 1265 + gen/resourceviews1_beta2-cli/Cargo.toml | 30 + gen/resourceviews1_beta2-cli/LICENSE.md | 30 + gen/resourceviews1_beta2-cli/README.md | 4 + gen/resourceviews1_beta2-cli/mkdocs.yml | 27 + gen/resourceviews1_beta2-cli/src/cmn.rs | 439 + gen/resourceviews1_beta2-cli/src/main.rs | 783 + gen/siteverification1-cli/Cargo.toml | 30 + gen/siteverification1-cli/LICENSE.md | 30 + gen/siteverification1-cli/README.md | 4 + gen/siteverification1-cli/mkdocs.yml | 23 + gen/siteverification1-cli/src/cmn.rs | 439 + gen/siteverification1-cli/src/main.rs | 591 + gen/spectrum1_explorer-cli/Cargo.toml | 30 + gen/spectrum1_explorer-cli/LICENSE.md | 30 + gen/spectrum1_explorer-cli/README.md | 4 + gen/spectrum1_explorer-cli/mkdocs.yml | 22 + gen/spectrum1_explorer-cli/src/cmn.rs | 439 + gen/spectrum1_explorer-cli/src/main.rs | 1290 + gen/sqladmin1_beta4-cli/Cargo.toml | 30 + gen/sqladmin1_beta4-cli/LICENSE.md | 30 + gen/sqladmin1_beta4-cli/README.md | 4 + gen/sqladmin1_beta4-cli/mkdocs.yml | 51 + gen/sqladmin1_beta4-cli/src/cmn.rs | 439 + gen/sqladmin1_beta4-cli/src/main.rs | 2956 +++ gen/storage1-cli/Cargo.toml | 30 + gen/storage1-cli/LICENSE.md | 30 + gen/storage1-cli/README.md | 4 + gen/storage1-cli/mkdocs.yml | 50 + gen/storage1-cli/src/cmn.rs | 439 + gen/storage1-cli/src/main.rs | 3654 +++ gen/tagmanager1-cli/Cargo.toml | 30 + gen/tagmanager1-cli/LICENSE.md | 30 + gen/tagmanager1-cli/README.md | 4 + gen/tagmanager1-cli/mkdocs.yml | 62 + gen/tagmanager1-cli/src/cmn.rs | 439 + gen/tagmanager1-cli/src/main.rs | 3483 +++ gen/tagmanager1/src/cmn.rs | 46 +- gen/taskqueue1_beta2-cli/Cargo.toml | 30 + gen/taskqueue1_beta2-cli/LICENSE.md | 30 + gen/taskqueue1_beta2-cli/README.md | 4 + gen/taskqueue1_beta2-cli/mkdocs.yml | 24 + gen/taskqueue1_beta2-cli/src/cmn.rs | 439 + gen/taskqueue1_beta2-cli/src/main.rs | 628 + gen/tasks1-cli/Cargo.toml | 30 + gen/tasks1-cli/LICENSE.md | 30 + gen/tasks1-cli/README.md | 4 + gen/tasks1-cli/mkdocs.yml | 30 + gen/tasks1-cli/src/cmn.rs | 439 + gen/tasks1-cli/src/main.rs | 1088 + gen/translate2-cli/Cargo.toml | 30 + gen/translate2-cli/LICENSE.md | 30 + gen/translate2-cli/README.md | 4 + gen/translate2-cli/mkdocs.yml | 19 + gen/translate2-cli/src/cmn.rs | 439 + gen/translate2-cli/src/main.rs | 283 + gen/urlshortener1-cli/Cargo.toml | 30 + gen/urlshortener1-cli/LICENSE.md | 30 + gen/urlshortener1-cli/README.md | 4 + gen/urlshortener1-cli/mkdocs.yml | 19 + gen/urlshortener1-cli/src/cmn.rs | 439 + gen/urlshortener1-cli/src/main.rs | 352 + gen/webfonts1-cli/Cargo.toml | 30 + gen/webfonts1-cli/LICENSE.md | 30 + gen/webfonts1-cli/README.md | 4 + gen/webfonts1-cli/mkdocs.yml | 17 + gen/webfonts1-cli/src/cmn.rs | 439 + gen/webfonts1-cli/src/main.rs | 172 + gen/webmasters3-cli/Cargo.toml | 30 + gen/webmasters3-cli/LICENSE.md | 30 + gen/webmasters3-cli/README.md | 4 + gen/webmasters3-cli/mkdocs.yml | 28 + gen/webmasters3-cli/src/cmn.rs | 439 + gen/webmasters3-cli/src/main.rs | 704 + gen/youtube3-cli/Cargo.toml | 6 +- gen/youtube3-cli/README.md | 4 + gen/youtube3-cli/mkdocs.yml | 66 + gen/youtube3-cli/src/cmn.rs | 437 + gen/youtube3-cli/src/main.rs | 7197 +++++- gen/youtubeanalytics1-cli/Cargo.toml | 30 + gen/youtubeanalytics1-cli/LICENSE.md | 30 + gen/youtubeanalytics1-cli/README.md | 4 + gen/youtubeanalytics1-cli/mkdocs.yml | 26 + gen/youtubeanalytics1-cli/src/cmn.rs | 439 + gen/youtubeanalytics1-cli/src/main.rs | 800 + 476 files changed, 190441 insertions(+), 1038 deletions(-) create mode 100644 gen/adexchangebuyer1d3-cli/Cargo.toml create mode 100644 gen/adexchangebuyer1d3-cli/LICENSE.md create mode 100644 gen/adexchangebuyer1d3-cli/README.md create mode 100644 gen/adexchangebuyer1d3-cli/mkdocs.yml create mode 100644 gen/adexchangebuyer1d3-cli/src/cmn.rs create mode 100644 gen/adexchangebuyer1d3-cli/src/main.rs create mode 100644 gen/adexchangeseller2-cli/Cargo.toml create mode 100644 gen/adexchangeseller2-cli/LICENSE.md create mode 100644 gen/adexchangeseller2-cli/README.md create mode 100644 gen/adexchangeseller2-cli/mkdocs.yml create mode 100644 gen/adexchangeseller2-cli/src/cmn.rs create mode 100644 gen/adexchangeseller2-cli/src/main.rs create mode 100644 gen/admin1_directory-cli/Cargo.toml create mode 100644 gen/admin1_directory-cli/LICENSE.md create mode 100644 gen/admin1_directory-cli/README.md create mode 100644 gen/admin1_directory-cli/mkdocs.yml create mode 100644 gen/admin1_directory-cli/src/cmn.rs create mode 100644 gen/admin1_directory-cli/src/main.rs create mode 100644 gen/admin1_reports-cli/Cargo.toml create mode 100644 gen/admin1_reports-cli/LICENSE.md create mode 100644 gen/admin1_reports-cli/README.md create mode 100644 gen/admin1_reports-cli/mkdocs.yml create mode 100644 gen/admin1_reports-cli/src/cmn.rs create mode 100644 gen/admin1_reports-cli/src/main.rs create mode 100644 gen/admin2_email_migration-cli/Cargo.toml create mode 100644 gen/admin2_email_migration-cli/LICENSE.md create mode 100644 gen/admin2_email_migration-cli/README.md create mode 100644 gen/admin2_email_migration-cli/mkdocs.yml create mode 100644 gen/admin2_email_migration-cli/src/cmn.rs create mode 100644 gen/admin2_email_migration-cli/src/main.rs create mode 100644 gen/adsense1d4-cli/Cargo.toml create mode 100644 gen/adsense1d4-cli/LICENSE.md create mode 100644 gen/adsense1d4-cli/README.md create mode 100644 gen/adsense1d4-cli/mkdocs.yml create mode 100644 gen/adsense1d4-cli/src/cmn.rs create mode 100644 gen/adsense1d4-cli/src/main.rs create mode 100644 gen/adsensehost4d1-cli/Cargo.toml create mode 100644 gen/adsensehost4d1-cli/LICENSE.md create mode 100644 gen/adsensehost4d1-cli/README.md create mode 100644 gen/adsensehost4d1-cli/mkdocs.yml create mode 100644 gen/adsensehost4d1-cli/src/cmn.rs create mode 100644 gen/adsensehost4d1-cli/src/main.rs create mode 100644 gen/analytics3-cli/Cargo.toml create mode 100644 gen/analytics3-cli/LICENSE.md create mode 100644 gen/analytics3-cli/README.md create mode 100644 gen/analytics3-cli/mkdocs.yml create mode 100644 gen/analytics3-cli/src/cmn.rs create mode 100644 gen/analytics3-cli/src/main.rs create mode 100644 gen/androidenterprise1-cli/Cargo.toml create mode 100644 gen/androidenterprise1-cli/LICENSE.md create mode 100644 gen/androidenterprise1-cli/README.md create mode 100644 gen/androidenterprise1-cli/mkdocs.yml create mode 100644 gen/androidenterprise1-cli/src/cmn.rs create mode 100644 gen/androidenterprise1-cli/src/main.rs create mode 100644 gen/androidpublisher2-cli/Cargo.toml create mode 100644 gen/androidpublisher2-cli/LICENSE.md create mode 100644 gen/androidpublisher2-cli/README.md create mode 100644 gen/androidpublisher2-cli/mkdocs.yml create mode 100644 gen/androidpublisher2-cli/src/cmn.rs create mode 100644 gen/androidpublisher2-cli/src/main.rs create mode 100644 gen/appsactivity1-cli/Cargo.toml create mode 100644 gen/appsactivity1-cli/LICENSE.md create mode 100644 gen/appsactivity1-cli/README.md create mode 100644 gen/appsactivity1-cli/mkdocs.yml create mode 100644 gen/appsactivity1-cli/src/cmn.rs create mode 100644 gen/appsactivity1-cli/src/main.rs create mode 100644 gen/appstate1-cli/Cargo.toml create mode 100644 gen/appstate1-cli/LICENSE.md create mode 100644 gen/appstate1-cli/README.md create mode 100644 gen/appstate1-cli/mkdocs.yml create mode 100644 gen/appstate1-cli/src/cmn.rs create mode 100644 gen/appstate1-cli/src/main.rs create mode 100644 gen/audit1-cli/Cargo.toml create mode 100644 gen/audit1-cli/LICENSE.md create mode 100644 gen/audit1-cli/README.md create mode 100644 gen/audit1-cli/mkdocs.yml create mode 100644 gen/audit1-cli/src/cmn.rs create mode 100644 gen/audit1-cli/src/main.rs create mode 100644 gen/autoscaler1_beta2-cli/Cargo.toml create mode 100644 gen/autoscaler1_beta2-cli/LICENSE.md create mode 100644 gen/autoscaler1_beta2-cli/README.md create mode 100644 gen/autoscaler1_beta2-cli/mkdocs.yml create mode 100644 gen/autoscaler1_beta2-cli/src/cmn.rs create mode 100644 gen/autoscaler1_beta2-cli/src/main.rs create mode 100644 gen/bigquery2-cli/Cargo.toml create mode 100644 gen/bigquery2-cli/LICENSE.md create mode 100644 gen/bigquery2-cli/README.md create mode 100644 gen/bigquery2-cli/mkdocs.yml create mode 100644 gen/bigquery2-cli/src/cmn.rs create mode 100644 gen/bigquery2-cli/src/main.rs create mode 100644 gen/blogger3-cli/Cargo.toml create mode 100644 gen/blogger3-cli/LICENSE.md create mode 100644 gen/blogger3-cli/README.md create mode 100644 gen/blogger3-cli/mkdocs.yml create mode 100644 gen/blogger3-cli/src/cmn.rs create mode 100644 gen/blogger3-cli/src/main.rs create mode 100644 gen/books1-cli/Cargo.toml create mode 100644 gen/books1-cli/LICENSE.md create mode 100644 gen/books1-cli/README.md create mode 100644 gen/books1-cli/mkdocs.yml create mode 100644 gen/books1-cli/src/cmn.rs create mode 100644 gen/books1-cli/src/main.rs create mode 100644 gen/calendar3-cli/Cargo.toml create mode 100644 gen/calendar3-cli/LICENSE.md create mode 100644 gen/calendar3-cli/README.md create mode 100644 gen/calendar3-cli/mkdocs.yml create mode 100644 gen/calendar3-cli/src/cmn.rs create mode 100644 gen/calendar3-cli/src/main.rs create mode 100644 gen/civicinfo2-cli/Cargo.toml create mode 100644 gen/civicinfo2-cli/LICENSE.md create mode 100644 gen/civicinfo2-cli/README.md create mode 100644 gen/civicinfo2-cli/mkdocs.yml create mode 100644 gen/civicinfo2-cli/src/cmn.rs create mode 100644 gen/civicinfo2-cli/src/main.rs create mode 100644 gen/cloudlatencytest2-cli/Cargo.toml create mode 100644 gen/cloudlatencytest2-cli/LICENSE.md create mode 100644 gen/cloudlatencytest2-cli/README.md create mode 100644 gen/cloudlatencytest2-cli/mkdocs.yml create mode 100644 gen/cloudlatencytest2-cli/src/cmn.rs create mode 100644 gen/cloudlatencytest2-cli/src/main.rs create mode 100644 gen/cloudmonitoring2_beta2-cli/Cargo.toml create mode 100644 gen/cloudmonitoring2_beta2-cli/LICENSE.md create mode 100644 gen/cloudmonitoring2_beta2-cli/README.md create mode 100644 gen/cloudmonitoring2_beta2-cli/mkdocs.yml create mode 100644 gen/cloudmonitoring2_beta2-cli/src/cmn.rs create mode 100644 gen/cloudmonitoring2_beta2-cli/src/main.rs create mode 100644 gen/cloudsearch1-cli/Cargo.toml create mode 100644 gen/cloudsearch1-cli/LICENSE.md create mode 100644 gen/cloudsearch1-cli/README.md create mode 100644 gen/cloudsearch1-cli/mkdocs.yml create mode 100644 gen/cloudsearch1-cli/src/cmn.rs create mode 100644 gen/cloudsearch1-cli/src/main.rs create mode 100644 gen/compute1-cli/Cargo.toml create mode 100644 gen/compute1-cli/LICENSE.md create mode 100644 gen/compute1-cli/README.md create mode 100644 gen/compute1-cli/mkdocs.yml create mode 100644 gen/compute1-cli/src/cmn.rs create mode 100644 gen/compute1-cli/src/main.rs create mode 100644 gen/container1_beta1-cli/Cargo.toml create mode 100644 gen/container1_beta1-cli/LICENSE.md create mode 100644 gen/container1_beta1-cli/README.md create mode 100644 gen/container1_beta1-cli/mkdocs.yml create mode 100644 gen/container1_beta1-cli/src/cmn.rs create mode 100644 gen/container1_beta1-cli/src/main.rs create mode 100644 gen/content2-cli/Cargo.toml create mode 100644 gen/content2-cli/LICENSE.md create mode 100644 gen/content2-cli/README.md create mode 100644 gen/content2-cli/mkdocs.yml create mode 100644 gen/content2-cli/src/cmn.rs create mode 100644 gen/content2-cli/src/main.rs create mode 100644 gen/coordinate1-cli/Cargo.toml create mode 100644 gen/coordinate1-cli/LICENSE.md create mode 100644 gen/coordinate1-cli/README.md create mode 100644 gen/coordinate1-cli/mkdocs.yml create mode 100644 gen/coordinate1-cli/src/cmn.rs create mode 100644 gen/coordinate1-cli/src/main.rs create mode 100644 gen/customsearch1-cli/Cargo.toml create mode 100644 gen/customsearch1-cli/LICENSE.md create mode 100644 gen/customsearch1-cli/README.md create mode 100644 gen/customsearch1-cli/mkdocs.yml create mode 100644 gen/customsearch1-cli/src/cmn.rs create mode 100644 gen/customsearch1-cli/src/main.rs create mode 100644 gen/dataflow1_b4-cli/Cargo.toml create mode 100644 gen/dataflow1_b4-cli/LICENSE.md create mode 100644 gen/dataflow1_b4-cli/README.md create mode 100644 gen/dataflow1_b4-cli/mkdocs.yml create mode 100644 gen/dataflow1_b4-cli/src/cmn.rs create mode 100644 gen/dataflow1_b4-cli/src/main.rs create mode 100644 gen/datastore1_beta2-cli/Cargo.toml create mode 100644 gen/datastore1_beta2-cli/LICENSE.md create mode 100644 gen/datastore1_beta2-cli/README.md create mode 100644 gen/datastore1_beta2-cli/mkdocs.yml create mode 100644 gen/datastore1_beta2-cli/src/cmn.rs create mode 100644 gen/datastore1_beta2-cli/src/main.rs create mode 100644 gen/deploymentmanager2_beta1-cli/Cargo.toml create mode 100644 gen/deploymentmanager2_beta1-cli/LICENSE.md create mode 100644 gen/deploymentmanager2_beta1-cli/README.md create mode 100644 gen/deploymentmanager2_beta1-cli/mkdocs.yml create mode 100644 gen/deploymentmanager2_beta1-cli/src/cmn.rs create mode 100644 gen/deploymentmanager2_beta1-cli/src/main.rs create mode 100644 gen/dfareporting2-cli/Cargo.toml create mode 100644 gen/dfareporting2-cli/LICENSE.md create mode 100644 gen/dfareporting2-cli/README.md create mode 100644 gen/dfareporting2-cli/mkdocs.yml create mode 100644 gen/dfareporting2-cli/src/cmn.rs create mode 100644 gen/dfareporting2-cli/src/main.rs create mode 100644 gen/discovery1-cli/Cargo.toml create mode 100644 gen/discovery1-cli/LICENSE.md create mode 100644 gen/discovery1-cli/README.md create mode 100644 gen/discovery1-cli/mkdocs.yml create mode 100644 gen/discovery1-cli/src/cmn.rs create mode 100644 gen/discovery1-cli/src/main.rs create mode 100644 gen/dns1_beta1-cli/Cargo.toml create mode 100644 gen/dns1_beta1-cli/LICENSE.md create mode 100644 gen/dns1_beta1-cli/README.md create mode 100644 gen/dns1_beta1-cli/mkdocs.yml create mode 100644 gen/dns1_beta1-cli/src/cmn.rs create mode 100644 gen/dns1_beta1-cli/src/main.rs create mode 100644 gen/doubleclickbidmanager1-cli/Cargo.toml create mode 100644 gen/doubleclickbidmanager1-cli/LICENSE.md create mode 100644 gen/doubleclickbidmanager1-cli/README.md create mode 100644 gen/doubleclickbidmanager1-cli/mkdocs.yml create mode 100644 gen/doubleclickbidmanager1-cli/src/cmn.rs create mode 100644 gen/doubleclickbidmanager1-cli/src/main.rs create mode 100644 gen/doubleclicksearch2-cli/Cargo.toml create mode 100644 gen/doubleclicksearch2-cli/LICENSE.md create mode 100644 gen/doubleclicksearch2-cli/README.md create mode 100644 gen/doubleclicksearch2-cli/mkdocs.yml create mode 100644 gen/doubleclicksearch2-cli/src/cmn.rs create mode 100644 gen/doubleclicksearch2-cli/src/main.rs create mode 100644 gen/drive2-cli/Cargo.toml create mode 100644 gen/drive2-cli/LICENSE.md create mode 100644 gen/drive2-cli/README.md create mode 100644 gen/drive2-cli/mkdocs.yml create mode 100644 gen/drive2-cli/src/cmn.rs create mode 100644 gen/drive2-cli/src/main.rs create mode 100644 gen/fitness1-cli/Cargo.toml create mode 100644 gen/fitness1-cli/LICENSE.md create mode 100644 gen/fitness1-cli/README.md create mode 100644 gen/fitness1-cli/mkdocs.yml create mode 100644 gen/fitness1-cli/src/cmn.rs create mode 100644 gen/fitness1-cli/src/main.rs create mode 100644 gen/freebase1-cli/Cargo.toml create mode 100644 gen/freebase1-cli/LICENSE.md create mode 100644 gen/freebase1-cli/README.md create mode 100644 gen/freebase1-cli/mkdocs.yml create mode 100644 gen/freebase1-cli/src/cmn.rs create mode 100644 gen/freebase1-cli/src/main.rs create mode 100644 gen/freebase1_sandbox-cli/Cargo.toml create mode 100644 gen/freebase1_sandbox-cli/LICENSE.md create mode 100644 gen/freebase1_sandbox-cli/README.md create mode 100644 gen/freebase1_sandbox-cli/mkdocs.yml create mode 100644 gen/freebase1_sandbox-cli/src/cmn.rs create mode 100644 gen/freebase1_sandbox-cli/src/main.rs create mode 100644 gen/fusiontables2-cli/Cargo.toml create mode 100644 gen/fusiontables2-cli/LICENSE.md create mode 100644 gen/fusiontables2-cli/README.md create mode 100644 gen/fusiontables2-cli/mkdocs.yml create mode 100644 gen/fusiontables2-cli/src/cmn.rs create mode 100644 gen/fusiontables2-cli/src/main.rs create mode 100644 gen/games1-cli/Cargo.toml create mode 100644 gen/games1-cli/LICENSE.md create mode 100644 gen/games1-cli/README.md create mode 100644 gen/games1-cli/mkdocs.yml create mode 100644 gen/games1-cli/src/cmn.rs create mode 100644 gen/games1-cli/src/main.rs create mode 100644 gen/gamesconfiguration1_configuration-cli/Cargo.toml create mode 100644 gen/gamesconfiguration1_configuration-cli/LICENSE.md create mode 100644 gen/gamesconfiguration1_configuration-cli/README.md create mode 100644 gen/gamesconfiguration1_configuration-cli/mkdocs.yml create mode 100644 gen/gamesconfiguration1_configuration-cli/src/cmn.rs create mode 100644 gen/gamesconfiguration1_configuration-cli/src/main.rs create mode 100644 gen/gamesmanagement1_management-cli/Cargo.toml create mode 100644 gen/gamesmanagement1_management-cli/LICENSE.md create mode 100644 gen/gamesmanagement1_management-cli/README.md create mode 100644 gen/gamesmanagement1_management-cli/mkdocs.yml create mode 100644 gen/gamesmanagement1_management-cli/src/cmn.rs create mode 100644 gen/gamesmanagement1_management-cli/src/main.rs create mode 100644 gen/gan1_beta1-cli/Cargo.toml create mode 100644 gen/gan1_beta1-cli/LICENSE.md create mode 100644 gen/gan1_beta1-cli/README.md create mode 100644 gen/gan1_beta1-cli/mkdocs.yml create mode 100644 gen/gan1_beta1-cli/src/cmn.rs create mode 100644 gen/gan1_beta1-cli/src/main.rs create mode 100644 gen/genomics1_beta2-cli/Cargo.toml create mode 100644 gen/genomics1_beta2-cli/LICENSE.md create mode 100644 gen/genomics1_beta2-cli/README.md create mode 100644 gen/genomics1_beta2-cli/mkdocs.yml create mode 100644 gen/genomics1_beta2-cli/src/cmn.rs create mode 100644 gen/genomics1_beta2-cli/src/main.rs create mode 100644 gen/gmail1-cli/Cargo.toml create mode 100644 gen/gmail1-cli/LICENSE.md create mode 100644 gen/gmail1-cli/README.md create mode 100644 gen/gmail1-cli/mkdocs.yml create mode 100644 gen/gmail1-cli/src/cmn.rs create mode 100644 gen/gmail1-cli/src/main.rs create mode 100644 gen/groupssettings1-cli/Cargo.toml create mode 100644 gen/groupssettings1-cli/LICENSE.md create mode 100644 gen/groupssettings1-cli/README.md create mode 100644 gen/groupssettings1-cli/mkdocs.yml create mode 100644 gen/groupssettings1-cli/src/cmn.rs create mode 100644 gen/groupssettings1-cli/src/main.rs create mode 100644 gen/identitytoolkit3-cli/Cargo.toml create mode 100644 gen/identitytoolkit3-cli/LICENSE.md create mode 100644 gen/identitytoolkit3-cli/README.md create mode 100644 gen/identitytoolkit3-cli/mkdocs.yml create mode 100644 gen/identitytoolkit3-cli/src/cmn.rs create mode 100644 gen/identitytoolkit3-cli/src/main.rs create mode 100644 gen/licensing1-cli/Cargo.toml create mode 100644 gen/licensing1-cli/LICENSE.md create mode 100644 gen/licensing1-cli/README.md create mode 100644 gen/licensing1-cli/mkdocs.yml create mode 100644 gen/licensing1-cli/src/cmn.rs create mode 100644 gen/licensing1-cli/src/main.rs create mode 100644 gen/logging1_beta3-cli/Cargo.toml create mode 100644 gen/logging1_beta3-cli/LICENSE.md create mode 100644 gen/logging1_beta3-cli/README.md create mode 100644 gen/logging1_beta3-cli/mkdocs.yml create mode 100644 gen/logging1_beta3-cli/src/cmn.rs create mode 100644 gen/logging1_beta3-cli/src/main.rs create mode 100644 gen/manager1_beta2-cli/Cargo.toml create mode 100644 gen/manager1_beta2-cli/LICENSE.md create mode 100644 gen/manager1_beta2-cli/README.md create mode 100644 gen/manager1_beta2-cli/mkdocs.yml create mode 100644 gen/manager1_beta2-cli/src/cmn.rs create mode 100644 gen/manager1_beta2-cli/src/main.rs create mode 100644 gen/mapsengine1-cli/Cargo.toml create mode 100644 gen/mapsengine1-cli/LICENSE.md create mode 100644 gen/mapsengine1-cli/README.md create mode 100644 gen/mapsengine1-cli/mkdocs.yml create mode 100644 gen/mapsengine1-cli/src/cmn.rs create mode 100644 gen/mapsengine1-cli/src/main.rs create mode 100644 gen/mirror1-cli/Cargo.toml create mode 100644 gen/mirror1-cli/LICENSE.md create mode 100644 gen/mirror1-cli/README.md create mode 100644 gen/mirror1-cli/mkdocs.yml create mode 100644 gen/mirror1-cli/src/cmn.rs create mode 100644 gen/mirror1-cli/src/main.rs create mode 100644 gen/oauth2_v2-cli/Cargo.toml create mode 100644 gen/oauth2_v2-cli/LICENSE.md create mode 100644 gen/oauth2_v2-cli/README.md create mode 100644 gen/oauth2_v2-cli/mkdocs.yml create mode 100644 gen/oauth2_v2-cli/src/cmn.rs create mode 100644 gen/oauth2_v2-cli/src/main.rs create mode 100644 gen/pagespeedonline2-cli/Cargo.toml create mode 100644 gen/pagespeedonline2-cli/LICENSE.md create mode 100644 gen/pagespeedonline2-cli/README.md create mode 100644 gen/pagespeedonline2-cli/mkdocs.yml create mode 100644 gen/pagespeedonline2-cli/src/cmn.rs create mode 100644 gen/pagespeedonline2-cli/src/main.rs create mode 100644 gen/plus1-cli/Cargo.toml create mode 100644 gen/plus1-cli/LICENSE.md create mode 100644 gen/plus1-cli/README.md create mode 100644 gen/plus1-cli/mkdocs.yml create mode 100644 gen/plus1-cli/src/cmn.rs create mode 100644 gen/plus1-cli/src/main.rs create mode 100644 gen/plusdomains1-cli/Cargo.toml create mode 100644 gen/plusdomains1-cli/LICENSE.md create mode 100644 gen/plusdomains1-cli/README.md create mode 100644 gen/plusdomains1-cli/mkdocs.yml create mode 100644 gen/plusdomains1-cli/src/cmn.rs create mode 100644 gen/plusdomains1-cli/src/main.rs create mode 100644 gen/prediction1d6-cli/Cargo.toml create mode 100644 gen/prediction1d6-cli/LICENSE.md create mode 100644 gen/prediction1d6-cli/README.md create mode 100644 gen/prediction1d6-cli/mkdocs.yml create mode 100644 gen/prediction1d6-cli/src/cmn.rs create mode 100644 gen/prediction1d6-cli/src/main.rs create mode 100644 gen/pubsub1_beta2-cli/Cargo.toml create mode 100644 gen/pubsub1_beta2-cli/LICENSE.md create mode 100644 gen/pubsub1_beta2-cli/README.md create mode 100644 gen/pubsub1_beta2-cli/mkdocs.yml create mode 100644 gen/pubsub1_beta2-cli/src/cmn.rs create mode 100644 gen/pubsub1_beta2-cli/src/main.rs create mode 100644 gen/qpxexpress1-cli/Cargo.toml create mode 100644 gen/qpxexpress1-cli/LICENSE.md create mode 100644 gen/qpxexpress1-cli/README.md create mode 100644 gen/qpxexpress1-cli/mkdocs.yml create mode 100644 gen/qpxexpress1-cli/src/cmn.rs create mode 100644 gen/qpxexpress1-cli/src/main.rs create mode 100644 gen/replicapool1_beta2-cli/Cargo.toml create mode 100644 gen/replicapool1_beta2-cli/LICENSE.md create mode 100644 gen/replicapool1_beta2-cli/README.md create mode 100644 gen/replicapool1_beta2-cli/mkdocs.yml create mode 100644 gen/replicapool1_beta2-cli/src/cmn.rs create mode 100644 gen/replicapool1_beta2-cli/src/main.rs create mode 100644 gen/replicapoolupdater1_beta1-cli/Cargo.toml create mode 100644 gen/replicapoolupdater1_beta1-cli/LICENSE.md create mode 100644 gen/replicapoolupdater1_beta1-cli/README.md create mode 100644 gen/replicapoolupdater1_beta1-cli/mkdocs.yml create mode 100644 gen/replicapoolupdater1_beta1-cli/src/cmn.rs create mode 100644 gen/replicapoolupdater1_beta1-cli/src/main.rs create mode 100644 gen/reseller1_sandbox-cli/Cargo.toml create mode 100644 gen/reseller1_sandbox-cli/LICENSE.md create mode 100644 gen/reseller1_sandbox-cli/README.md create mode 100644 gen/reseller1_sandbox-cli/mkdocs.yml create mode 100644 gen/reseller1_sandbox-cli/src/cmn.rs create mode 100644 gen/reseller1_sandbox-cli/src/main.rs create mode 100644 gen/resourceviews1_beta2-cli/Cargo.toml create mode 100644 gen/resourceviews1_beta2-cli/LICENSE.md create mode 100644 gen/resourceviews1_beta2-cli/README.md create mode 100644 gen/resourceviews1_beta2-cli/mkdocs.yml create mode 100644 gen/resourceviews1_beta2-cli/src/cmn.rs create mode 100644 gen/resourceviews1_beta2-cli/src/main.rs create mode 100644 gen/siteverification1-cli/Cargo.toml create mode 100644 gen/siteverification1-cli/LICENSE.md create mode 100644 gen/siteverification1-cli/README.md create mode 100644 gen/siteverification1-cli/mkdocs.yml create mode 100644 gen/siteverification1-cli/src/cmn.rs create mode 100644 gen/siteverification1-cli/src/main.rs create mode 100644 gen/spectrum1_explorer-cli/Cargo.toml create mode 100644 gen/spectrum1_explorer-cli/LICENSE.md create mode 100644 gen/spectrum1_explorer-cli/README.md create mode 100644 gen/spectrum1_explorer-cli/mkdocs.yml create mode 100644 gen/spectrum1_explorer-cli/src/cmn.rs create mode 100644 gen/spectrum1_explorer-cli/src/main.rs create mode 100644 gen/sqladmin1_beta4-cli/Cargo.toml create mode 100644 gen/sqladmin1_beta4-cli/LICENSE.md create mode 100644 gen/sqladmin1_beta4-cli/README.md create mode 100644 gen/sqladmin1_beta4-cli/mkdocs.yml create mode 100644 gen/sqladmin1_beta4-cli/src/cmn.rs create mode 100644 gen/sqladmin1_beta4-cli/src/main.rs create mode 100644 gen/storage1-cli/Cargo.toml create mode 100644 gen/storage1-cli/LICENSE.md create mode 100644 gen/storage1-cli/README.md create mode 100644 gen/storage1-cli/mkdocs.yml create mode 100644 gen/storage1-cli/src/cmn.rs create mode 100644 gen/storage1-cli/src/main.rs create mode 100644 gen/tagmanager1-cli/Cargo.toml create mode 100644 gen/tagmanager1-cli/LICENSE.md create mode 100644 gen/tagmanager1-cli/README.md create mode 100644 gen/tagmanager1-cli/mkdocs.yml create mode 100644 gen/tagmanager1-cli/src/cmn.rs create mode 100644 gen/tagmanager1-cli/src/main.rs create mode 100644 gen/taskqueue1_beta2-cli/Cargo.toml create mode 100644 gen/taskqueue1_beta2-cli/LICENSE.md create mode 100644 gen/taskqueue1_beta2-cli/README.md create mode 100644 gen/taskqueue1_beta2-cli/mkdocs.yml create mode 100644 gen/taskqueue1_beta2-cli/src/cmn.rs create mode 100644 gen/taskqueue1_beta2-cli/src/main.rs create mode 100644 gen/tasks1-cli/Cargo.toml create mode 100644 gen/tasks1-cli/LICENSE.md create mode 100644 gen/tasks1-cli/README.md create mode 100644 gen/tasks1-cli/mkdocs.yml create mode 100644 gen/tasks1-cli/src/cmn.rs create mode 100644 gen/tasks1-cli/src/main.rs create mode 100644 gen/translate2-cli/Cargo.toml create mode 100644 gen/translate2-cli/LICENSE.md create mode 100644 gen/translate2-cli/README.md create mode 100644 gen/translate2-cli/mkdocs.yml create mode 100644 gen/translate2-cli/src/cmn.rs create mode 100644 gen/translate2-cli/src/main.rs create mode 100644 gen/urlshortener1-cli/Cargo.toml create mode 100644 gen/urlshortener1-cli/LICENSE.md create mode 100644 gen/urlshortener1-cli/README.md create mode 100644 gen/urlshortener1-cli/mkdocs.yml create mode 100644 gen/urlshortener1-cli/src/cmn.rs create mode 100644 gen/urlshortener1-cli/src/main.rs create mode 100644 gen/webfonts1-cli/Cargo.toml create mode 100644 gen/webfonts1-cli/LICENSE.md create mode 100644 gen/webfonts1-cli/README.md create mode 100644 gen/webfonts1-cli/mkdocs.yml create mode 100644 gen/webfonts1-cli/src/cmn.rs create mode 100644 gen/webfonts1-cli/src/main.rs create mode 100644 gen/webmasters3-cli/Cargo.toml create mode 100644 gen/webmasters3-cli/LICENSE.md create mode 100644 gen/webmasters3-cli/README.md create mode 100644 gen/webmasters3-cli/mkdocs.yml create mode 100644 gen/webmasters3-cli/src/cmn.rs create mode 100644 gen/webmasters3-cli/src/main.rs create mode 100644 gen/youtube3-cli/README.md create mode 100644 gen/youtube3-cli/mkdocs.yml create mode 100644 gen/youtubeanalytics1-cli/Cargo.toml create mode 100644 gen/youtubeanalytics1-cli/LICENSE.md create mode 100644 gen/youtubeanalytics1-cli/README.md create mode 100644 gen/youtubeanalytics1-cli/mkdocs.yml create mode 100644 gen/youtubeanalytics1-cli/src/cmn.rs create mode 100644 gen/youtubeanalytics1-cli/src/main.rs diff --git a/.gitignore b/.gitignore index e03dd740d9f..4bf80387e36 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .pyenv .virtualenv gen/doc/ -gen/*-cli/ *.go *.pyc **target/ diff --git a/gen/adexchangebuyer1d3-cli/Cargo.toml b/gen/adexchangebuyer1d3-cli/Cargo.toml new file mode 100644 index 00000000000..745f580f9e5 --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-adexchangebuyer1d3-cli" +version = "0.0.1+20150323" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Ad Exchange Buyer (protocol v1.3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/adexchangebuyer1d3-cli" +homepage = "https://developers.google.com/ad-exchange/buyer-rest" +documentation = "http://byron.github.io/google-apis-rs/google_adexchangebuyer1d3_cli" +license = "MIT" +keywords = ["adexchangebuyer", "google", "cli"] + +[[bin]] +name = "adexchangebuyer1d3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-adexchangebuyer1d3] +path = "../adexchangebuyer1d3" diff --git a/gen/adexchangebuyer1d3-cli/LICENSE.md b/gen/adexchangebuyer1d3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/adexchangebuyer1d3-cli/README.md b/gen/adexchangebuyer1d3-cli/README.md new file mode 100644 index 00000000000..863572e9538 --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADEXCHANGEBUYER:V1.3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/adexchangebuyer1d3-cli/mkdocs.yml b/gen/adexchangebuyer1d3-cli/mkdocs.yml new file mode 100644 index 00000000000..a7c8e97e51a --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/mkdocs.yml @@ -0,0 +1,37 @@ +site_name: Ad Exchange Buyer v0.0.1+20150323 +site_url: http://byron.github.io/google-apis-rs/google-adexchangebuyer1d3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/adexchangebuyer1d3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_patch.md', 'Accounts', 'Patch'] +- ['accounts_update.md', 'Accounts', 'Update'] +- ['billing-info_get.md', 'Billing Info', 'Get'] +- ['billing-info_list.md', 'Billing Info', 'List'] +- ['budget_get.md', 'Budget', 'Get'] +- ['budget_patch.md', 'Budget', 'Patch'] +- ['budget_update.md', 'Budget', 'Update'] +- ['creatives_get.md', 'Creatives', 'Get'] +- ['creatives_insert.md', 'Creatives', 'Insert'] +- ['creatives_list.md', 'Creatives', 'List'] +- ['direct-deals_get.md', 'Direct Deals', 'Get'] +- ['direct-deals_list.md', 'Direct Deals', 'List'] +- ['performance-report_list.md', 'Performance Report', 'List'] +- ['pretargeting-config_delete.md', 'Pretargeting Config', 'Delete'] +- ['pretargeting-config_get.md', 'Pretargeting Config', 'Get'] +- ['pretargeting-config_insert.md', 'Pretargeting Config', 'Insert'] +- ['pretargeting-config_list.md', 'Pretargeting Config', 'List'] +- ['pretargeting-config_patch.md', 'Pretargeting Config', 'Patch'] +- ['pretargeting-config_update.md', 'Pretargeting Config', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/adexchangebuyer1d3-cli/src/cmn.rs b/gen/adexchangebuyer1d3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/adexchangebuyer1d3-cli/src/main.rs b/gen/adexchangebuyer1d3-cli/src/main.rs new file mode 100644 index 00000000000..163d251dfb3 --- /dev/null +++ b/gen/adexchangebuyer1d3-cli/src/main.rs @@ -0,0 +1,1742 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_adexchangebuyer1d3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + adexchangebuyer1d3 [options] accounts get [-p ]... [-o ] + adexchangebuyer1d3 [options] accounts list [-p ]... [-o ] + adexchangebuyer1d3 [options] accounts patch -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] accounts update -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] billing-info get [-p ]... [-o ] + adexchangebuyer1d3 [options] billing-info list [-p ]... [-o ] + adexchangebuyer1d3 [options] budget get [-p ]... [-o ] + adexchangebuyer1d3 [options] budget patch -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] budget update -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] creatives get [-p ]... [-o ] + adexchangebuyer1d3 [options] creatives insert -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] creatives list [-p ]... [-o ] + adexchangebuyer1d3 [options] direct-deals get [-p ]... [-o ] + adexchangebuyer1d3 [options] direct-deals list [-p ]... [-o ] + adexchangebuyer1d3 [options] performance-report list [-p ]... [-o ] + adexchangebuyer1d3 [options] pretargeting-config delete [-p ]... + adexchangebuyer1d3 [options] pretargeting-config get [-p ]... [-o ] + adexchangebuyer1d3 [options] pretargeting-config insert -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] pretargeting-config list [-p ]... [-o ] + adexchangebuyer1d3 [options] pretargeting-config patch -r ... [-p ]... [-o ] + adexchangebuyer1d3 [options] pretargeting-config update -r ... [-p ]... [-o ] + adexchangebuyer1d3 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AdExchangeBuyer>, +} + + +impl Engine { + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let id: i32 = arg_from_str(&self.opt.arg_id, err, "", "integer"); + let mut call = self.hub.accounts().get(id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Account = Default::default(); + let id: i32 = arg_from_str(&self.opt.arg_id, err, "", "integer"); + let mut call = self.hub.accounts().patch(&request, id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "maximum-total-qps" => { + request.maximum_total_qps = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-total-qps", "integer")); + }, + "maximum-active-creatives" => { + request.maximum_active_creatives = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-active-creatives", "integer")); + }, + "cookie-matching-nid" => { + request.cookie_matching_nid = Some(value.unwrap_or("").to_string()); + }, + "number-active-creatives" => { + request.number_active_creatives = Some(arg_from_str(value.unwrap_or("-0"), err, "number-active-creatives", "integer")); + }, + "id" => { + request.id = Some(arg_from_str(value.unwrap_or("-0"), err, "id", "integer")); + }, + "cookie-matching-url" => { + request.cookie_matching_url = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Account = Default::default(); + let id: i32 = arg_from_str(&self.opt.arg_id, err, "", "integer"); + let mut call = self.hub.accounts().update(&request, id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "maximum-total-qps" => { + request.maximum_total_qps = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-total-qps", "integer")); + }, + "maximum-active-creatives" => { + request.maximum_active_creatives = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-active-creatives", "integer")); + }, + "cookie-matching-nid" => { + request.cookie_matching_nid = Some(value.unwrap_or("").to_string()); + }, + "number-active-creatives" => { + request.number_active_creatives = Some(arg_from_str(value.unwrap_or("-0"), err, "number-active-creatives", "integer")); + }, + "id" => { + request.id = Some(arg_from_str(value.unwrap_or("-0"), err, "id", "integer")); + }, + "cookie-matching-url" => { + request.cookie_matching_url = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _billing_info_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let account_id: i32 = arg_from_str(&self.opt.arg_account_id, err, "", "integer"); + let mut call = self.hub.billing_info().get(account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _billing_info_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.billing_info().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _budget_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.budget().get(&self.opt.arg_account_id, &self.opt.arg_billing_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _budget_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Budget = Default::default(); + let mut call = self.hub.budget().patch(&request, &self.opt.arg_account_id, &self.opt.arg_billing_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "budget-amount" => { + request.budget_amount = Some(value.unwrap_or("").to_string()); + }, + "currency-code" => { + request.currency_code = Some(value.unwrap_or("").to_string()); + }, + "billing-id" => { + request.billing_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _budget_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Budget = Default::default(); + let mut call = self.hub.budget().update(&request, &self.opt.arg_account_id, &self.opt.arg_billing_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "budget-amount" => { + request.budget_amount = Some(value.unwrap_or("").to_string()); + }, + "currency-code" => { + request.currency_code = Some(value.unwrap_or("").to_string()); + }, + "billing-id" => { + request.billing_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let account_id: i32 = arg_from_str(&self.opt.arg_account_id, err, "", "integer"); + let mut call = self.hub.creatives().get(account_id, &self.opt.arg_buyer_creative_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Creative = Default::default(); + let mut call = self.hub.creatives().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_filtering_reasons_init(request: &mut api::Creative) { + if request.filtering_reasons.is_none() { + request.filtering_reasons = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "product-categories" => { + if request.product_categories.is_none() { + request.product_categories = Some(Default::default()); + } + request.product_categories.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "product-categories", "integer")); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "video-url" => { + request.video_url = Some(value.unwrap_or("").to_string()); + }, + "agency-id" => { + request.agency_id = Some(value.unwrap_or("").to_string()); + }, + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "attribute" => { + if request.attribute.is_none() { + request.attribute = Some(Default::default()); + } + request.attribute.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "attribute", "integer")); + }, + "restricted-categories" => { + if request.restricted_categories.is_none() { + request.restricted_categories = Some(Default::default()); + } + request.restricted_categories.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "restricted-categories", "integer")); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "advertiser-name" => { + request.advertiser_name = Some(value.unwrap_or("").to_string()); + }, + "html-snippet" => { + request.html_snippet = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + if request.advertiser_id.is_none() { + request.advertiser_id = Some(Default::default()); + } + request.advertiser_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "buyer-creative-id" => { + request.buyer_creative_id = Some(value.unwrap_or("").to_string()); + }, + "click-through-url" => { + if request.click_through_url.is_none() { + request.click_through_url = Some(Default::default()); + } + request.click_through_url.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "vendor-type" => { + if request.vendor_type.is_none() { + request.vendor_type = Some(Default::default()); + } + request.vendor_type.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "vendor-type", "integer")); + }, + "filtering-reasons.date" => { + request_filtering_reasons_init(&mut request); + request.filtering_reasons.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "sensitive-categories" => { + request_filtering_reasons_init(&mut request); + if request.sensitive_categories.is_none() { + request.sensitive_categories = Some(Default::default()); + } + request.sensitive_categories.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "sensitive-categories", "integer")); + }, + "account-id" => { + request_filtering_reasons_init(&mut request); + request.account_id = Some(arg_from_str(value.unwrap_or("-0"), err, "account-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.creatives().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "status-filter" => { + call = call.status_filter(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "buyer-creative-id" => { + call = call.add_buyer_creative_id(value.unwrap_or("")); + }, + "account-id" => { + call = call.add_account_id(arg_from_str(value.unwrap_or("-0"), err, "account-id", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _direct_deals_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.direct_deals().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _direct_deals_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.direct_deals().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _performance_report_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.performance_report().list(&self.opt.arg_account_id, &self.opt.arg_end_date_time, &self.opt.arg_start_date_time); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pretargeting_config_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pretargeting_config().delete(&self.opt.arg_account_id, &self.opt.arg_config_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _pretargeting_config_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pretargeting_config().get(&self.opt.arg_account_id, &self.opt.arg_config_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pretargeting_config_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::PretargetingConfig = Default::default(); + let mut call = self.hub.pretargeting_config().insert(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "billing-id" => { + request.billing_id = Some(value.unwrap_or("").to_string()); + }, + "languages" => { + if request.languages.is_none() { + request.languages = Some(Default::default()); + } + request.languages.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "config-name" => { + request.config_name = Some(value.unwrap_or("").to_string()); + }, + "excluded-geo-criteria-ids" => { + if request.excluded_geo_criteria_ids.is_none() { + request.excluded_geo_criteria_ids = Some(Default::default()); + } + request.excluded_geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-lists" => { + if request.user_lists.is_none() { + request.user_lists = Some(Default::default()); + } + request.user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-verticals" => { + if request.excluded_verticals.is_none() { + request.excluded_verticals = Some(Default::default()); + } + request.excluded_verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "vendor-types" => { + if request.vendor_types.is_none() { + request.vendor_types = Some(Default::default()); + } + request.vendor_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-content-labels" => { + if request.excluded_content_labels.is_none() { + request.excluded_content_labels = Some(Default::default()); + } + request.excluded_content_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "verticals" => { + if request.verticals.is_none() { + request.verticals = Some(Default::default()); + } + request.verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "platforms" => { + if request.platforms.is_none() { + request.platforms = Some(Default::default()); + } + request.platforms.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-devices" => { + if request.mobile_devices.is_none() { + request.mobile_devices = Some(Default::default()); + } + request.mobile_devices.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creative-type" => { + if request.creative_type.is_none() { + request.creative_type = Some(Default::default()); + } + request.creative_type.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "geo-criteria-ids" => { + if request.geo_criteria_ids.is_none() { + request.geo_criteria_ids = Some(Default::default()); + } + request.geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-operating-system-versions" => { + if request.mobile_operating_system_versions.is_none() { + request.mobile_operating_system_versions = Some(Default::default()); + } + request.mobile_operating_system_versions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-carriers" => { + if request.mobile_carriers.is_none() { + request.mobile_carriers = Some(Default::default()); + } + request.mobile_carriers.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "config-id" => { + request.config_id = Some(value.unwrap_or("").to_string()); + }, + "excluded-user-lists" => { + if request.excluded_user_lists.is_none() { + request.excluded_user_lists = Some(Default::default()); + } + request.excluded_user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "is-active" => { + request.is_active = Some(arg_from_str(value.unwrap_or("false"), err, "is-active", "boolean")); + }, + "supported-creative-attributes" => { + if request.supported_creative_attributes.is_none() { + request.supported_creative_attributes = Some(Default::default()); + } + request.supported_creative_attributes.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pretargeting_config_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pretargeting_config().list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pretargeting_config_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::PretargetingConfig = Default::default(); + let mut call = self.hub.pretargeting_config().patch(&request, &self.opt.arg_account_id, &self.opt.arg_config_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "billing-id" => { + request.billing_id = Some(value.unwrap_or("").to_string()); + }, + "languages" => { + if request.languages.is_none() { + request.languages = Some(Default::default()); + } + request.languages.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "config-name" => { + request.config_name = Some(value.unwrap_or("").to_string()); + }, + "excluded-geo-criteria-ids" => { + if request.excluded_geo_criteria_ids.is_none() { + request.excluded_geo_criteria_ids = Some(Default::default()); + } + request.excluded_geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-lists" => { + if request.user_lists.is_none() { + request.user_lists = Some(Default::default()); + } + request.user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-verticals" => { + if request.excluded_verticals.is_none() { + request.excluded_verticals = Some(Default::default()); + } + request.excluded_verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "vendor-types" => { + if request.vendor_types.is_none() { + request.vendor_types = Some(Default::default()); + } + request.vendor_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-content-labels" => { + if request.excluded_content_labels.is_none() { + request.excluded_content_labels = Some(Default::default()); + } + request.excluded_content_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "verticals" => { + if request.verticals.is_none() { + request.verticals = Some(Default::default()); + } + request.verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "platforms" => { + if request.platforms.is_none() { + request.platforms = Some(Default::default()); + } + request.platforms.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-devices" => { + if request.mobile_devices.is_none() { + request.mobile_devices = Some(Default::default()); + } + request.mobile_devices.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creative-type" => { + if request.creative_type.is_none() { + request.creative_type = Some(Default::default()); + } + request.creative_type.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "geo-criteria-ids" => { + if request.geo_criteria_ids.is_none() { + request.geo_criteria_ids = Some(Default::default()); + } + request.geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-operating-system-versions" => { + if request.mobile_operating_system_versions.is_none() { + request.mobile_operating_system_versions = Some(Default::default()); + } + request.mobile_operating_system_versions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-carriers" => { + if request.mobile_carriers.is_none() { + request.mobile_carriers = Some(Default::default()); + } + request.mobile_carriers.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "config-id" => { + request.config_id = Some(value.unwrap_or("").to_string()); + }, + "excluded-user-lists" => { + if request.excluded_user_lists.is_none() { + request.excluded_user_lists = Some(Default::default()); + } + request.excluded_user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "is-active" => { + request.is_active = Some(arg_from_str(value.unwrap_or("false"), err, "is-active", "boolean")); + }, + "supported-creative-attributes" => { + if request.supported_creative_attributes.is_none() { + request.supported_creative_attributes = Some(Default::default()); + } + request.supported_creative_attributes.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pretargeting_config_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::PretargetingConfig = Default::default(); + let mut call = self.hub.pretargeting_config().update(&request, &self.opt.arg_account_id, &self.opt.arg_config_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "billing-id" => { + request.billing_id = Some(value.unwrap_or("").to_string()); + }, + "languages" => { + if request.languages.is_none() { + request.languages = Some(Default::default()); + } + request.languages.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "config-name" => { + request.config_name = Some(value.unwrap_or("").to_string()); + }, + "excluded-geo-criteria-ids" => { + if request.excluded_geo_criteria_ids.is_none() { + request.excluded_geo_criteria_ids = Some(Default::default()); + } + request.excluded_geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-lists" => { + if request.user_lists.is_none() { + request.user_lists = Some(Default::default()); + } + request.user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-verticals" => { + if request.excluded_verticals.is_none() { + request.excluded_verticals = Some(Default::default()); + } + request.excluded_verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "vendor-types" => { + if request.vendor_types.is_none() { + request.vendor_types = Some(Default::default()); + } + request.vendor_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "excluded-content-labels" => { + if request.excluded_content_labels.is_none() { + request.excluded_content_labels = Some(Default::default()); + } + request.excluded_content_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "verticals" => { + if request.verticals.is_none() { + request.verticals = Some(Default::default()); + } + request.verticals.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "platforms" => { + if request.platforms.is_none() { + request.platforms = Some(Default::default()); + } + request.platforms.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-devices" => { + if request.mobile_devices.is_none() { + request.mobile_devices = Some(Default::default()); + } + request.mobile_devices.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creative-type" => { + if request.creative_type.is_none() { + request.creative_type = Some(Default::default()); + } + request.creative_type.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "geo-criteria-ids" => { + if request.geo_criteria_ids.is_none() { + request.geo_criteria_ids = Some(Default::default()); + } + request.geo_criteria_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-operating-system-versions" => { + if request.mobile_operating_system_versions.is_none() { + request.mobile_operating_system_versions = Some(Default::default()); + } + request.mobile_operating_system_versions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mobile-carriers" => { + if request.mobile_carriers.is_none() { + request.mobile_carriers = Some(Default::default()); + } + request.mobile_carriers.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "config-id" => { + request.config_id = Some(value.unwrap_or("").to_string()); + }, + "excluded-user-lists" => { + if request.excluded_user_lists.is_none() { + request.excluded_user_lists = Some(Default::default()); + } + request.excluded_user_lists.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "is-active" => { + request.is_active = Some(arg_from_str(value.unwrap_or("false"), err, "is-active", "boolean")); + }, + "supported-creative-attributes" => { + if request.supported_creative_attributes.is_none() { + request.supported_creative_attributes = Some(Default::default()); + } + request.supported_creative_attributes.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._accounts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_billing_info { + if self.opt.cmd_get { + call_result = self._billing_info_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._billing_info_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_budget { + if self.opt.cmd_get { + call_result = self._budget_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._budget_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._budget_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creatives { + if self.opt.cmd_get { + call_result = self._creatives_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._creatives_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._creatives_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_direct_deals { + if self.opt.cmd_get { + call_result = self._direct_deals_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._direct_deals_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_performance_report { + if self.opt.cmd_list { + call_result = self._performance_report_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_pretargeting_config { + if self.opt.cmd_delete { + call_result = self._pretargeting_config_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._pretargeting_config_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._pretargeting_config_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._pretargeting_config_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._pretargeting_config_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._pretargeting_config_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "adexchangebuyer1d3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "adexchangebuyer1d3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AdExchangeBuyer::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/adexchangeseller2-cli/Cargo.toml b/gen/adexchangeseller2-cli/Cargo.toml new file mode 100644 index 00000000000..8dcaf36b5fd --- /dev/null +++ b/gen/adexchangeseller2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-adexchangeseller2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Ad Exchange Seller (protocol v2.0)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/adexchangeseller2-cli" +homepage = "https://developers.google.com/ad-exchange/seller-rest/" +documentation = "http://byron.github.io/google-apis-rs/google_adexchangeseller2_cli" +license = "MIT" +keywords = ["adexchangeseller", "google", "cli"] + +[[bin]] +name = "adexchangeseller2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-adexchangeseller2] +path = "../adexchangeseller2" diff --git a/gen/adexchangeseller2-cli/LICENSE.md b/gen/adexchangeseller2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/adexchangeseller2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/adexchangeseller2-cli/README.md b/gen/adexchangeseller2-cli/README.md new file mode 100644 index 00000000000..778ac3ab91a --- /dev/null +++ b/gen/adexchangeseller2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADEXCHANGESELLER:V2.0 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/adexchangeseller2-cli/mkdocs.yml b/gen/adexchangeseller2-cli/mkdocs.yml new file mode 100644 index 00000000000..b75cd6d9dc8 --- /dev/null +++ b/gen/adexchangeseller2-cli/mkdocs.yml @@ -0,0 +1,30 @@ +site_name: Ad Exchange Seller v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-adexchangeseller2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/adexchangeseller2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_adclients-list.md', 'Accounts', 'Adclients List'] +- ['accounts_alerts-list.md', 'Accounts', 'Alerts List'] +- ['accounts_customchannels-get.md', 'Accounts', 'Customchannels Get'] +- ['accounts_customchannels-list.md', 'Accounts', 'Customchannels List'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_metadata-dimensions-list.md', 'Accounts', 'Metadata Dimensions List'] +- ['accounts_metadata-metrics-list.md', 'Accounts', 'Metadata Metrics List'] +- ['accounts_preferreddeals-get.md', 'Accounts', 'Preferreddeals Get'] +- ['accounts_preferreddeals-list.md', 'Accounts', 'Preferreddeals List'] +- ['accounts_reports-generate.md', 'Accounts', 'Reports Generate'] +- ['accounts_reports-saved-generate.md', 'Accounts', 'Reports Saved Generate'] +- ['accounts_reports-saved-list.md', 'Accounts', 'Reports Saved List'] +- ['accounts_urlchannels-list.md', 'Accounts', 'Urlchannels List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/adexchangeseller2-cli/src/cmn.rs b/gen/adexchangeseller2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/adexchangeseller2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/adexchangeseller2-cli/src/main.rs b/gen/adexchangeseller2-cli/src/main.rs new file mode 100644 index 00000000000..7ed33e071d7 --- /dev/null +++ b/gen/adexchangeseller2-cli/src/main.rs @@ -0,0 +1,855 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_adexchangeseller2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + adexchangeseller2 [options] accounts adclients-list [-p ]... [-o ] + adexchangeseller2 [options] accounts alerts-list [-p ]... [-o ] + adexchangeseller2 [options] accounts customchannels-get [-p ]... [-o ] + adexchangeseller2 [options] accounts customchannels-list [-p ]... [-o ] + adexchangeseller2 [options] accounts get [-p ]... [-o ] + adexchangeseller2 [options] accounts list [-p ]... [-o ] + adexchangeseller2 [options] accounts metadata-dimensions-list [-p ]... [-o ] + adexchangeseller2 [options] accounts metadata-metrics-list [-p ]... [-o ] + adexchangeseller2 [options] accounts preferreddeals-get [-p ]... [-o ] + adexchangeseller2 [options] accounts preferreddeals-list [-p ]... [-o ] + adexchangeseller2 [options] accounts reports-generate [-p ]... [-o ] + adexchangeseller2 [options] accounts reports-saved-generate [-p ]... [-o ] + adexchangeseller2 [options] accounts reports-saved-list [-p ]... [-o ] + adexchangeseller2 [options] accounts urlchannels-list [-p ]... [-o ] + adexchangeseller2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AdExchangeSeller>, +} + + +impl Engine { + fn _accounts_adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_alerts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().alerts_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_customchannels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().customchannels_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().customchannels_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_metadata_dimensions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().metadata_dimensions_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_metadata_metrics_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().metadata_metrics_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_preferreddeals_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().preferreddeals_get(&self.opt.arg_account_id, &self.opt.arg_deal_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_preferreddeals_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().preferreddeals_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut download_mode = false; + let mut call = self.hub.accounts().reports_generate(&self.opt.arg_account_id, &self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _accounts_reports_saved_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_saved_generate(&self.opt.arg_account_id, &self.opt.arg_saved_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_saved_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_saved_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_urlchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().urlchannels_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_adclients_list { + call_result = self._accounts_adclients_list(dry_run, &mut err); + } else if self.opt.cmd_alerts_list { + call_result = self._accounts_alerts_list(dry_run, &mut err); + } else if self.opt.cmd_customchannels_get { + call_result = self._accounts_customchannels_get(dry_run, &mut err); + } else if self.opt.cmd_customchannels_list { + call_result = self._accounts_customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_metadata_dimensions_list { + call_result = self._accounts_metadata_dimensions_list(dry_run, &mut err); + } else if self.opt.cmd_metadata_metrics_list { + call_result = self._accounts_metadata_metrics_list(dry_run, &mut err); + } else if self.opt.cmd_preferreddeals_get { + call_result = self._accounts_preferreddeals_get(dry_run, &mut err); + } else if self.opt.cmd_preferreddeals_list { + call_result = self._accounts_preferreddeals_list(dry_run, &mut err); + } else if self.opt.cmd_reports_generate { + call_result = self._accounts_reports_generate(dry_run, &mut err); + } else if self.opt.cmd_reports_saved_generate { + call_result = self._accounts_reports_saved_generate(dry_run, &mut err); + } else if self.opt.cmd_reports_saved_list { + call_result = self._accounts_reports_saved_list(dry_run, &mut err); + } else if self.opt.cmd_urlchannels_list { + call_result = self._accounts_urlchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "adexchangeseller2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "adexchangeseller2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AdExchangeSeller::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/admin1_directory-cli/Cargo.toml b/gen/admin1_directory-cli/Cargo.toml new file mode 100644 index 00000000000..67fb941cf34 --- /dev/null +++ b/gen/admin1_directory-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin1_directory-cli" +version = "0.0.1+20150309" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with directory (protocol directory_v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_directory-cli" +homepage = "https://developers.google.com/admin-sdk/directory/" +documentation = "http://byron.github.io/google-apis-rs/google_admin1_directory_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin1-directory" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin1_directory] +path = "../admin1_directory" diff --git a/gen/admin1_directory-cli/LICENSE.md b/gen/admin1_directory-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/admin1_directory-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/admin1_directory-cli/README.md b/gen/admin1_directory-cli/README.md new file mode 100644 index 00000000000..ee5759b0f6c --- /dev/null +++ b/gen/admin1_directory-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:DIRECTORY_V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin1_directory-cli/mkdocs.yml b/gen/admin1_directory-cli/mkdocs.yml new file mode 100644 index 00000000000..f5a2db0c20e --- /dev/null +++ b/gen/admin1_directory-cli/mkdocs.yml @@ -0,0 +1,83 @@ +site_name: directory v0.0.1+20150309 +site_url: http://byron.github.io/google-apis-rs/google-admin1_directory-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_directory-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['asps_delete.md', 'Asps', 'Delete'] +- ['asps_get.md', 'Asps', 'Get'] +- ['asps_list.md', 'Asps', 'List'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['chromeosdevices_get.md', 'Chromeosdevices', 'Get'] +- ['chromeosdevices_list.md', 'Chromeosdevices', 'List'] +- ['chromeosdevices_patch.md', 'Chromeosdevices', 'Patch'] +- ['chromeosdevices_update.md', 'Chromeosdevices', 'Update'] +- ['groups_aliases-delete.md', 'Groups', 'Aliases Delete'] +- ['groups_aliases-insert.md', 'Groups', 'Aliases Insert'] +- ['groups_aliases-list.md', 'Groups', 'Aliases List'] +- ['groups_delete.md', 'Groups', 'Delete'] +- ['groups_get.md', 'Groups', 'Get'] +- ['groups_insert.md', 'Groups', 'Insert'] +- ['groups_list.md', 'Groups', 'List'] +- ['groups_patch.md', 'Groups', 'Patch'] +- ['groups_update.md', 'Groups', 'Update'] +- ['members_delete.md', 'Members', 'Delete'] +- ['members_get.md', 'Members', 'Get'] +- ['members_insert.md', 'Members', 'Insert'] +- ['members_list.md', 'Members', 'List'] +- ['members_patch.md', 'Members', 'Patch'] +- ['members_update.md', 'Members', 'Update'] +- ['mobiledevices_action.md', 'Mobiledevices', 'Action'] +- ['mobiledevices_delete.md', 'Mobiledevices', 'Delete'] +- ['mobiledevices_get.md', 'Mobiledevices', 'Get'] +- ['mobiledevices_list.md', 'Mobiledevices', 'List'] +- ['notifications_delete.md', 'Notifications', 'Delete'] +- ['notifications_get.md', 'Notifications', 'Get'] +- ['notifications_list.md', 'Notifications', 'List'] +- ['notifications_patch.md', 'Notifications', 'Patch'] +- ['notifications_update.md', 'Notifications', 'Update'] +- ['orgunits_delete.md', 'Orgunits', 'Delete'] +- ['orgunits_get.md', 'Orgunits', 'Get'] +- ['orgunits_insert.md', 'Orgunits', 'Insert'] +- ['orgunits_list.md', 'Orgunits', 'List'] +- ['orgunits_patch.md', 'Orgunits', 'Patch'] +- ['orgunits_update.md', 'Orgunits', 'Update'] +- ['schemas_delete.md', 'Schemas', 'Delete'] +- ['schemas_get.md', 'Schemas', 'Get'] +- ['schemas_insert.md', 'Schemas', 'Insert'] +- ['schemas_list.md', 'Schemas', 'List'] +- ['schemas_patch.md', 'Schemas', 'Patch'] +- ['schemas_update.md', 'Schemas', 'Update'] +- ['tokens_delete.md', 'Tokens', 'Delete'] +- ['tokens_get.md', 'Tokens', 'Get'] +- ['tokens_list.md', 'Tokens', 'List'] +- ['users_aliases-delete.md', 'Users', 'Aliases Delete'] +- ['users_aliases-insert.md', 'Users', 'Aliases Insert'] +- ['users_aliases-list.md', 'Users', 'Aliases List'] +- ['users_aliases-watch.md', 'Users', 'Aliases Watch'] +- ['users_delete.md', 'Users', 'Delete'] +- ['users_get.md', 'Users', 'Get'] +- ['users_insert.md', 'Users', 'Insert'] +- ['users_list.md', 'Users', 'List'] +- ['users_make-admin.md', 'Users', 'Make Admin'] +- ['users_patch.md', 'Users', 'Patch'] +- ['users_photos-delete.md', 'Users', 'Photos Delete'] +- ['users_photos-get.md', 'Users', 'Photos Get'] +- ['users_photos-patch.md', 'Users', 'Photos Patch'] +- ['users_photos-update.md', 'Users', 'Photos Update'] +- ['users_undelete.md', 'Users', 'Undelete'] +- ['users_update.md', 'Users', 'Update'] +- ['users_watch.md', 'Users', 'Watch'] +- ['verification-codes_generate.md', 'Verification Codes', 'Generate'] +- ['verification-codes_invalidate.md', 'Verification Codes', 'Invalidate'] +- ['verification-codes_list.md', 'Verification Codes', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin1_directory-cli/src/cmn.rs b/gen/admin1_directory-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/admin1_directory-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/admin1_directory-cli/src/main.rs b/gen/admin1_directory-cli/src/main.rs new file mode 100644 index 00000000000..750712e1ea2 --- /dev/null +++ b/gen/admin1_directory-cli/src/main.rs @@ -0,0 +1,4769 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin1_directory as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin1-directory [options] asps delete [-p ]... + admin1-directory [options] asps get [-p ]... [-o ] + admin1-directory [options] asps list [-p ]... [-o ] + admin1-directory [options] channels stop -r ... [-p ]... + admin1-directory [options] chromeosdevices get [-p ]... [-o ] + admin1-directory [options] chromeosdevices list [-p ]... [-o ] + admin1-directory [options] chromeosdevices patch -r ... [-p ]... [-o ] + admin1-directory [options] chromeosdevices update -r ... [-p ]... [-o ] + admin1-directory [options] groups aliases-delete [-p ]... + admin1-directory [options] groups aliases-insert -r ... [-p ]... [-o ] + admin1-directory [options] groups aliases-list [-p ]... [-o ] + admin1-directory [options] groups delete [-p ]... + admin1-directory [options] groups get [-p ]... [-o ] + admin1-directory [options] groups insert -r ... [-p ]... [-o ] + admin1-directory [options] groups list [-p ]... [-o ] + admin1-directory [options] groups patch -r ... [-p ]... [-o ] + admin1-directory [options] groups update -r ... [-p ]... [-o ] + admin1-directory [options] members delete [-p ]... + admin1-directory [options] members get [-p ]... [-o ] + admin1-directory [options] members insert -r ... [-p ]... [-o ] + admin1-directory [options] members list [-p ]... [-o ] + admin1-directory [options] members patch -r ... [-p ]... [-o ] + admin1-directory [options] members update -r ... [-p ]... [-o ] + admin1-directory [options] mobiledevices action -r ... [-p ]... + admin1-directory [options] mobiledevices delete [-p ]... + admin1-directory [options] mobiledevices get [-p ]... [-o ] + admin1-directory [options] mobiledevices list [-p ]... [-o ] + admin1-directory [options] notifications delete [-p ]... + admin1-directory [options] notifications get [-p ]... [-o ] + admin1-directory [options] notifications list [-p ]... [-o ] + admin1-directory [options] notifications patch -r ... [-p ]... [-o ] + admin1-directory [options] notifications update -r ... [-p ]... [-o ] + admin1-directory [options] orgunits delete [-p ]... + admin1-directory [options] orgunits get [-p ]... [-o ] + admin1-directory [options] orgunits insert -r ... [-p ]... [-o ] + admin1-directory [options] orgunits list [-p ]... [-o ] + admin1-directory [options] orgunits patch -r ... [-p ]... [-o ] + admin1-directory [options] orgunits update -r ... [-p ]... [-o ] + admin1-directory [options] schemas delete [-p ]... + admin1-directory [options] schemas get [-p ]... [-o ] + admin1-directory [options] schemas insert -r ... [-p ]... [-o ] + admin1-directory [options] schemas list [-p ]... [-o ] + admin1-directory [options] schemas patch -r ... [-p ]... [-o ] + admin1-directory [options] schemas update -r ... [-p ]... [-o ] + admin1-directory [options] tokens delete [-p ]... + admin1-directory [options] tokens get [-p ]... [-o ] + admin1-directory [options] tokens list [-p ]... [-o ] + admin1-directory [options] users aliases-delete [-p ]... + admin1-directory [options] users aliases-insert -r ... [-p ]... [-o ] + admin1-directory [options] users aliases-list [-p ]... [-o ] + admin1-directory [options] users aliases-watch -r ... [-p ]... [-o ] + admin1-directory [options] users delete [-p ]... + admin1-directory [options] users get [-p ]... [-o ] + admin1-directory [options] users insert -r ... [-p ]... [-o ] + admin1-directory [options] users list [-p ]... [-o ] + admin1-directory [options] users make-admin -r ... [-p ]... + admin1-directory [options] users patch -r ... [-p ]... [-o ] + admin1-directory [options] users photos-delete [-p ]... + admin1-directory [options] users photos-get [-p ]... [-o ] + admin1-directory [options] users photos-patch -r ... [-p ]... [-o ] + admin1-directory [options] users photos-update -r ... [-p ]... [-o ] + admin1-directory [options] users undelete -r ... [-p ]... + admin1-directory [options] users update -r ... [-p ]... [-o ] + admin1-directory [options] users watch -r ... [-p ]... [-o ] + admin1-directory [options] verification-codes generate [-p ]... + admin1-directory [options] verification-codes invalidate [-p ]... + admin1-directory [options] verification-codes list [-p ]... [-o ] + admin1-directory --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Directory>, +} + + +impl Engine { + fn _asps_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let code_id: i32 = arg_from_str(&self.opt.arg_code_id, err, "", "integer"); + let mut call = self.hub.asps().delete(&self.opt.arg_user_key, code_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _asps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let code_id: i32 = arg_from_str(&self.opt.arg_code_id, err, "", "integer"); + let mut call = self.hub.asps().get(&self.opt.arg_user_key, code_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _asps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.asps().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _chromeosdevices_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.chromeosdevices().get(&self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.chromeosdevices().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ChromeOsDevice = Default::default(); + let mut call = self.hub.chromeosdevices().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mac-address" => { + request.mac_address = Some(value.unwrap_or("").to_string()); + }, + "last-sync" => { + request.last_sync = Some(value.unwrap_or("").to_string()); + }, + "order-number" => { + request.order_number = Some(value.unwrap_or("").to_string()); + }, + "annotated-user" => { + request.annotated_user = Some(value.unwrap_or("").to_string()); + }, + "firmware-version" => { + request.firmware_version = Some(value.unwrap_or("").to_string()); + }, + "boot-mode" => { + request.boot_mode = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "support-end-date" => { + request.support_end_date = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "will-auto-renew" => { + request.will_auto_renew = Some(arg_from_str(value.unwrap_or("false"), err, "will-auto-renew", "boolean")); + }, + "ethernet-mac-address" => { + request.ethernet_mac_address = Some(value.unwrap_or("").to_string()); + }, + "meid" => { + request.meid = Some(value.unwrap_or("").to_string()); + }, + "annotated-location" => { + request.annotated_location = Some(value.unwrap_or("").to_string()); + }, + "device-id" => { + request.device_id = Some(value.unwrap_or("").to_string()); + }, + "platform-version" => { + request.platform_version = Some(value.unwrap_or("").to_string()); + }, + "os-version" => { + request.os_version = Some(value.unwrap_or("").to_string()); + }, + "last-enrollment-time" => { + request.last_enrollment_time = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "serial-number" => { + request.serial_number = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "model" => { + request.model = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _chromeosdevices_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ChromeOsDevice = Default::default(); + let mut call = self.hub.chromeosdevices().update(&request, &self.opt.arg_customer_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mac-address" => { + request.mac_address = Some(value.unwrap_or("").to_string()); + }, + "last-sync" => { + request.last_sync = Some(value.unwrap_or("").to_string()); + }, + "order-number" => { + request.order_number = Some(value.unwrap_or("").to_string()); + }, + "annotated-user" => { + request.annotated_user = Some(value.unwrap_or("").to_string()); + }, + "firmware-version" => { + request.firmware_version = Some(value.unwrap_or("").to_string()); + }, + "boot-mode" => { + request.boot_mode = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "support-end-date" => { + request.support_end_date = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "will-auto-renew" => { + request.will_auto_renew = Some(arg_from_str(value.unwrap_or("false"), err, "will-auto-renew", "boolean")); + }, + "ethernet-mac-address" => { + request.ethernet_mac_address = Some(value.unwrap_or("").to_string()); + }, + "meid" => { + request.meid = Some(value.unwrap_or("").to_string()); + }, + "annotated-location" => { + request.annotated_location = Some(value.unwrap_or("").to_string()); + }, + "device-id" => { + request.device_id = Some(value.unwrap_or("").to_string()); + }, + "platform-version" => { + request.platform_version = Some(value.unwrap_or("").to_string()); + }, + "os-version" => { + request.os_version = Some(value.unwrap_or("").to_string()); + }, + "last-enrollment-time" => { + request.last_enrollment_time = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "serial-number" => { + request.serial_number = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "model" => { + request.model = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_aliases_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().aliases_delete(&self.opt.arg_group_key, &self.opt.arg_alias); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _groups_aliases_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Alias = Default::default(); + let mut call = self.hub.groups().aliases_insert(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "alias" => { + request.alias = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_aliases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().aliases_list(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().delete(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().get(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Group = Default::default(); + let mut call = self.hub.groups().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.groups().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-key" => { + call = call.user_key(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Group = Default::default(); + let mut call = self.hub.groups().patch(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Group = Default::default(); + let mut call = self.hub.groups().update(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "admin-created" => { + request.admin_created = Some(arg_from_str(value.unwrap_or("false"), err, "admin-created", "boolean")); + }, + "direct-members-count" => { + request.direct_members_count = Some(arg_from_str(value.unwrap_or("-0"), err, "direct-members-count", "int64")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().delete(&self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _members_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().get(&self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Member = Default::default(); + let mut call = self.hub.members().insert(&request, &self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.members().list(&self.opt.arg_group_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "roles" => { + call = call.roles(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Member = Default::default(); + let mut call = self.hub.members().patch(&request, &self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _members_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Member = Default::default(); + let mut call = self.hub.members().update(&request, &self.opt.arg_group_key, &self.opt.arg_member_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mobiledevices_action(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::MobileDeviceAction = Default::default(); + let mut call = self.hub.mobiledevices().action(&request, &self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "action" => { + request.action = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mobiledevices_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().delete(&self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mobiledevices_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().get(&self.opt.arg_customer_id, &self.opt.arg_resource_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mobiledevices_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mobiledevices().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().delete(&self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _notifications_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().get(&self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.notifications().list(&self.opt.arg_customer); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Notification = Default::default(); + let mut call = self.hub.notifications().patch(&request, &self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "send-time" => { + request.send_time = Some(value.unwrap_or("").to_string()); + }, + "notification-id" => { + request.notification_id = Some(value.unwrap_or("").to_string()); + }, + "from-address" => { + request.from_address = Some(value.unwrap_or("").to_string()); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "subject" => { + request.subject = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _notifications_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Notification = Default::default(); + let mut call = self.hub.notifications().update(&request, &self.opt.arg_customer, &self.opt.arg_notification_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "send-time" => { + request.send_time = Some(value.unwrap_or("").to_string()); + }, + "notification-id" => { + request.notification_id = Some(value.unwrap_or("").to_string()); + }, + "from-address" => { + request.from_address = Some(value.unwrap_or("").to_string()); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "subject" => { + request.subject = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().delete(&self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _orgunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().get(&self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::OrgUnit = Default::default(); + let mut call = self.hub.orgunits().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.orgunits().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "org-unit-path" => { + call = call.org_unit_path(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::OrgUnit = Default::default(); + let mut call = self.hub.orgunits().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _orgunits_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::OrgUnit = Default::default(); + let mut call = self.hub.orgunits().update(&request, &self.opt.arg_customer_id, &self.opt.arg_org_unit_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-path" => { + request.parent_org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "parent-org-unit-id" => { + request.parent_org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "block-inheritance" => { + request.block_inheritance = Some(arg_from_str(value.unwrap_or("false"), err, "block-inheritance", "boolean")); + }, + "org-unit-id" => { + request.org_unit_id = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().delete(&self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _schemas_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().get(&self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Schema = Default::default(); + let mut call = self.hub.schemas().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.schemas().list(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Schema = Default::default(); + let mut call = self.hub.schemas().patch(&request, &self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schemas_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Schema = Default::default(); + let mut call = self.hub.schemas().update(&request, &self.opt.arg_customer_id, &self.opt.arg_schema_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "schema-id" => { + request.schema_id = Some(value.unwrap_or("").to_string()); + }, + "schema-name" => { + request.schema_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tokens_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().delete(&self.opt.arg_user_key, &self.opt.arg_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tokens_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().get(&self.opt.arg_user_key, &self.opt.arg_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tokens_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tokens().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().aliases_delete(&self.opt.arg_user_key, &self.opt.arg_alias); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_aliases_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Alias = Default::default(); + let mut call = self.hub.users().aliases_insert(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "alias" => { + request.alias = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().aliases_list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "event" => { + call = call.event(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_aliases_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.users().aliases_watch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "event" => { + call = call.event(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().delete(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().get(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::User = Default::default(); + let mut call = self.hub.users().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = value.unwrap_or("").to_string(); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event" => { + call = call.event(value.unwrap_or("")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_make_admin(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UserMakeAdmin = Default::default(); + let mut call = self.hub.users().make_admin(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(arg_from_str(value.unwrap_or("false"), err, "status", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::User = Default::default(); + let mut call = self.hub.users().patch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = value.unwrap_or("").to_string(); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().photos_delete(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_photos_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().photos_get(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UserPhoto = Default::default(); + let mut call = self.hub.users().photos_patch(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "photo-data" => { + request.photo_data = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_photos_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UserPhoto = Default::default(); + let mut call = self.hub.users().photos_update(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "photo-data" => { + request.photo_data = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_undelete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UserUndelete = Default::default(); + let mut call = self.hub.users().undelete(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::User = Default::default(); + let mut call = self.hub.users().update(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_name_init(request: &mut api::User) { + if request.name.is_none() { + request.name = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "is-delegated-admin" => { + request.is_delegated_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-delegated-admin", "boolean")); + }, + "suspended" => { + request.suspended = Some(arg_from_str(value.unwrap_or("false"), err, "suspended", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "aliases" => { + if request.aliases.is_none() { + request.aliases = Some(Default::default()); + } + request.aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "non-editable-aliases" => { + if request.non_editable_aliases.is_none() { + request.non_editable_aliases = Some(Default::default()); + } + request.non_editable_aliases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "deletion-time" => { + request.deletion_time = Some(value.unwrap_or("").to_string()); + }, + "suspension-reason" => { + request.suspension_reason = Some(value.unwrap_or("").to_string()); + }, + "thumbnail-photo-url" => { + request.thumbnail_photo_url = Some(value.unwrap_or("").to_string()); + }, + "is-admin" => { + request.is_admin = Some(arg_from_str(value.unwrap_or("false"), err, "is-admin", "boolean")); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(arg_from_str(value.unwrap_or("false"), err, "include-in-global-address-list", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-login-time" => { + request.last_login_time = Some(value.unwrap_or("").to_string()); + }, + "org-unit-path" => { + request.org_unit_path = Some(value.unwrap_or("").to_string()); + }, + "agreed-to-terms" => { + request.agreed_to_terms = Some(arg_from_str(value.unwrap_or("false"), err, "agreed-to-terms", "boolean")); + }, + "ip-whitelisted" => { + request.ip_whitelisted = Some(arg_from_str(value.unwrap_or("false"), err, "ip-whitelisted", "boolean")); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "is-mailbox-setup" => { + request.is_mailbox_setup = Some(arg_from_str(value.unwrap_or("false"), err, "is-mailbox-setup", "boolean")); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "hash-function" => { + request.hash_function = Some(value.unwrap_or("").to_string()); + }, + "name.full-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().full_name = value.unwrap_or("").to_string(); + }, + "name.given-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "name.family-name" => { + request_name_init(&mut request); + request.name.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_name_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "change-password-at-next-login" => { + request_name_init(&mut request); + request.change_password_at_next_login = Some(arg_from_str(value.unwrap_or("false"), err, "change-password-at-next-login", "boolean")); + }, + "customer-id" => { + request_name_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.users().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view-type" => { + call = call.view_type(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event" => { + call = call.event(value.unwrap_or("")); + }, + "domain" => { + call = call.domain(value.unwrap_or("")); + }, + "customer" => { + call = call.customer(value.unwrap_or("")); + }, + "custom-field-mask" => { + call = call.custom_field_mask(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _verification_codes_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().generate(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _verification_codes_invalidate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().invalidate(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _verification_codes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.verification_codes().list(&self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_asps { + if self.opt.cmd_delete { + call_result = self._asps_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._asps_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._asps_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_chromeosdevices { + if self.opt.cmd_get { + call_result = self._chromeosdevices_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._chromeosdevices_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._chromeosdevices_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._chromeosdevices_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_groups { + if self.opt.cmd_aliases_delete { + call_result = self._groups_aliases_delete(dry_run, &mut err); + } else if self.opt.cmd_aliases_insert { + call_result = self._groups_aliases_insert(dry_run, &mut err); + } else if self.opt.cmd_aliases_list { + call_result = self._groups_aliases_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._groups_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_members { + if self.opt.cmd_delete { + call_result = self._members_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._members_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._members_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._members_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._members_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._members_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_mobiledevices { + if self.opt.cmd_action { + call_result = self._mobiledevices_action(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._mobiledevices_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._mobiledevices_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._mobiledevices_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_notifications { + if self.opt.cmd_delete { + call_result = self._notifications_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._notifications_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._notifications_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._notifications_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._notifications_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_orgunits { + if self.opt.cmd_delete { + call_result = self._orgunits_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._orgunits_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._orgunits_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._orgunits_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._orgunits_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._orgunits_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_schemas { + if self.opt.cmd_delete { + call_result = self._schemas_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._schemas_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._schemas_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._schemas_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._schemas_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._schemas_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tokens { + if self.opt.cmd_delete { + call_result = self._tokens_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tokens_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tokens_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_users { + if self.opt.cmd_aliases_delete { + call_result = self._users_aliases_delete(dry_run, &mut err); + } else if self.opt.cmd_aliases_insert { + call_result = self._users_aliases_insert(dry_run, &mut err); + } else if self.opt.cmd_aliases_list { + call_result = self._users_aliases_list(dry_run, &mut err); + } else if self.opt.cmd_aliases_watch { + call_result = self._users_aliases_watch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._users_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._users_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._users_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._users_list(dry_run, &mut err); + } else if self.opt.cmd_make_admin { + call_result = self._users_make_admin(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._users_patch(dry_run, &mut err); + } else if self.opt.cmd_photos_delete { + call_result = self._users_photos_delete(dry_run, &mut err); + } else if self.opt.cmd_photos_get { + call_result = self._users_photos_get(dry_run, &mut err); + } else if self.opt.cmd_photos_patch { + call_result = self._users_photos_patch(dry_run, &mut err); + } else if self.opt.cmd_photos_update { + call_result = self._users_photos_update(dry_run, &mut err); + } else if self.opt.cmd_undelete { + call_result = self._users_undelete(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._users_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._users_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_verification_codes { + if self.opt.cmd_generate { + call_result = self._verification_codes_generate(dry_run, &mut err); + } else if self.opt.cmd_invalidate { + call_result = self._verification_codes_invalidate(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._verification_codes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "admin1-directory-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "admin1-directory", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Directory::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/admin1_reports-cli/Cargo.toml b/gen/admin1_reports-cli/Cargo.toml new file mode 100644 index 00000000000..b6c3e4f0f80 --- /dev/null +++ b/gen/admin1_reports-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin1_reports-cli" +version = "0.0.1+20150115" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with reports (protocol reports_v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_reports-cli" +homepage = "https://developers.google.com/admin-sdk/reports/" +documentation = "http://byron.github.io/google-apis-rs/google_admin1_reports_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin1-reports" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin1_reports] +path = "../admin1_reports" diff --git a/gen/admin1_reports-cli/LICENSE.md b/gen/admin1_reports-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/admin1_reports-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/admin1_reports-cli/README.md b/gen/admin1_reports-cli/README.md new file mode 100644 index 00000000000..d63739eb1c9 --- /dev/null +++ b/gen/admin1_reports-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:REPORTS_V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin1_reports-cli/mkdocs.yml b/gen/admin1_reports-cli/mkdocs.yml new file mode 100644 index 00000000000..d5581f072cf --- /dev/null +++ b/gen/admin1_reports-cli/mkdocs.yml @@ -0,0 +1,21 @@ +site_name: reports v0.0.1+20150115 +site_url: http://byron.github.io/google-apis-rs/google-admin1_reports-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_reports-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_list.md', 'Activities', 'List'] +- ['activities_watch.md', 'Activities', 'Watch'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['customer-usage-reports_get.md', 'Customer Usage Reports', 'Get'] +- ['user-usage-report_get.md', 'User Usage Report', 'Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin1_reports-cli/src/cmn.rs b/gen/admin1_reports-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/admin1_reports-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/admin1_reports-cli/src/main.rs b/gen/admin1_reports-cli/src/main.rs new file mode 100644 index 00000000000..41dfbdd61de --- /dev/null +++ b/gen/admin1_reports-cli/src/main.rs @@ -0,0 +1,535 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin1_reports as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin1-reports [options] activities list [-p ]... [-o ] + admin1-reports [options] activities watch -r ... [-p ]... [-o ] + admin1-reports [options] channels stop -r ... [-p ]... + admin1-reports [options] customer-usage-reports get [-p ]... [-o ] + admin1-reports [options] user-usage-report get [-p ]... [-o ] + admin1-reports --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Reports>, +} + + +impl Engine { + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.activities().list(&self.opt.arg_user_key, &self.opt.arg_application_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.activities().watch(&request, &self.opt.arg_user_key, &self.opt.arg_application_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _customer_usage_reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customer_usage_reports().get(&self.opt.arg_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "parameters" => { + call = call.parameters(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_usage_report_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.user_usage_report().get(&self.opt.arg_user_key, &self.opt.arg_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "parameters" => { + call = call.parameters(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_activities { + if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._activities_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_customer_usage_reports { + if self.opt.cmd_get { + call_result = self._customer_usage_reports_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_user_usage_report { + if self.opt.cmd_get { + call_result = self._user_usage_report_get(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "admin1-reports-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "admin1-reports", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Reports::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/Cargo.toml b/gen/admin2_email_migration-cli/Cargo.toml new file mode 100644 index 00000000000..c610595b04b --- /dev/null +++ b/gen/admin2_email_migration-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-admin2_email_migration-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with admin (protocol email_migration_v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/admin2_email_migration-cli" +homepage = "https://developers.google.com/admin-sdk/email-migration/v2/" +documentation = "http://byron.github.io/google-apis-rs/google_admin2_email_migration_cli" +license = "MIT" +keywords = ["admin", "google", "cli"] + +[[bin]] +name = "admin2-email-migration" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-admin2_email_migration] +path = "../admin2_email_migration" diff --git a/gen/admin2_email_migration-cli/LICENSE.md b/gen/admin2_email_migration-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/admin2_email_migration-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/admin2_email_migration-cli/README.md b/gen/admin2_email_migration-cli/README.md new file mode 100644 index 00000000000..ed6449c3abf --- /dev/null +++ b/gen/admin2_email_migration-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADMIN:EMAIL_MIGRATION_V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/mkdocs.yml b/gen/admin2_email_migration-cli/mkdocs.yml new file mode 100644 index 00000000000..c666938a660 --- /dev/null +++ b/gen/admin2_email_migration-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: admin v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-admin2_email_migration-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/admin2_email_migration-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['mail_insert.md', 'Mail', 'Insert'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/admin2_email_migration-cli/src/cmn.rs b/gen/admin2_email_migration-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/admin2_email_migration-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/admin2_email_migration-cli/src/main.rs b/gen/admin2_email_migration-cli/src/main.rs new file mode 100644 index 00000000000..c90b782cc4c --- /dev/null +++ b/gen/admin2_email_migration-cli/src/main.rs @@ -0,0 +1,224 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_admin2_email_migration as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + admin2-email-migration [options] mail insert -r ... -u (simple|resumable) [-p ]... + admin2-email-migration --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Admin>, +} + + +impl Engine { + fn _mail_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::MailItem = Default::default(); + let mut call = self.hub.mail().insert(&request, &self.opt.arg_user_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "is-trash" => { + request.is_trash = Some(arg_from_str(value.unwrap_or("false"), err, "is-trash", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "labels" => { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + request.labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "is-draft" => { + request.is_draft = Some(arg_from_str(value.unwrap_or("false"), err, "is-draft", "boolean")); + }, + "is-inbox" => { + request.is_inbox = Some(arg_from_str(value.unwrap_or("false"), err, "is-inbox", "boolean")); + }, + "is-sent" => { + request.is_sent = Some(arg_from_str(value.unwrap_or("false"), err, "is-sent", "boolean")); + }, + "is-starred" => { + request.is_starred = Some(arg_from_str(value.unwrap_or("false"), err, "is-starred", "boolean")); + }, + "is-unread" => { + request.is_unread = Some(arg_from_str(value.unwrap_or("false"), err, "is-unread", "boolean")); + }, + "is-deleted" => { + request.is_deleted = Some(arg_from_str(value.unwrap_or("false"), err, "is-deleted", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_mail { + if self.opt.cmd_insert { + call_result = self._mail_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "admin2-email-migration-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "admin2-email-migration", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Admin::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/adsense1d4-cli/Cargo.toml b/gen/adsense1d4-cli/Cargo.toml new file mode 100644 index 00000000000..8fcdb442f5f --- /dev/null +++ b/gen/adsense1d4-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-adsense1d4-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with AdSense (protocol v1.4)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/adsense1d4-cli" +homepage = "https://developers.google.com/adsense/management/" +documentation = "http://byron.github.io/google-apis-rs/google_adsense1d4_cli" +license = "MIT" +keywords = ["adsense", "google", "cli"] + +[[bin]] +name = "adsense1d4" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-adsense1d4] +path = "../adsense1d4" diff --git a/gen/adsense1d4-cli/LICENSE.md b/gen/adsense1d4-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/adsense1d4-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/adsense1d4-cli/README.md b/gen/adsense1d4-cli/README.md new file mode 100644 index 00000000000..053e3832cdd --- /dev/null +++ b/gen/adsense1d4-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADSENSE:V1.4 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/adsense1d4-cli/mkdocs.yml b/gen/adsense1d4-cli/mkdocs.yml new file mode 100644 index 00000000000..ae9d468eceb --- /dev/null +++ b/gen/adsense1d4-cli/mkdocs.yml @@ -0,0 +1,54 @@ +site_name: AdSense v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-adsense1d4-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/adsense1d4-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_adclients-list.md', 'Accounts', 'Adclients List'] +- ['accounts_adunits-customchannels-list.md', 'Accounts', 'Adunits Customchannels List'] +- ['accounts_adunits-get.md', 'Accounts', 'Adunits Get'] +- ['accounts_adunits-get-ad-code.md', 'Accounts', 'Adunits Get Ad Code'] +- ['accounts_adunits-list.md', 'Accounts', 'Adunits List'] +- ['accounts_alerts-delete.md', 'Accounts', 'Alerts Delete'] +- ['accounts_alerts-list.md', 'Accounts', 'Alerts List'] +- ['accounts_customchannels-adunits-list.md', 'Accounts', 'Customchannels Adunits List'] +- ['accounts_customchannels-get.md', 'Accounts', 'Customchannels Get'] +- ['accounts_customchannels-list.md', 'Accounts', 'Customchannels List'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_payments-list.md', 'Accounts', 'Payments List'] +- ['accounts_reports-generate.md', 'Accounts', 'Reports Generate'] +- ['accounts_reports-saved-generate.md', 'Accounts', 'Reports Saved Generate'] +- ['accounts_reports-saved-list.md', 'Accounts', 'Reports Saved List'] +- ['accounts_savedadstyles-get.md', 'Accounts', 'Savedadstyles Get'] +- ['accounts_savedadstyles-list.md', 'Accounts', 'Savedadstyles List'] +- ['accounts_urlchannels-list.md', 'Accounts', 'Urlchannels List'] +- ['adclients_list.md', 'Adclients', 'List'] +- ['adunits_customchannels-list.md', 'Adunits', 'Customchannels List'] +- ['adunits_get.md', 'Adunits', 'Get'] +- ['adunits_get-ad-code.md', 'Adunits', 'Get Ad Code'] +- ['adunits_list.md', 'Adunits', 'List'] +- ['alerts_delete.md', 'Alerts', 'Delete'] +- ['alerts_list.md', 'Alerts', 'List'] +- ['customchannels_adunits-list.md', 'Customchannels', 'Adunits List'] +- ['customchannels_get.md', 'Customchannels', 'Get'] +- ['customchannels_list.md', 'Customchannels', 'List'] +- ['metadata_dimensions-list.md', 'Metadata', 'Dimensions List'] +- ['metadata_metrics-list.md', 'Metadata', 'Metrics List'] +- ['payments_list.md', 'Payments', 'List'] +- ['reports_generate.md', 'Reports', 'Generate'] +- ['reports_saved-generate.md', 'Reports', 'Saved Generate'] +- ['reports_saved-list.md', 'Reports', 'Saved List'] +- ['savedadstyles_get.md', 'Savedadstyles', 'Get'] +- ['savedadstyles_list.md', 'Savedadstyles', 'List'] +- ['urlchannels_list.md', 'Urlchannels', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/adsense1d4-cli/src/cmn.rs b/gen/adsense1d4-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/adsense1d4-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/adsense1d4-cli/src/main.rs b/gen/adsense1d4-cli/src/main.rs new file mode 100644 index 00000000000..e90b07e5b07 --- /dev/null +++ b/gen/adsense1d4-cli/src/main.rs @@ -0,0 +1,2158 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_adsense1d4 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + adsense1d4 [options] accounts adclients-list [-p ]... [-o ] + adsense1d4 [options] accounts adunits-customchannels-list [-p ]... [-o ] + adsense1d4 [options] accounts adunits-get [-p ]... [-o ] + adsense1d4 [options] accounts adunits-get-ad-code [-p ]... [-o ] + adsense1d4 [options] accounts adunits-list [-p ]... [-o ] + adsense1d4 [options] accounts alerts-delete [-p ]... + adsense1d4 [options] accounts alerts-list [-p ]... [-o ] + adsense1d4 [options] accounts customchannels-adunits-list [-p ]... [-o ] + adsense1d4 [options] accounts customchannels-get [-p ]... [-o ] + adsense1d4 [options] accounts customchannels-list [-p ]... [-o ] + adsense1d4 [options] accounts get [-p ]... [-o ] + adsense1d4 [options] accounts list [-p ]... [-o ] + adsense1d4 [options] accounts payments-list [-p ]... [-o ] + adsense1d4 [options] accounts reports-generate [-p ]... [-o ] + adsense1d4 [options] accounts reports-saved-generate [-p ]... [-o ] + adsense1d4 [options] accounts reports-saved-list [-p ]... [-o ] + adsense1d4 [options] accounts savedadstyles-get [-p ]... [-o ] + adsense1d4 [options] accounts savedadstyles-list [-p ]... [-o ] + adsense1d4 [options] accounts urlchannels-list [-p ]... [-o ] + adsense1d4 [options] adclients list [-p ]... [-o ] + adsense1d4 [options] adunits customchannels-list [-p ]... [-o ] + adsense1d4 [options] adunits get [-p ]... [-o ] + adsense1d4 [options] adunits get-ad-code [-p ]... [-o ] + adsense1d4 [options] adunits list [-p ]... [-o ] + adsense1d4 [options] alerts delete [-p ]... + adsense1d4 [options] alerts list [-p ]... [-o ] + adsense1d4 [options] customchannels adunits-list [-p ]... [-o ] + adsense1d4 [options] customchannels get [-p ]... [-o ] + adsense1d4 [options] customchannels list [-p ]... [-o ] + adsense1d4 [options] metadata dimensions-list [-p ]... [-o ] + adsense1d4 [options] metadata metrics-list [-p ]... [-o ] + adsense1d4 [options] payments list [-p ]... [-o ] + adsense1d4 [options] reports generate [-p ]... [-o ] + adsense1d4 [options] reports saved-generate [-p ]... [-o ] + adsense1d4 [options] reports saved-list [-p ]... [-o ] + adsense1d4 [options] savedadstyles get [-p ]... [-o ] + adsense1d4 [options] savedadstyles list [-p ]... [-o ] + adsense1d4 [options] urlchannels list [-p ]... [-o ] + adsense1d4 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AdSense>, +} + + +impl Engine { + fn _accounts_adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_customchannels_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get_ad_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get_ad_code(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_alerts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().alerts_delete(&self.opt.arg_account_id, &self.opt.arg_alert_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_alerts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().alerts_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_customchannels_adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().customchannels_adunits_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_customchannels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().customchannels_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().customchannels_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tree" => { + call = call.tree(arg_from_str(value.unwrap_or("false"), err, "tree", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_payments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().payments_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut download_mode = false; + let mut call = self.hub.accounts().reports_generate(&self.opt.arg_account_id, &self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "use-timezone-reporting" => { + call = call.use_timezone_reporting(arg_from_str(value.unwrap_or("false"), err, "use-timezone-reporting", "boolean")); + }, + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "currency" => { + call = call.currency(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _accounts_reports_saved_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_saved_generate(&self.opt.arg_account_id, &self.opt.arg_saved_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_saved_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_saved_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_savedadstyles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().savedadstyles_get(&self.opt.arg_account_id, &self.opt.arg_saved_ad_style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_savedadstyles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().savedadstyles_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_urlchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().urlchannels_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adclients().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adunits_customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adunits().customchannels_list(&self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adunits().get(&self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adunits_get_ad_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adunits().get_ad_code(&self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adunits().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _alerts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.alerts().delete(&self.opt.arg_alert_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _alerts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.alerts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().adunits_list(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().get(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metadata_dimensions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.metadata().dimensions_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metadata_metrics_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.metadata().metrics_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _payments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.payments().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut download_mode = false; + let mut call = self.hub.reports().generate(&self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "use-timezone-reporting" => { + call = call.use_timezone_reporting(arg_from_str(value.unwrap_or("false"), err, "use-timezone-reporting", "boolean")); + }, + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "currency" => { + call = call.currency(value.unwrap_or("")); + }, + "account-id" => { + call = call.add_account_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _reports_saved_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.reports().saved_generate(&self.opt.arg_saved_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_saved_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.reports().saved_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _savedadstyles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.savedadstyles().get(&self.opt.arg_saved_ad_style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _savedadstyles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.savedadstyles().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.urlchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_adclients_list { + call_result = self._accounts_adclients_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_customchannels_list { + call_result = self._accounts_adunits_customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_get { + call_result = self._accounts_adunits_get(dry_run, &mut err); + } else if self.opt.cmd_adunits_get_ad_code { + call_result = self._accounts_adunits_get_ad_code(dry_run, &mut err); + } else if self.opt.cmd_adunits_list { + call_result = self._accounts_adunits_list(dry_run, &mut err); + } else if self.opt.cmd_alerts_delete { + call_result = self._accounts_alerts_delete(dry_run, &mut err); + } else if self.opt.cmd_alerts_list { + call_result = self._accounts_alerts_list(dry_run, &mut err); + } else if self.opt.cmd_customchannels_adunits_list { + call_result = self._accounts_customchannels_adunits_list(dry_run, &mut err); + } else if self.opt.cmd_customchannels_get { + call_result = self._accounts_customchannels_get(dry_run, &mut err); + } else if self.opt.cmd_customchannels_list { + call_result = self._accounts_customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_payments_list { + call_result = self._accounts_payments_list(dry_run, &mut err); + } else if self.opt.cmd_reports_generate { + call_result = self._accounts_reports_generate(dry_run, &mut err); + } else if self.opt.cmd_reports_saved_generate { + call_result = self._accounts_reports_saved_generate(dry_run, &mut err); + } else if self.opt.cmd_reports_saved_list { + call_result = self._accounts_reports_saved_list(dry_run, &mut err); + } else if self.opt.cmd_savedadstyles_get { + call_result = self._accounts_savedadstyles_get(dry_run, &mut err); + } else if self.opt.cmd_savedadstyles_list { + call_result = self._accounts_savedadstyles_list(dry_run, &mut err); + } else if self.opt.cmd_urlchannels_list { + call_result = self._accounts_urlchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_adclients { + if self.opt.cmd_list { + call_result = self._adclients_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_adunits { + if self.opt.cmd_customchannels_list { + call_result = self._adunits_customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._adunits_get(dry_run, &mut err); + } else if self.opt.cmd_get_ad_code { + call_result = self._adunits_get_ad_code(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._adunits_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_alerts { + if self.opt.cmd_delete { + call_result = self._alerts_delete(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._alerts_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_customchannels { + if self.opt.cmd_adunits_list { + call_result = self._customchannels_adunits_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._customchannels_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._customchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_metadata { + if self.opt.cmd_dimensions_list { + call_result = self._metadata_dimensions_list(dry_run, &mut err); + } else if self.opt.cmd_metrics_list { + call_result = self._metadata_metrics_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_payments { + if self.opt.cmd_list { + call_result = self._payments_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_generate { + call_result = self._reports_generate(dry_run, &mut err); + } else if self.opt.cmd_saved_generate { + call_result = self._reports_saved_generate(dry_run, &mut err); + } else if self.opt.cmd_saved_list { + call_result = self._reports_saved_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_savedadstyles { + if self.opt.cmd_get { + call_result = self._savedadstyles_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._savedadstyles_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_urlchannels { + if self.opt.cmd_list { + call_result = self._urlchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "adsense1d4-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "adsense1d4", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AdSense::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/Cargo.toml b/gen/adsensehost4d1-cli/Cargo.toml new file mode 100644 index 00000000000..3fb2c6aa2bd --- /dev/null +++ b/gen/adsensehost4d1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-adsensehost4d1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with AdSense Host (protocol v4.1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/adsensehost4d1-cli" +homepage = "https://developers.google.com/adsense/host/" +documentation = "http://byron.github.io/google-apis-rs/google_adsensehost4d1_cli" +license = "MIT" +keywords = ["adsensehost", "google", "cli"] + +[[bin]] +name = "adsensehost4d1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-adsensehost4d1] +path = "../adsensehost4d1" diff --git a/gen/adsensehost4d1-cli/LICENSE.md b/gen/adsensehost4d1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/adsensehost4d1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/adsensehost4d1-cli/README.md b/gen/adsensehost4d1-cli/README.md new file mode 100644 index 00000000000..cc58d0fdf2c --- /dev/null +++ b/gen/adsensehost4d1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ADSENSEHOST:V4.1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/mkdocs.yml b/gen/adsensehost4d1-cli/mkdocs.yml new file mode 100644 index 00000000000..12de3662b9d --- /dev/null +++ b/gen/adsensehost4d1-cli/mkdocs.yml @@ -0,0 +1,42 @@ +site_name: AdSense Host v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-adsensehost4d1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/adsensehost4d1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_adclients-get.md', 'Accounts', 'Adclients Get'] +- ['accounts_adclients-list.md', 'Accounts', 'Adclients List'] +- ['accounts_adunits-delete.md', 'Accounts', 'Adunits Delete'] +- ['accounts_adunits-get.md', 'Accounts', 'Adunits Get'] +- ['accounts_adunits-get-ad-code.md', 'Accounts', 'Adunits Get Ad Code'] +- ['accounts_adunits-insert.md', 'Accounts', 'Adunits Insert'] +- ['accounts_adunits-list.md', 'Accounts', 'Adunits List'] +- ['accounts_adunits-patch.md', 'Accounts', 'Adunits Patch'] +- ['accounts_adunits-update.md', 'Accounts', 'Adunits Update'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_reports-generate.md', 'Accounts', 'Reports Generate'] +- ['adclients_get.md', 'Adclients', 'Get'] +- ['adclients_list.md', 'Adclients', 'List'] +- ['associationsessions_start.md', 'Associationsessions', 'Start'] +- ['associationsessions_verify.md', 'Associationsessions', 'Verify'] +- ['customchannels_delete.md', 'Customchannels', 'Delete'] +- ['customchannels_get.md', 'Customchannels', 'Get'] +- ['customchannels_insert.md', 'Customchannels', 'Insert'] +- ['customchannels_list.md', 'Customchannels', 'List'] +- ['customchannels_patch.md', 'Customchannels', 'Patch'] +- ['customchannels_update.md', 'Customchannels', 'Update'] +- ['reports_generate.md', 'Reports', 'Generate'] +- ['urlchannels_delete.md', 'Urlchannels', 'Delete'] +- ['urlchannels_insert.md', 'Urlchannels', 'Insert'] +- ['urlchannels_list.md', 'Urlchannels', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/adsensehost4d1-cli/src/cmn.rs b/gen/adsensehost4d1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/adsensehost4d1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/adsensehost4d1-cli/src/main.rs b/gen/adsensehost4d1-cli/src/main.rs new file mode 100644 index 00000000000..5144c3b985e --- /dev/null +++ b/gen/adsensehost4d1-cli/src/main.rs @@ -0,0 +1,1906 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_adsensehost4d1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + adsensehost4d1 [options] accounts adclients-get [-p ]... [-o ] + adsensehost4d1 [options] accounts adclients-list [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-delete [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-get [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-get-ad-code [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-list [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-patch -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts adunits-update -r ... [-p ]... [-o ] + adsensehost4d1 [options] accounts get [-p ]... [-o ] + adsensehost4d1 [options] accounts list [-p ]... [-o ] + adsensehost4d1 [options] accounts reports-generate [-p ]... [-o ] + adsensehost4d1 [options] adclients get [-p ]... [-o ] + adsensehost4d1 [options] adclients list [-p ]... [-o ] + adsensehost4d1 [options] associationsessions start [-p ]... [-o ] + adsensehost4d1 [options] associationsessions verify [-p ]... [-o ] + adsensehost4d1 [options] customchannels delete [-p ]... [-o ] + adsensehost4d1 [options] customchannels get [-p ]... [-o ] + adsensehost4d1 [options] customchannels insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] customchannels list [-p ]... [-o ] + adsensehost4d1 [options] customchannels patch -r ... [-p ]... [-o ] + adsensehost4d1 [options] customchannels update -r ... [-p ]... [-o ] + adsensehost4d1 [options] reports generate [-p ]... [-o ] + adsensehost4d1 [options] urlchannels delete [-p ]... [-o ] + adsensehost4d1 [options] urlchannels insert -r ... [-p ]... [-o ] + adsensehost4d1 [options] urlchannels list [-p ]... [-o ] + adsensehost4d1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AdSenseHost>, +} + + +impl Engine { + fn _accounts_adclients_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adclients_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_delete(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_get_ad_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_get_ad_code(&self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "host-custom-channel-id" => { + call = call.add_host_custom_channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AdUnit = Default::default(); + let mut call = self.hub.accounts().adunits_insert(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.color = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.url = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.size" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = value.unwrap_or("").to_string(); + }, + "custom-style.colors.url" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.url = value.unwrap_or("").to_string(); + }, + "custom-style.colors.text" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.text = value.unwrap_or("").to_string(); + }, + "custom-style.colors.border" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.border = value.unwrap_or("").to_string(); + }, + "custom-style.colors.background" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.background = value.unwrap_or("").to_string(); + }, + "custom-style.colors.title" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.title = value.unwrap_or("").to_string(); + }, + "custom-style.font.family" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.family = value.unwrap_or("").to_string(); + }, + "custom-style.font.size" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.size = value.unwrap_or("").to_string(); + }, + "custom-style.kind" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().adunits_list(&self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-inactive" => { + call = call.include_inactive(arg_from_str(value.unwrap_or("false"), err, "include-inactive", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AdUnit = Default::default(); + let mut call = self.hub.accounts().adunits_patch(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id, &self.opt.arg_ad_unit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.color = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.url = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.size" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = value.unwrap_or("").to_string(); + }, + "custom-style.colors.url" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.url = value.unwrap_or("").to_string(); + }, + "custom-style.colors.text" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.text = value.unwrap_or("").to_string(); + }, + "custom-style.colors.border" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.border = value.unwrap_or("").to_string(); + }, + "custom-style.colors.background" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.background = value.unwrap_or("").to_string(); + }, + "custom-style.colors.title" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.title = value.unwrap_or("").to_string(); + }, + "custom-style.font.family" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.family = value.unwrap_or("").to_string(); + }, + "custom-style.font.size" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.size = value.unwrap_or("").to_string(); + }, + "custom-style.kind" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_adunits_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AdUnit = Default::default(); + let mut call = self.hub.accounts().adunits_update(&request, &self.opt.arg_account_id, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_ads_settings_init(request: &mut api::AdUnit) { + if request.content_ads_settings.is_none() { + request.content_ads_settings = Some(Default::default()); + } + } + + fn request_custom_style_init(request: &mut api::AdUnit) { + if request.custom_style.is_none() { + request.custom_style = Some(Default::default()); + } + } + + fn request_mobile_content_ads_settings_init(request: &mut api::AdUnit) { + if request.mobile_content_ads_settings.is_none() { + request.mobile_content_ads_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-ads-settings.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.color" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.color = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.url" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.url = value.unwrap_or("").to_string(); + }, + "content-ads-settings.backup-option.type" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().backup_option.type_ = value.unwrap_or("").to_string(); + }, + "content-ads-settings.size" => { + request_content_ads_settings_init(&mut request); + request.content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "id" => { + request_content_ads_settings_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "mobile-content-ads-settings.scripting-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().scripting_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.type" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.markup-language" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().markup_language = value.unwrap_or("").to_string(); + }, + "mobile-content-ads-settings.size" => { + request_mobile_content_ads_settings_init(&mut request); + request.mobile_content_ads_settings.as_mut().unwrap().size = value.unwrap_or("").to_string(); + }, + "custom-style.corners" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().corners = value.unwrap_or("").to_string(); + }, + "custom-style.colors.url" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.url = value.unwrap_or("").to_string(); + }, + "custom-style.colors.text" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.text = value.unwrap_or("").to_string(); + }, + "custom-style.colors.border" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.border = value.unwrap_or("").to_string(); + }, + "custom-style.colors.background" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.background = value.unwrap_or("").to_string(); + }, + "custom-style.colors.title" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().colors.title = value.unwrap_or("").to_string(); + }, + "custom-style.font.family" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.family = value.unwrap_or("").to_string(); + }, + "custom-style.font.size" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().font.size = value.unwrap_or("").to_string(); + }, + "custom-style.kind" => { + request_custom_style_init(&mut request); + request.custom_style.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(&self.opt.arg_filter_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().reports_generate(&self.opt.arg_account_id, &self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adclients_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adclients().get(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _adclients_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.adclients().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _associationsessions_start(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.associationsessions().start(&self.opt.arg_product_code, &self.opt.arg_website_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "website-locale" => { + call = call.website_locale(value.unwrap_or("")); + }, + "user-locale" => { + call = call.user_locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _associationsessions_verify(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.associationsessions().verify(&self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().delete(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().get(&self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomChannel = Default::default(); + let mut call = self.hub.customchannels().insert(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.customchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomChannel = Default::default(); + let mut call = self.hub.customchannels().patch(&request, &self.opt.arg_ad_client_id, &self.opt.arg_custom_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customchannels_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomChannel = Default::default(); + let mut call = self.hub.customchannels().update(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "code" => { + request.code = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.reports().generate(&self.opt.arg_start_date, &self.opt.arg_end_date); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.add_sort(value.unwrap_or("")); + }, + "metric" => { + call = call.add_metric(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "dimension" => { + call = call.add_dimension(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.urlchannels().delete(&self.opt.arg_ad_client_id, &self.opt.arg_url_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlChannel = Default::default(); + let mut call = self.hub.urlchannels().insert(&request, &self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "url-pattern" => { + request.url_pattern = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlchannels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.urlchannels().list(&self.opt.arg_ad_client_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_adclients_get { + call_result = self._accounts_adclients_get(dry_run, &mut err); + } else if self.opt.cmd_adclients_list { + call_result = self._accounts_adclients_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_delete { + call_result = self._accounts_adunits_delete(dry_run, &mut err); + } else if self.opt.cmd_adunits_get { + call_result = self._accounts_adunits_get(dry_run, &mut err); + } else if self.opt.cmd_adunits_get_ad_code { + call_result = self._accounts_adunits_get_ad_code(dry_run, &mut err); + } else if self.opt.cmd_adunits_insert { + call_result = self._accounts_adunits_insert(dry_run, &mut err); + } else if self.opt.cmd_adunits_list { + call_result = self._accounts_adunits_list(dry_run, &mut err); + } else if self.opt.cmd_adunits_patch { + call_result = self._accounts_adunits_patch(dry_run, &mut err); + } else if self.opt.cmd_adunits_update { + call_result = self._accounts_adunits_update(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_reports_generate { + call_result = self._accounts_reports_generate(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_adclients { + if self.opt.cmd_get { + call_result = self._adclients_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._adclients_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_associationsessions { + if self.opt.cmd_start { + call_result = self._associationsessions_start(dry_run, &mut err); + } else if self.opt.cmd_verify { + call_result = self._associationsessions_verify(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_customchannels { + if self.opt.cmd_delete { + call_result = self._customchannels_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._customchannels_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._customchannels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._customchannels_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._customchannels_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._customchannels_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_generate { + call_result = self._reports_generate(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_urlchannels { + if self.opt.cmd_delete { + call_result = self._urlchannels_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._urlchannels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._urlchannels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "adsensehost4d1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "adsensehost4d1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AdSenseHost::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/analytics3-cli/Cargo.toml b/gen/analytics3-cli/Cargo.toml new file mode 100644 index 00000000000..9fc8986b22b --- /dev/null +++ b/gen/analytics3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-analytics3-cli" +version = "0.0.1+20150308" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with analytics (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/analytics3-cli" +homepage = "https://developers.google.com/analytics/" +documentation = "http://byron.github.io/google-apis-rs/google_analytics3_cli" +license = "MIT" +keywords = ["analytics", "google", "cli"] + +[[bin]] +name = "analytics3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-analytics3] +path = "../analytics3" diff --git a/gen/analytics3-cli/LICENSE.md b/gen/analytics3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/analytics3-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/analytics3-cli/README.md b/gen/analytics3-cli/README.md new file mode 100644 index 00000000000..d68546a4807 --- /dev/null +++ b/gen/analytics3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ANALYTICS:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/analytics3-cli/mkdocs.yml b/gen/analytics3-cli/mkdocs.yml new file mode 100644 index 00000000000..92e7661763a --- /dev/null +++ b/gen/analytics3-cli/mkdocs.yml @@ -0,0 +1,94 @@ +site_name: analytics v0.0.1+20150308 +site_url: http://byron.github.io/google-apis-rs/google-analytics3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/analytics3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['data_ga-get.md', 'Data', 'Ga Get'] +- ['data_mcf-get.md', 'Data', 'Mcf Get'] +- ['data_realtime-get.md', 'Data', 'Realtime Get'] +- ['management_account-summaries-list.md', 'Management', 'Account Summaries List'] +- ['management_account-user-links-delete.md', 'Management', 'Account User Links Delete'] +- ['management_account-user-links-insert.md', 'Management', 'Account User Links Insert'] +- ['management_account-user-links-list.md', 'Management', 'Account User Links List'] +- ['management_account-user-links-update.md', 'Management', 'Account User Links Update'] +- ['management_accounts-list.md', 'Management', 'Accounts List'] +- ['management_custom-data-sources-list.md', 'Management', 'Custom Data Sources List'] +- ['management_custom-dimensions-get.md', 'Management', 'Custom Dimensions Get'] +- ['management_custom-dimensions-insert.md', 'Management', 'Custom Dimensions Insert'] +- ['management_custom-dimensions-list.md', 'Management', 'Custom Dimensions List'] +- ['management_custom-dimensions-patch.md', 'Management', 'Custom Dimensions Patch'] +- ['management_custom-dimensions-update.md', 'Management', 'Custom Dimensions Update'] +- ['management_custom-metrics-get.md', 'Management', 'Custom Metrics Get'] +- ['management_custom-metrics-insert.md', 'Management', 'Custom Metrics Insert'] +- ['management_custom-metrics-list.md', 'Management', 'Custom Metrics List'] +- ['management_custom-metrics-patch.md', 'Management', 'Custom Metrics Patch'] +- ['management_custom-metrics-update.md', 'Management', 'Custom Metrics Update'] +- ['management_experiments-delete.md', 'Management', 'Experiments Delete'] +- ['management_experiments-get.md', 'Management', 'Experiments Get'] +- ['management_experiments-insert.md', 'Management', 'Experiments Insert'] +- ['management_experiments-list.md', 'Management', 'Experiments List'] +- ['management_experiments-patch.md', 'Management', 'Experiments Patch'] +- ['management_experiments-update.md', 'Management', 'Experiments Update'] +- ['management_filters-delete.md', 'Management', 'Filters Delete'] +- ['management_filters-get.md', 'Management', 'Filters Get'] +- ['management_filters-insert.md', 'Management', 'Filters Insert'] +- ['management_filters-list.md', 'Management', 'Filters List'] +- ['management_filters-patch.md', 'Management', 'Filters Patch'] +- ['management_filters-update.md', 'Management', 'Filters Update'] +- ['management_goals-get.md', 'Management', 'Goals Get'] +- ['management_goals-insert.md', 'Management', 'Goals Insert'] +- ['management_goals-list.md', 'Management', 'Goals List'] +- ['management_goals-patch.md', 'Management', 'Goals Patch'] +- ['management_goals-update.md', 'Management', 'Goals Update'] +- ['management_profile-filter-links-delete.md', 'Management', 'Profile Filter Links Delete'] +- ['management_profile-filter-links-get.md', 'Management', 'Profile Filter Links Get'] +- ['management_profile-filter-links-insert.md', 'Management', 'Profile Filter Links Insert'] +- ['management_profile-filter-links-list.md', 'Management', 'Profile Filter Links List'] +- ['management_profile-filter-links-patch.md', 'Management', 'Profile Filter Links Patch'] +- ['management_profile-filter-links-update.md', 'Management', 'Profile Filter Links Update'] +- ['management_profile-user-links-delete.md', 'Management', 'Profile User Links Delete'] +- ['management_profile-user-links-insert.md', 'Management', 'Profile User Links Insert'] +- ['management_profile-user-links-list.md', 'Management', 'Profile User Links List'] +- ['management_profile-user-links-update.md', 'Management', 'Profile User Links Update'] +- ['management_profiles-delete.md', 'Management', 'Profiles Delete'] +- ['management_profiles-get.md', 'Management', 'Profiles Get'] +- ['management_profiles-insert.md', 'Management', 'Profiles Insert'] +- ['management_profiles-list.md', 'Management', 'Profiles List'] +- ['management_profiles-patch.md', 'Management', 'Profiles Patch'] +- ['management_profiles-update.md', 'Management', 'Profiles Update'] +- ['management_segments-list.md', 'Management', 'Segments List'] +- ['management_unsampled-reports-get.md', 'Management', 'Unsampled Reports Get'] +- ['management_unsampled-reports-insert.md', 'Management', 'Unsampled Reports Insert'] +- ['management_unsampled-reports-list.md', 'Management', 'Unsampled Reports List'] +- ['management_uploads-delete-upload-data.md', 'Management', 'Uploads Delete Upload Data'] +- ['management_uploads-get.md', 'Management', 'Uploads Get'] +- ['management_uploads-list.md', 'Management', 'Uploads List'] +- ['management_uploads-upload-data.md', 'Management', 'Uploads Upload Data'] +- ['management_web-property-ad-words-links-delete.md', 'Management', 'Web Property Ad Words Links Delete'] +- ['management_web-property-ad-words-links-get.md', 'Management', 'Web Property Ad Words Links Get'] +- ['management_web-property-ad-words-links-insert.md', 'Management', 'Web Property Ad Words Links Insert'] +- ['management_web-property-ad-words-links-list.md', 'Management', 'Web Property Ad Words Links List'] +- ['management_web-property-ad-words-links-patch.md', 'Management', 'Web Property Ad Words Links Patch'] +- ['management_web-property-ad-words-links-update.md', 'Management', 'Web Property Ad Words Links Update'] +- ['management_webproperties-get.md', 'Management', 'Webproperties Get'] +- ['management_webproperties-insert.md', 'Management', 'Webproperties Insert'] +- ['management_webproperties-list.md', 'Management', 'Webproperties List'] +- ['management_webproperties-patch.md', 'Management', 'Webproperties Patch'] +- ['management_webproperties-update.md', 'Management', 'Webproperties Update'] +- ['management_webproperty-user-links-delete.md', 'Management', 'Webproperty User Links Delete'] +- ['management_webproperty-user-links-insert.md', 'Management', 'Webproperty User Links Insert'] +- ['management_webproperty-user-links-list.md', 'Management', 'Webproperty User Links List'] +- ['management_webproperty-user-links-update.md', 'Management', 'Webproperty User Links Update'] +- ['metadata_columns-list.md', 'Metadata', 'Columns List'] +- ['provisioning_create-account-ticket.md', 'Provisioning', 'Create Account Ticket'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/analytics3-cli/src/cmn.rs b/gen/analytics3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/analytics3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/analytics3-cli/src/main.rs b/gen/analytics3-cli/src/main.rs new file mode 100644 index 00000000000..b20c70143ff --- /dev/null +++ b/gen/analytics3-cli/src/main.rs @@ -0,0 +1,8003 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_analytics3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + analytics3 [options] data ga-get [-p ]... [-o ] + analytics3 [options] data mcf-get [-p ]... [-o ] + analytics3 [options] data realtime-get [-p ]... [-o ] + analytics3 [options] management account-summaries-list [-p ]... [-o ] + analytics3 [options] management account-user-links-delete [-p ]... + analytics3 [options] management account-user-links-insert -r ... [-p ]... [-o ] + analytics3 [options] management account-user-links-list [-p ]... [-o ] + analytics3 [options] management account-user-links-update -r ... [-p ]... [-o ] + analytics3 [options] management accounts-list [-p ]... [-o ] + analytics3 [options] management custom-data-sources-list [-p ]... [-o ] + analytics3 [options] management custom-dimensions-get [-p ]... [-o ] + analytics3 [options] management custom-dimensions-insert -r ... [-p ]... [-o ] + analytics3 [options] management custom-dimensions-list [-p ]... [-o ] + analytics3 [options] management custom-dimensions-patch -r ... [-p ]... [-o ] + analytics3 [options] management custom-dimensions-update -r ... [-p ]... [-o ] + analytics3 [options] management custom-metrics-get [-p ]... [-o ] + analytics3 [options] management custom-metrics-insert -r ... [-p ]... [-o ] + analytics3 [options] management custom-metrics-list [-p ]... [-o ] + analytics3 [options] management custom-metrics-patch -r ... [-p ]... [-o ] + analytics3 [options] management custom-metrics-update -r ... [-p ]... [-o ] + analytics3 [options] management experiments-delete [-p ]... + analytics3 [options] management experiments-get [-p ]... [-o ] + analytics3 [options] management experiments-insert -r ... [-p ]... [-o ] + analytics3 [options] management experiments-list [-p ]... [-o ] + analytics3 [options] management experiments-patch -r ... [-p ]... [-o ] + analytics3 [options] management experiments-update -r ... [-p ]... [-o ] + analytics3 [options] management filters-delete [-p ]... [-o ] + analytics3 [options] management filters-get [-p ]... [-o ] + analytics3 [options] management filters-insert -r ... [-p ]... [-o ] + analytics3 [options] management filters-list [-p ]... [-o ] + analytics3 [options] management filters-patch -r ... [-p ]... [-o ] + analytics3 [options] management filters-update -r ... [-p ]... [-o ] + analytics3 [options] management goals-get [-p ]... [-o ] + analytics3 [options] management goals-insert -r ... [-p ]... [-o ] + analytics3 [options] management goals-list [-p ]... [-o ] + analytics3 [options] management goals-patch -r ... [-p ]... [-o ] + analytics3 [options] management goals-update -r ... [-p ]... [-o ] + analytics3 [options] management profile-filter-links-delete [-p ]... + analytics3 [options] management profile-filter-links-get [-p ]... [-o ] + analytics3 [options] management profile-filter-links-insert -r ... [-p ]... [-o ] + analytics3 [options] management profile-filter-links-list [-p ]... [-o ] + analytics3 [options] management profile-filter-links-patch -r ... [-p ]... [-o ] + analytics3 [options] management profile-filter-links-update -r ... [-p ]... [-o ] + analytics3 [options] management profile-user-links-delete [-p ]... + analytics3 [options] management profile-user-links-insert -r ... [-p ]... [-o ] + analytics3 [options] management profile-user-links-list [-p ]... [-o ] + analytics3 [options] management profile-user-links-update -r ... [-p ]... [-o ] + analytics3 [options] management profiles-delete [-p ]... + analytics3 [options] management profiles-get [-p ]... [-o ] + analytics3 [options] management profiles-insert -r ... [-p ]... [-o ] + analytics3 [options] management profiles-list [-p ]... [-o ] + analytics3 [options] management profiles-patch -r ... [-p ]... [-o ] + analytics3 [options] management profiles-update -r ... [-p ]... [-o ] + analytics3 [options] management segments-list [-p ]... [-o ] + analytics3 [options] management unsampled-reports-get [-p ]... [-o ] + analytics3 [options] management unsampled-reports-insert -r ... [-p ]... [-o ] + analytics3 [options] management unsampled-reports-list [-p ]... [-o ] + analytics3 [options] management uploads-delete-upload-data -r ... [-p ]... + analytics3 [options] management uploads-get [-p ]... [-o ] + analytics3 [options] management uploads-list [-p ]... [-o ] + analytics3 [options] management uploads-upload-data -u (simple|resumable) [-p ]... [-o ] + analytics3 [options] management web-property-ad-words-links-delete [-p ]... + analytics3 [options] management web-property-ad-words-links-get [-p ]... [-o ] + analytics3 [options] management web-property-ad-words-links-insert -r ... [-p ]... [-o ] + analytics3 [options] management web-property-ad-words-links-list [-p ]... [-o ] + analytics3 [options] management web-property-ad-words-links-patch -r ... [-p ]... [-o ] + analytics3 [options] management web-property-ad-words-links-update -r ... [-p ]... [-o ] + analytics3 [options] management webproperties-get [-p ]... [-o ] + analytics3 [options] management webproperties-insert -r ... [-p ]... [-o ] + analytics3 [options] management webproperties-list [-p ]... [-o ] + analytics3 [options] management webproperties-patch -r ... [-p ]... [-o ] + analytics3 [options] management webproperties-update -r ... [-p ]... [-o ] + analytics3 [options] management webproperty-user-links-delete [-p ]... + analytics3 [options] management webproperty-user-links-insert -r ... [-p ]... [-o ] + analytics3 [options] management webproperty-user-links-list [-p ]... [-o ] + analytics3 [options] management webproperty-user-links-update -r ... [-p ]... [-o ] + analytics3 [options] metadata columns-list [-p ]... [-o ] + analytics3 [options] provisioning create-account-ticket -r ... [-p ]... [-o ] + analytics3 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Analytics>, +} + + +impl Engine { + fn _data_ga_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.data().ga_get(&self.opt.arg_ids, &self.opt.arg_start_date, &self.opt.arg_end_date, &self.opt.arg_metrics); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "segment" => { + call = call.segment(value.unwrap_or("")); + }, + "sampling-level" => { + call = call.sampling_level(value.unwrap_or("")); + }, + "output" => { + call = call.output(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "dimensions" => { + call = call.dimensions(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _data_mcf_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.data().mcf_get(&self.opt.arg_ids, &self.opt.arg_start_date, &self.opt.arg_end_date, &self.opt.arg_metrics); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "sampling-level" => { + call = call.sampling_level(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "dimensions" => { + call = call.dimensions(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _data_realtime_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.data().realtime_get(&self.opt.arg_ids, &self.opt.arg_metrics); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "dimensions" => { + call = call.dimensions(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_account_summaries_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().account_summaries_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_account_user_links_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().account_user_links_delete(&self.opt.arg_account_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_account_user_links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().account_user_links_insert(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_account_user_links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().account_user_links_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_account_user_links_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().account_user_links_update(&request, &self.opt.arg_account_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().accounts_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_data_sources_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().custom_data_sources_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_dimensions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().custom_dimensions_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_dimension_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_dimensions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomDimension = Default::default(); + let mut call = self.hub.management().custom_dimensions_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomDimension) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_dimensions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().custom_dimensions_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_dimensions_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomDimension = Default::default(); + let mut call = self.hub.management().custom_dimensions_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_dimension_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ignore-custom-data-source-links" => { + call = call.ignore_custom_data_source_links(arg_from_str(value.unwrap_or("false"), err, "ignore-custom-data-source-links", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomDimension) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_dimensions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomDimension = Default::default(); + let mut call = self.hub.management().custom_dimensions_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_dimension_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ignore-custom-data-source-links" => { + call = call.ignore_custom_data_source_links(arg_from_str(value.unwrap_or("false"), err, "ignore-custom-data-source-links", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomDimension) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_metrics_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().custom_metrics_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_metric_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_metrics_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomMetric = Default::default(); + let mut call = self.hub.management().custom_metrics_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomMetric) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "max-value" => { + request.max_value = Some(value.unwrap_or("").to_string()); + }, + "min-value" => { + request.min_value = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_metrics_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().custom_metrics_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_metrics_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomMetric = Default::default(); + let mut call = self.hub.management().custom_metrics_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_metric_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ignore-custom-data-source-links" => { + call = call.ignore_custom_data_source_links(arg_from_str(value.unwrap_or("false"), err, "ignore-custom-data-source-links", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomMetric) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "max-value" => { + request.max_value = Some(value.unwrap_or("").to_string()); + }, + "min-value" => { + request.min_value = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_custom_metrics_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CustomMetric = Default::default(); + let mut call = self.hub.management().custom_metrics_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_metric_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ignore-custom-data-source-links" => { + call = call.ignore_custom_data_source_links(arg_from_str(value.unwrap_or("false"), err, "ignore-custom-data-source-links", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::CustomMetric) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "index" => { + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "max-value" => { + request.max_value = Some(value.unwrap_or("").to_string()); + }, + "min-value" => { + request.min_value = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "scope" => { + request.scope = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_experiments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().experiments_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_experiment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_experiments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().experiments_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_experiment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_experiments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Experiment = Default::default(); + let mut call = self.hub.management().experiments_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::Experiment) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "traffic-coverage" => { + request.traffic_coverage = Some(arg_from_str(value.unwrap_or("0.0"), err, "traffic-coverage", "number")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "optimization-type" => { + request.optimization_type = Some(value.unwrap_or("").to_string()); + }, + "objective-metric" => { + request.objective_metric = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "equal-weighting" => { + request.equal_weighting = Some(arg_from_str(value.unwrap_or("false"), err, "equal-weighting", "boolean")); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "snippet" => { + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "editable-in-ga-ui" => { + request.editable_in_ga_ui = Some(arg_from_str(value.unwrap_or("false"), err, "editable-in-ga-ui", "boolean")); + }, + "rewrite-variation-urls-as-original" => { + request.rewrite_variation_urls_as_original = Some(arg_from_str(value.unwrap_or("false"), err, "rewrite-variation-urls-as-original", "boolean")); + }, + "serving-framework" => { + request.serving_framework = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "winner-confidence-level" => { + request.winner_confidence_level = Some(arg_from_str(value.unwrap_or("0.0"), err, "winner-confidence-level", "number")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "winner-found" => { + request.winner_found = Some(arg_from_str(value.unwrap_or("false"), err, "winner-found", "boolean")); + }, + "reason-experiment-ended" => { + request.reason_experiment_ended = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "minimum-experiment-length-in-days" => { + request.minimum_experiment_length_in_days = Some(arg_from_str(value.unwrap_or("-0"), err, "minimum-experiment-length-in-days", "integer")); + }, + "profile-id" => { + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "end-time" => { + request_parent_link_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_experiments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().experiments_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_experiments_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Experiment = Default::default(); + let mut call = self.hub.management().experiments_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_experiment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::Experiment) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "traffic-coverage" => { + request.traffic_coverage = Some(arg_from_str(value.unwrap_or("0.0"), err, "traffic-coverage", "number")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "optimization-type" => { + request.optimization_type = Some(value.unwrap_or("").to_string()); + }, + "objective-metric" => { + request.objective_metric = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "equal-weighting" => { + request.equal_weighting = Some(arg_from_str(value.unwrap_or("false"), err, "equal-weighting", "boolean")); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "snippet" => { + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "editable-in-ga-ui" => { + request.editable_in_ga_ui = Some(arg_from_str(value.unwrap_or("false"), err, "editable-in-ga-ui", "boolean")); + }, + "rewrite-variation-urls-as-original" => { + request.rewrite_variation_urls_as_original = Some(arg_from_str(value.unwrap_or("false"), err, "rewrite-variation-urls-as-original", "boolean")); + }, + "serving-framework" => { + request.serving_framework = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "winner-confidence-level" => { + request.winner_confidence_level = Some(arg_from_str(value.unwrap_or("0.0"), err, "winner-confidence-level", "number")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "winner-found" => { + request.winner_found = Some(arg_from_str(value.unwrap_or("false"), err, "winner-found", "boolean")); + }, + "reason-experiment-ended" => { + request.reason_experiment_ended = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "minimum-experiment-length-in-days" => { + request.minimum_experiment_length_in_days = Some(arg_from_str(value.unwrap_or("-0"), err, "minimum-experiment-length-in-days", "integer")); + }, + "profile-id" => { + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "end-time" => { + request_parent_link_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_experiments_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Experiment = Default::default(); + let mut call = self.hub.management().experiments_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_experiment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_parent_link_init(request: &mut api::Experiment) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "traffic-coverage" => { + request.traffic_coverage = Some(arg_from_str(value.unwrap_or("0.0"), err, "traffic-coverage", "number")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "optimization-type" => { + request.optimization_type = Some(value.unwrap_or("").to_string()); + }, + "objective-metric" => { + request.objective_metric = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "equal-weighting" => { + request.equal_weighting = Some(arg_from_str(value.unwrap_or("false"), err, "equal-weighting", "boolean")); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "snippet" => { + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "editable-in-ga-ui" => { + request.editable_in_ga_ui = Some(arg_from_str(value.unwrap_or("false"), err, "editable-in-ga-ui", "boolean")); + }, + "rewrite-variation-urls-as-original" => { + request.rewrite_variation_urls_as_original = Some(arg_from_str(value.unwrap_or("false"), err, "rewrite-variation-urls-as-original", "boolean")); + }, + "serving-framework" => { + request.serving_framework = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "winner-confidence-level" => { + request.winner_confidence_level = Some(arg_from_str(value.unwrap_or("0.0"), err, "winner-confidence-level", "number")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "winner-found" => { + request.winner_found = Some(arg_from_str(value.unwrap_or("false"), err, "winner-found", "boolean")); + }, + "reason-experiment-ended" => { + request.reason_experiment_ended = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "minimum-experiment-length-in-days" => { + request.minimum_experiment_length_in_days = Some(arg_from_str(value.unwrap_or("-0"), err, "minimum-experiment-length-in-days", "integer")); + }, + "profile-id" => { + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "end-time" => { + request_parent_link_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().filters_delete(&self.opt.arg_account_id, &self.opt.arg_filter_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().filters_get(&self.opt.arg_account_id, &self.opt.arg_filter_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Filter = Default::default(); + let mut call = self.hub.management().filters_insert(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advanced_details_init(request: &mut api::Filter) { + if request.advanced_details.is_none() { + request.advanced_details = Some(Default::default()); + } + } + + fn request_exclude_details_init(request: &mut api::Filter) { + if request.exclude_details.is_none() { + request.exclude_details = Some(Default::default()); + } + } + + fn request_include_details_init(request: &mut api::Filter) { + if request.include_details.is_none() { + request.include_details = Some(Default::default()); + } + } + + fn request_lowercase_details_init(request: &mut api::Filter) { + if request.lowercase_details.is_none() { + request.lowercase_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Filter) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_search_and_replace_details_init(request: &mut api::Filter) { + if request.search_and_replace_details.is_none() { + request.search_and_replace_details = Some(Default::default()); + } + } + + fn request_uppercase_details_init(request: &mut api::Filter) { + if request.uppercase_details.is_none() { + request.uppercase_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "uppercase-details.field" => { + request_uppercase_details_init(&mut request); + request.uppercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "updated" => { + request_uppercase_details_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "advanced-details.extract-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_b = value.unwrap_or("").to_string(); + }, + "advanced-details.override-output-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().override_output_field = arg_from_str(value.unwrap_or("false"), err, "advanced-details.override-output-field", "boolean"); + }, + "advanced-details.field-a-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-a-required", "boolean"); + }, + "advanced-details.output-constructor" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_constructor = value.unwrap_or("").to_string(); + }, + "advanced-details.field-b-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-b-required", "boolean"); + }, + "advanced-details.case-sensitive" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "advanced-details.case-sensitive", "boolean"); + }, + "advanced-details.field-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b = value.unwrap_or("").to_string(); + }, + "advanced-details.field-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a = value.unwrap_or("").to_string(); + }, + "advanced-details.extract-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_a = value.unwrap_or("").to_string(); + }, + "advanced-details.output-to-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_to_field = value.unwrap_or("").to_string(); + }, + "lowercase-details.field" => { + request_lowercase_details_init(&mut request); + request.lowercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.case-sensitive" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "search-and-replace-details.case-sensitive", "boolean"); + }, + "search-and-replace-details.search-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().search_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.replace-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().replace_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.field" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "exclude-details.case-sensitive" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "exclude-details.case-sensitive", "boolean"); + }, + "exclude-details.kind" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "exclude-details.match-type" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "exclude-details.expression-value" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "exclude-details.field" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "include-details.case-sensitive" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "include-details.case-sensitive", "boolean"); + }, + "include-details.kind" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "include-details.match-type" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "include-details.expression-value" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "include-details.field" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().filters_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Filter = Default::default(); + let mut call = self.hub.management().filters_patch(&request, &self.opt.arg_account_id, &self.opt.arg_filter_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advanced_details_init(request: &mut api::Filter) { + if request.advanced_details.is_none() { + request.advanced_details = Some(Default::default()); + } + } + + fn request_exclude_details_init(request: &mut api::Filter) { + if request.exclude_details.is_none() { + request.exclude_details = Some(Default::default()); + } + } + + fn request_include_details_init(request: &mut api::Filter) { + if request.include_details.is_none() { + request.include_details = Some(Default::default()); + } + } + + fn request_lowercase_details_init(request: &mut api::Filter) { + if request.lowercase_details.is_none() { + request.lowercase_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Filter) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_search_and_replace_details_init(request: &mut api::Filter) { + if request.search_and_replace_details.is_none() { + request.search_and_replace_details = Some(Default::default()); + } + } + + fn request_uppercase_details_init(request: &mut api::Filter) { + if request.uppercase_details.is_none() { + request.uppercase_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "uppercase-details.field" => { + request_uppercase_details_init(&mut request); + request.uppercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "updated" => { + request_uppercase_details_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "advanced-details.extract-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_b = value.unwrap_or("").to_string(); + }, + "advanced-details.override-output-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().override_output_field = arg_from_str(value.unwrap_or("false"), err, "advanced-details.override-output-field", "boolean"); + }, + "advanced-details.field-a-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-a-required", "boolean"); + }, + "advanced-details.output-constructor" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_constructor = value.unwrap_or("").to_string(); + }, + "advanced-details.field-b-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-b-required", "boolean"); + }, + "advanced-details.case-sensitive" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "advanced-details.case-sensitive", "boolean"); + }, + "advanced-details.field-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b = value.unwrap_or("").to_string(); + }, + "advanced-details.field-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a = value.unwrap_or("").to_string(); + }, + "advanced-details.extract-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_a = value.unwrap_or("").to_string(); + }, + "advanced-details.output-to-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_to_field = value.unwrap_or("").to_string(); + }, + "lowercase-details.field" => { + request_lowercase_details_init(&mut request); + request.lowercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.case-sensitive" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "search-and-replace-details.case-sensitive", "boolean"); + }, + "search-and-replace-details.search-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().search_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.replace-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().replace_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.field" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "exclude-details.case-sensitive" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "exclude-details.case-sensitive", "boolean"); + }, + "exclude-details.kind" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "exclude-details.match-type" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "exclude-details.expression-value" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "exclude-details.field" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "include-details.case-sensitive" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "include-details.case-sensitive", "boolean"); + }, + "include-details.kind" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "include-details.match-type" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "include-details.expression-value" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "include-details.field" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_filters_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Filter = Default::default(); + let mut call = self.hub.management().filters_update(&request, &self.opt.arg_account_id, &self.opt.arg_filter_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advanced_details_init(request: &mut api::Filter) { + if request.advanced_details.is_none() { + request.advanced_details = Some(Default::default()); + } + } + + fn request_exclude_details_init(request: &mut api::Filter) { + if request.exclude_details.is_none() { + request.exclude_details = Some(Default::default()); + } + } + + fn request_include_details_init(request: &mut api::Filter) { + if request.include_details.is_none() { + request.include_details = Some(Default::default()); + } + } + + fn request_lowercase_details_init(request: &mut api::Filter) { + if request.lowercase_details.is_none() { + request.lowercase_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Filter) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_search_and_replace_details_init(request: &mut api::Filter) { + if request.search_and_replace_details.is_none() { + request.search_and_replace_details = Some(Default::default()); + } + } + + fn request_uppercase_details_init(request: &mut api::Filter) { + if request.uppercase_details.is_none() { + request.uppercase_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "uppercase-details.field" => { + request_uppercase_details_init(&mut request); + request.uppercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "updated" => { + request_uppercase_details_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "advanced-details.extract-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_b = value.unwrap_or("").to_string(); + }, + "advanced-details.override-output-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().override_output_field = arg_from_str(value.unwrap_or("false"), err, "advanced-details.override-output-field", "boolean"); + }, + "advanced-details.field-a-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-a-required", "boolean"); + }, + "advanced-details.output-constructor" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_constructor = value.unwrap_or("").to_string(); + }, + "advanced-details.field-b-required" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b_required = arg_from_str(value.unwrap_or("false"), err, "advanced-details.field-b-required", "boolean"); + }, + "advanced-details.case-sensitive" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "advanced-details.case-sensitive", "boolean"); + }, + "advanced-details.field-b" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_b = value.unwrap_or("").to_string(); + }, + "advanced-details.field-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().field_a = value.unwrap_or("").to_string(); + }, + "advanced-details.extract-a" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().extract_a = value.unwrap_or("").to_string(); + }, + "advanced-details.output-to-field" => { + request_advanced_details_init(&mut request); + request.advanced_details.as_mut().unwrap().output_to_field = value.unwrap_or("").to_string(); + }, + "lowercase-details.field" => { + request_lowercase_details_init(&mut request); + request.lowercase_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.case-sensitive" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "search-and-replace-details.case-sensitive", "boolean"); + }, + "search-and-replace-details.search-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().search_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.replace-string" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().replace_string = value.unwrap_or("").to_string(); + }, + "search-and-replace-details.field" => { + request_search_and_replace_details_init(&mut request); + request.search_and_replace_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "exclude-details.case-sensitive" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "exclude-details.case-sensitive", "boolean"); + }, + "exclude-details.kind" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "exclude-details.match-type" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "exclude-details.expression-value" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "exclude-details.field" => { + request_exclude_details_init(&mut request); + request.exclude_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "include-details.case-sensitive" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "include-details.case-sensitive", "boolean"); + }, + "include-details.kind" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "include-details.match-type" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "include-details.expression-value" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().expression_value = value.unwrap_or("").to_string(); + }, + "include-details.field" => { + request_include_details_init(&mut request); + request.include_details.as_mut().unwrap().field = value.unwrap_or("").to_string(); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_goals_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().goals_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_goal_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_goals_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Goal = Default::default(); + let mut call = self.hub.management().goals_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_event_details_init(request: &mut api::Goal) { + if request.event_details.is_none() { + request.event_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Goal) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_url_destination_details_init(request: &mut api::Goal) { + if request.url_destination_details.is_none() { + request.url_destination_details = Some(Default::default()); + } + } + + fn request_visit_num_pages_details_init(request: &mut api::Goal) { + if request.visit_num_pages_details.is_none() { + request.visit_num_pages_details = Some(Default::default()); + } + } + + fn request_visit_time_on_site_details_init(request: &mut api::Goal) { + if request.visit_time_on_site_details.is_none() { + request.visit_time_on_site_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "visit-time-on-site-details.comparison-type" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-time-on-site-details.comparison-value" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "name" => { + request_visit_time_on_site_details_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_visit_time_on_site_details_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "url-destination-details.url" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "url-destination-details.case-sensitive" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.case-sensitive", "boolean"); + }, + "url-destination-details.match-type" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "url-destination-details.first-step-required" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().first_step_required = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.first-step-required", "boolean"); + }, + "kind" => { + request_url_destination_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request_url_destination_details_init(&mut request); + request.value = Some(arg_from_str(value.unwrap_or("0.0"), err, "value", "number")); + }, + "visit-num-pages-details.comparison-type" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-num-pages-details.comparison-value" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "internal-web-property-id" => { + request_visit_num_pages_details_init(&mut request); + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "event-details.use-event-value" => { + request_event_details_init(&mut request); + request.event_details.as_mut().unwrap().use_event_value = arg_from_str(value.unwrap_or("false"), err, "event-details.use-event-value", "boolean"); + }, + "web-property-id" => { + request_event_details_init(&mut request); + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_event_details_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "profile-id" => { + request_event_details_init(&mut request); + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_goals_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().goals_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_goals_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Goal = Default::default(); + let mut call = self.hub.management().goals_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_goal_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_event_details_init(request: &mut api::Goal) { + if request.event_details.is_none() { + request.event_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Goal) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_url_destination_details_init(request: &mut api::Goal) { + if request.url_destination_details.is_none() { + request.url_destination_details = Some(Default::default()); + } + } + + fn request_visit_num_pages_details_init(request: &mut api::Goal) { + if request.visit_num_pages_details.is_none() { + request.visit_num_pages_details = Some(Default::default()); + } + } + + fn request_visit_time_on_site_details_init(request: &mut api::Goal) { + if request.visit_time_on_site_details.is_none() { + request.visit_time_on_site_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "visit-time-on-site-details.comparison-type" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-time-on-site-details.comparison-value" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "name" => { + request_visit_time_on_site_details_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_visit_time_on_site_details_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "url-destination-details.url" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "url-destination-details.case-sensitive" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.case-sensitive", "boolean"); + }, + "url-destination-details.match-type" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "url-destination-details.first-step-required" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().first_step_required = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.first-step-required", "boolean"); + }, + "kind" => { + request_url_destination_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request_url_destination_details_init(&mut request); + request.value = Some(arg_from_str(value.unwrap_or("0.0"), err, "value", "number")); + }, + "visit-num-pages-details.comparison-type" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-num-pages-details.comparison-value" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "internal-web-property-id" => { + request_visit_num_pages_details_init(&mut request); + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "event-details.use-event-value" => { + request_event_details_init(&mut request); + request.event_details.as_mut().unwrap().use_event_value = arg_from_str(value.unwrap_or("false"), err, "event-details.use-event-value", "boolean"); + }, + "web-property-id" => { + request_event_details_init(&mut request); + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_event_details_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "profile-id" => { + request_event_details_init(&mut request); + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_goals_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Goal = Default::default(); + let mut call = self.hub.management().goals_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_goal_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_event_details_init(request: &mut api::Goal) { + if request.event_details.is_none() { + request.event_details = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Goal) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_url_destination_details_init(request: &mut api::Goal) { + if request.url_destination_details.is_none() { + request.url_destination_details = Some(Default::default()); + } + } + + fn request_visit_num_pages_details_init(request: &mut api::Goal) { + if request.visit_num_pages_details.is_none() { + request.visit_num_pages_details = Some(Default::default()); + } + } + + fn request_visit_time_on_site_details_init(request: &mut api::Goal) { + if request.visit_time_on_site_details.is_none() { + request.visit_time_on_site_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "visit-time-on-site-details.comparison-type" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-time-on-site-details.comparison-value" => { + request_visit_time_on_site_details_init(&mut request); + request.visit_time_on_site_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "name" => { + request_visit_time_on_site_details_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_visit_time_on_site_details_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "url-destination-details.url" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "url-destination-details.case-sensitive" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().case_sensitive = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.case-sensitive", "boolean"); + }, + "url-destination-details.match-type" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().match_type = value.unwrap_or("").to_string(); + }, + "url-destination-details.first-step-required" => { + request_url_destination_details_init(&mut request); + request.url_destination_details.as_mut().unwrap().first_step_required = arg_from_str(value.unwrap_or("false"), err, "url-destination-details.first-step-required", "boolean"); + }, + "kind" => { + request_url_destination_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request_url_destination_details_init(&mut request); + request.value = Some(arg_from_str(value.unwrap_or("0.0"), err, "value", "number")); + }, + "visit-num-pages-details.comparison-type" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_type = value.unwrap_or("").to_string(); + }, + "visit-num-pages-details.comparison-value" => { + request_visit_num_pages_details_init(&mut request); + request.visit_num_pages_details.as_mut().unwrap().comparison_value = value.unwrap_or("").to_string(); + }, + "internal-web-property-id" => { + request_visit_num_pages_details_init(&mut request); + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "event-details.use-event-value" => { + request_event_details_init(&mut request); + request.event_details.as_mut().unwrap().use_event_value = arg_from_str(value.unwrap_or("false"), err, "event-details.use-event-value", "boolean"); + }, + "web-property-id" => { + request_event_details_init(&mut request); + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_event_details_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "profile-id" => { + request_event_details_init(&mut request); + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "type" => { + request_parent_link_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_parent_link_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_parent_link_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_filter_links_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profile_filter_links_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_profile_filter_links_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profile_filter_links_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_filter_links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProfileFilterLink = Default::default(); + let mut call = self.hub.management().profile_filter_links_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_filter_ref_init(request: &mut api::ProfileFilterLink) { + if request.filter_ref.is_none() { + request.filter_ref = Some(Default::default()); + } + } + + fn request_profile_ref_init(request: &mut api::ProfileFilterLink) { + if request.profile_ref.is_none() { + request.profile_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "rank" => { + request.rank = Some(arg_from_str(value.unwrap_or("-0"), err, "rank", "integer")); + }, + "filter-ref.kind" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "filter-ref.href" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "filter-ref.id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "filter-ref.name" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "filter-ref.account-id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "profile-ref.kind" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "profile-ref.name" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "profile-ref.internal-web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().internal_web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.href" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "profile-ref.web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "profile-ref.account-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_profile_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_profile_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_filter_links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profile_filter_links_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_filter_links_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProfileFilterLink = Default::default(); + let mut call = self.hub.management().profile_filter_links_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_filter_ref_init(request: &mut api::ProfileFilterLink) { + if request.filter_ref.is_none() { + request.filter_ref = Some(Default::default()); + } + } + + fn request_profile_ref_init(request: &mut api::ProfileFilterLink) { + if request.profile_ref.is_none() { + request.profile_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "rank" => { + request.rank = Some(arg_from_str(value.unwrap_or("-0"), err, "rank", "integer")); + }, + "filter-ref.kind" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "filter-ref.href" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "filter-ref.id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "filter-ref.name" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "filter-ref.account-id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "profile-ref.kind" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "profile-ref.name" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "profile-ref.internal-web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().internal_web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.href" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "profile-ref.web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "profile-ref.account-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_profile_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_profile_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_filter_links_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProfileFilterLink = Default::default(); + let mut call = self.hub.management().profile_filter_links_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_filter_ref_init(request: &mut api::ProfileFilterLink) { + if request.filter_ref.is_none() { + request.filter_ref = Some(Default::default()); + } + } + + fn request_profile_ref_init(request: &mut api::ProfileFilterLink) { + if request.profile_ref.is_none() { + request.profile_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "rank" => { + request.rank = Some(arg_from_str(value.unwrap_or("-0"), err, "rank", "integer")); + }, + "filter-ref.kind" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "filter-ref.href" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "filter-ref.id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "filter-ref.name" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "filter-ref.account-id" => { + request_filter_ref_init(&mut request); + request.filter_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "profile-ref.kind" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "profile-ref.name" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "profile-ref.internal-web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().internal_web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.href" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "profile-ref.web-property-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().web_property_id = value.unwrap_or("").to_string(); + }, + "profile-ref.id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "profile-ref.account-id" => { + request_profile_ref_init(&mut request); + request.profile_ref.as_mut().unwrap().account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_profile_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_profile_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_user_links_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profile_user_links_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_profile_user_links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().profile_user_links_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_user_links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profile_user_links_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profile_user_links_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().profile_user_links_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profiles_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profiles_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_profiles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profiles_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profiles_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Profile = Default::default(); + let mut call = self.hub.management().profiles_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Profile) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Profile) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Profile) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "currency" => { + request.currency = Some(value.unwrap_or("").to_string()); + }, + "e-commerce-tracking" => { + request.e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "e-commerce-tracking", "boolean")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "timezone" => { + request.timezone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-category-parameters" => { + request.strip_site_search_category_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-category-parameters", "boolean")); + }, + "site-search-category-parameters" => { + request.site_search_category_parameters = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "exclude-query-parameters" => { + request.exclude_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "enhanced-e-commerce-tracking" => { + request_child_link_init(&mut request); + request.enhanced_e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "enhanced-e-commerce-tracking", "boolean")); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "default-page" => { + request_permissions_init(&mut request); + request.default_page = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_permissions_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-query-parameters" => { + request_permissions_init(&mut request); + request.strip_site_search_query_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-query-parameters", "boolean")); + }, + "name" => { + request_permissions_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_permissions_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "site-search-query-parameters" => { + request_permissions_init(&mut request); + request.site_search_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "website-url" => { + request_permissions_init(&mut request); + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profiles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().profiles_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profiles_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Profile = Default::default(); + let mut call = self.hub.management().profiles_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Profile) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Profile) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Profile) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "currency" => { + request.currency = Some(value.unwrap_or("").to_string()); + }, + "e-commerce-tracking" => { + request.e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "e-commerce-tracking", "boolean")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "timezone" => { + request.timezone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-category-parameters" => { + request.strip_site_search_category_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-category-parameters", "boolean")); + }, + "site-search-category-parameters" => { + request.site_search_category_parameters = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "exclude-query-parameters" => { + request.exclude_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "enhanced-e-commerce-tracking" => { + request_child_link_init(&mut request); + request.enhanced_e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "enhanced-e-commerce-tracking", "boolean")); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "default-page" => { + request_permissions_init(&mut request); + request.default_page = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_permissions_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-query-parameters" => { + request_permissions_init(&mut request); + request.strip_site_search_query_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-query-parameters", "boolean")); + }, + "name" => { + request_permissions_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_permissions_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "site-search-query-parameters" => { + request_permissions_init(&mut request); + request.site_search_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "website-url" => { + request_permissions_init(&mut request); + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_profiles_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Profile = Default::default(); + let mut call = self.hub.management().profiles_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Profile) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Profile) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Profile) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "currency" => { + request.currency = Some(value.unwrap_or("").to_string()); + }, + "e-commerce-tracking" => { + request.e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "e-commerce-tracking", "boolean")); + }, + "web-property-id" => { + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "timezone" => { + request.timezone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-category-parameters" => { + request.strip_site_search_category_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-category-parameters", "boolean")); + }, + "site-search-category-parameters" => { + request.site_search_category_parameters = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "exclude-query-parameters" => { + request.exclude_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "enhanced-e-commerce-tracking" => { + request_child_link_init(&mut request); + request.enhanced_e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "enhanced-e-commerce-tracking", "boolean")); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "default-page" => { + request_permissions_init(&mut request); + request.default_page = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_permissions_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "strip-site-search-query-parameters" => { + request_permissions_init(&mut request); + request.strip_site_search_query_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "strip-site-search-query-parameters", "boolean")); + }, + "name" => { + request_permissions_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_permissions_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "site-search-query-parameters" => { + request_permissions_init(&mut request); + request.site_search_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "website-url" => { + request_permissions_init(&mut request); + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_parent_link_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_segments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().segments_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_unsampled_reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().unsampled_reports_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id, &self.opt.arg_unsampled_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_unsampled_reports_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UnsampledReport = Default::default(); + let mut call = self.hub.management().unsampled_reports_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_cloud_storage_download_details_init(request: &mut api::UnsampledReport) { + if request.cloud_storage_download_details.is_none() { + request.cloud_storage_download_details = Some(Default::default()); + } + } + + fn request_drive_download_details_init(request: &mut api::UnsampledReport) { + if request.drive_download_details.is_none() { + request.drive_download_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "cloud-storage-download-details.bucket-id" => { + request_cloud_storage_download_details_init(&mut request); + request.cloud_storage_download_details.as_mut().unwrap().bucket_id = value.unwrap_or("").to_string(); + }, + "cloud-storage-download-details.object-id" => { + request_cloud_storage_download_details_init(&mut request); + request.cloud_storage_download_details.as_mut().unwrap().object_id = value.unwrap_or("").to_string(); + }, + "download-type" => { + request_cloud_storage_download_details_init(&mut request); + request.download_type = Some(value.unwrap_or("").to_string()); + }, + "dimensions" => { + request_cloud_storage_download_details_init(&mut request); + request.dimensions = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request_cloud_storage_download_details_init(&mut request); + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request_cloud_storage_download_details_init(&mut request); + request.end_date = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_cloud_storage_download_details_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_cloud_storage_download_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "drive-download-details.document-id" => { + request_drive_download_details_init(&mut request); + request.drive_download_details.as_mut().unwrap().document_id = value.unwrap_or("").to_string(); + }, + "profile-id" => { + request_drive_download_details_init(&mut request); + request.profile_id = Some(value.unwrap_or("").to_string()); + }, + "metrics" => { + request_drive_download_details_init(&mut request); + request.metrics = Some(value.unwrap_or("").to_string()); + }, + "filters" => { + request_drive_download_details_init(&mut request); + request.filters = Some(value.unwrap_or("").to_string()); + }, + "web-property-id" => { + request_drive_download_details_init(&mut request); + request.web_property_id = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_drive_download_details_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "segment" => { + request_drive_download_details_init(&mut request); + request.segment = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_drive_download_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_drive_download_details_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_drive_download_details_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_unsampled_reports_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().unsampled_reports_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_uploads_delete_upload_data(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AnalyticsDataimportDeleteUploadDataRequest = Default::default(); + let mut call = self.hub.management().uploads_delete_upload_data(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "custom-data-import-uids" => { + if request.custom_data_import_uids.is_none() { + request.custom_data_import_uids = Some(Default::default()); + } + request.custom_data_import_uids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_uploads_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().uploads_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_data_source_id, &self.opt.arg_upload_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_uploads_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().uploads_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_uploads_upload_data(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().uploads_upload_data(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_custom_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_web_property_ad_words_links_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().web_property_ad_words_links_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_web_property_ad_words_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_web_property_ad_words_links_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().web_property_ad_words_links_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_web_property_ad_words_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_web_property_ad_words_links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityAdWordsLink = Default::default(); + let mut call = self.hub.management().web_property_ad_words_links_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityAdWordsLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "profile-ids" => { + if request.profile_ids.is_none() { + request.profile_ids = Some(Default::default()); + } + request.profile_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_entity_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_entity_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_web_property_ad_words_links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().web_property_ad_words_links_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_web_property_ad_words_links_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityAdWordsLink = Default::default(); + let mut call = self.hub.management().web_property_ad_words_links_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_web_property_ad_words_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityAdWordsLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "profile-ids" => { + if request.profile_ids.is_none() { + request.profile_ids = Some(Default::default()); + } + request.profile_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_entity_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_entity_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_web_property_ad_words_links_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityAdWordsLink = Default::default(); + let mut call = self.hub.management().web_property_ad_words_links_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_web_property_ad_words_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityAdWordsLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "profile-ids" => { + if request.profile_ids.is_none() { + request.profile_ids = Some(Default::default()); + } + request.profile_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_entity_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_entity_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperties_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().webproperties_get(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperties_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Webproperty = Default::default(); + let mut call = self.hub.management().webproperties_insert(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Webproperty) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Webproperty) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Webproperty) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "default-profile-id" => { + request.default_profile_id = Some(value.unwrap_or("").to_string()); + }, + "level" => { + request.level = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "profile-count" => { + request.profile_count = Some(arg_from_str(value.unwrap_or("-0"), err, "profile-count", "integer")); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "industry-vertical" => { + request_child_link_init(&mut request); + request.industry_vertical = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "id" => { + request_permissions_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_permissions_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_permissions_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperties_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().webproperties_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperties_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Webproperty = Default::default(); + let mut call = self.hub.management().webproperties_patch(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Webproperty) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Webproperty) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Webproperty) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "default-profile-id" => { + request.default_profile_id = Some(value.unwrap_or("").to_string()); + }, + "level" => { + request.level = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "profile-count" => { + request.profile_count = Some(arg_from_str(value.unwrap_or("-0"), err, "profile-count", "integer")); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "industry-vertical" => { + request_child_link_init(&mut request); + request.industry_vertical = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "id" => { + request_permissions_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_permissions_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_permissions_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperties_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Webproperty = Default::default(); + let mut call = self.hub.management().webproperties_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_child_link_init(request: &mut api::Webproperty) { + if request.child_link.is_none() { + request.child_link = Some(Default::default()); + } + } + + fn request_parent_link_init(request: &mut api::Webproperty) { + if request.parent_link.is_none() { + request.parent_link = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::Webproperty) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "default-profile-id" => { + request.default_profile_id = Some(value.unwrap_or("").to_string()); + }, + "level" => { + request.level = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "profile-count" => { + request.profile_count = Some(arg_from_str(value.unwrap_or("-0"), err, "profile-count", "integer")); + }, + "internal-web-property-id" => { + request.internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "child-link.href" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "child-link.type" => { + request_child_link_init(&mut request); + request.child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "industry-vertical" => { + request_child_link_init(&mut request); + request.industry_vertical = Some(value.unwrap_or("").to_string()); + }, + "parent-link.href" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "parent-link.type" => { + request_parent_link_init(&mut request); + request.parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "id" => { + request_permissions_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_permissions_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_permissions_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperty_user_links_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().webproperty_user_links_delete(&self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _management_webproperty_user_links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().webproperty_user_links_insert(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperty_user_links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.management().webproperty_user_links_list(&self.opt.arg_account_id, &self.opt.arg_web_property_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _management_webproperty_user_links_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EntityUserLink = Default::default(); + let mut call = self.hub.management().webproperty_user_links_update(&request, &self.opt.arg_account_id, &self.opt.arg_web_property_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_entity_init(request: &mut api::EntityUserLink) { + if request.entity.is_none() { + request.entity = Some(Default::default()); + } + } + + fn request_permissions_init(request: &mut api::EntityUserLink) { + if request.permissions.is_none() { + request.permissions = Some(Default::default()); + } + } + + fn request_user_ref_init(request: &mut api::EntityUserLink) { + if request.user_ref.is_none() { + request.user_ref = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity.account-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.account-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.href = value.unwrap_or("").to_string(); + }, + "entity.account-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.id = value.unwrap_or("").to_string(); + }, + "entity.account-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().account_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.name = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.href = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.web_property_id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.id = value.unwrap_or("").to_string(); + }, + "entity.profile-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().profile_ref.account_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.kind" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.kind = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.name" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.name = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.internal-web-property-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.internal_web_property_id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.href" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.href = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.id = value.unwrap_or("").to_string(); + }, + "entity.web-property-ref.account-id" => { + request_entity_init(&mut request); + request.entity.as_mut().unwrap().web_property_ref.account_id = value.unwrap_or("").to_string(); + }, + "user-ref.kind" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "user-ref.email" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "user-ref.id" => { + request_user_ref_init(&mut request); + request.user_ref.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_user_ref_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_ref_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "permissions.local" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().local.push(value.unwrap_or("").to_string()); + }, + "permissions.effective" => { + request_permissions_init(&mut request); + request.permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metadata_columns_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.metadata().columns_list(&self.opt.arg_report_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _provisioning_create_account_ticket(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountTicket = Default::default(); + let mut call = self.hub.provisioning().create_account_ticket(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_account_init(request: &mut api::AccountTicket) { + if request.account.is_none() { + request.account = Some(Default::default()); + } + } + + fn request_profile_child_link_init(request: &mut api::AccountTicket) { + request_profile_init(request); + if request.profile.as_mut().unwrap().child_link.is_none() { + request.profile.as_mut().unwrap().child_link = Some(Default::default()); + } + } + + fn request_profile_init(request: &mut api::AccountTicket) { + if request.profile.is_none() { + request.profile = Some(Default::default()); + } + } + + fn request_profile_parent_link_init(request: &mut api::AccountTicket) { + request_profile_init(request); + if request.profile.as_mut().unwrap().parent_link.is_none() { + request.profile.as_mut().unwrap().parent_link = Some(Default::default()); + } + } + + fn request_profile_permissions_init(request: &mut api::AccountTicket) { + request_profile_init(request); + if request.profile.as_mut().unwrap().permissions.is_none() { + request.profile.as_mut().unwrap().permissions = Some(Default::default()); + } + } + + fn request_webproperty_child_link_init(request: &mut api::AccountTicket) { + request_webproperty_init(request); + if request.webproperty.as_mut().unwrap().child_link.is_none() { + request.webproperty.as_mut().unwrap().child_link = Some(Default::default()); + } + } + + fn request_webproperty_init(request: &mut api::AccountTicket) { + if request.webproperty.is_none() { + request.webproperty = Some(Default::default()); + } + } + + fn request_webproperty_parent_link_init(request: &mut api::AccountTicket) { + request_webproperty_init(request); + if request.webproperty.as_mut().unwrap().parent_link.is_none() { + request.webproperty.as_mut().unwrap().parent_link = Some(Default::default()); + } + } + + fn request_webproperty_permissions_init(request: &mut api::AccountTicket) { + request_webproperty_init(request); + if request.webproperty.as_mut().unwrap().permissions.is_none() { + request.webproperty.as_mut().unwrap().permissions = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "profile.currency" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().currency = Some(value.unwrap_or("").to_string()); + }, + "profile.e-commerce-tracking" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "profile.e-commerce-tracking", "boolean")); + }, + "profile.web-property-id" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().web_property_id = Some(value.unwrap_or("").to_string()); + }, + "profile.timezone" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().timezone = Some(value.unwrap_or("").to_string()); + }, + "profile.id" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "profile.account-id" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().account_id = Some(value.unwrap_or("").to_string()); + }, + "profile.strip-site-search-category-parameters" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().strip_site_search_category_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "profile.strip-site-search-category-parameters", "boolean")); + }, + "profile.site-search-category-parameters" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().site_search_category_parameters = Some(value.unwrap_or("").to_string()); + }, + "profile.type" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "profile.updated" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().updated = Some(value.unwrap_or("").to_string()); + }, + "profile.exclude-query-parameters" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().exclude_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "profile.internal-web-property-id" => { + request_profile_init(&mut request); + request.profile.as_mut().unwrap().internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "profile.child-link.href" => { + request_profile_child_link_init(&mut request); + request.profile.as_mut().unwrap().child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "profile.child-link.type" => { + request_profile_child_link_init(&mut request); + request.profile.as_mut().unwrap().child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "profile.enhanced-e-commerce-tracking" => { + request_profile_child_link_init(&mut request); + request.profile.as_mut().unwrap().enhanced_e_commerce_tracking = Some(arg_from_str(value.unwrap_or("false"), err, "profile.enhanced-e-commerce-tracking", "boolean")); + }, + "profile.permissions.effective" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "profile.default-page" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().default_page = Some(value.unwrap_or("").to_string()); + }, + "profile.kind" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "profile.strip-site-search-query-parameters" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().strip_site_search_query_parameters = Some(arg_from_str(value.unwrap_or("false"), err, "profile.strip-site-search-query-parameters", "boolean")); + }, + "profile.name" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "profile.created" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().created = Some(value.unwrap_or("").to_string()); + }, + "profile.site-search-query-parameters" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().site_search_query_parameters = Some(value.unwrap_or("").to_string()); + }, + "profile.website-url" => { + request_profile_permissions_init(&mut request); + request.profile.as_mut().unwrap().website_url = Some(value.unwrap_or("").to_string()); + }, + "profile.parent-link.href" => { + request_profile_parent_link_init(&mut request); + request.profile.as_mut().unwrap().parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "profile.parent-link.type" => { + request_profile_parent_link_init(&mut request); + request.profile.as_mut().unwrap().parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "profile.self-link" => { + request_profile_parent_link_init(&mut request); + request.profile.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "account.kind" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "account.name" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "account.created" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().created = value.unwrap_or("").to_string(); + }, + "account.updated" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().updated = value.unwrap_or("").to_string(); + }, + "account.child-link.href" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().child_link.href = value.unwrap_or("").to_string(); + }, + "account.child-link.type" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().child_link.type_ = value.unwrap_or("").to_string(); + }, + "account.id" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "account.self-link" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "account.permissions.effective" => { + request_account_init(&mut request); + request.account.as_mut().unwrap().permissions.effective.push(value.unwrap_or("").to_string()); + }, + "webproperty.website-url" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().website_url = Some(value.unwrap_or("").to_string()); + }, + "webproperty.updated" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().updated = Some(value.unwrap_or("").to_string()); + }, + "webproperty.name" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "webproperty.created" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().created = Some(value.unwrap_or("").to_string()); + }, + "webproperty.default-profile-id" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().default_profile_id = Some(value.unwrap_or("").to_string()); + }, + "webproperty.level" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().level = Some(value.unwrap_or("").to_string()); + }, + "webproperty.kind" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "webproperty.profile-count" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().profile_count = Some(arg_from_str(value.unwrap_or("-0"), err, "webproperty.profile-count", "integer")); + }, + "webproperty.internal-web-property-id" => { + request_webproperty_init(&mut request); + request.webproperty.as_mut().unwrap().internal_web_property_id = Some(value.unwrap_or("").to_string()); + }, + "webproperty.child-link.href" => { + request_webproperty_child_link_init(&mut request); + request.webproperty.as_mut().unwrap().child_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "webproperty.child-link.type" => { + request_webproperty_child_link_init(&mut request); + request.webproperty.as_mut().unwrap().child_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "webproperty.industry-vertical" => { + request_webproperty_child_link_init(&mut request); + request.webproperty.as_mut().unwrap().industry_vertical = Some(value.unwrap_or("").to_string()); + }, + "webproperty.parent-link.href" => { + request_webproperty_parent_link_init(&mut request); + request.webproperty.as_mut().unwrap().parent_link.as_mut().unwrap().href = value.unwrap_or("").to_string(); + }, + "webproperty.parent-link.type" => { + request_webproperty_parent_link_init(&mut request); + request.webproperty.as_mut().unwrap().parent_link.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "webproperty.permissions.effective" => { + request_webproperty_permissions_init(&mut request); + request.webproperty.as_mut().unwrap().permissions.as_mut().unwrap().effective.push(value.unwrap_or("").to_string()); + }, + "webproperty.id" => { + request_webproperty_permissions_init(&mut request); + request.webproperty.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "webproperty.self-link" => { + request_webproperty_permissions_init(&mut request); + request.webproperty.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "webproperty.account-id" => { + request_webproperty_permissions_init(&mut request); + request.webproperty.as_mut().unwrap().account_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_webproperty_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "redirect-uri" => { + request_webproperty_init(&mut request); + request.redirect_uri = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_webproperty_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_data { + if self.opt.cmd_ga_get { + call_result = self._data_ga_get(dry_run, &mut err); + } else if self.opt.cmd_mcf_get { + call_result = self._data_mcf_get(dry_run, &mut err); + } else if self.opt.cmd_realtime_get { + call_result = self._data_realtime_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_management { + if self.opt.cmd_account_summaries_list { + call_result = self._management_account_summaries_list(dry_run, &mut err); + } else if self.opt.cmd_account_user_links_delete { + call_result = self._management_account_user_links_delete(dry_run, &mut err); + } else if self.opt.cmd_account_user_links_insert { + call_result = self._management_account_user_links_insert(dry_run, &mut err); + } else if self.opt.cmd_account_user_links_list { + call_result = self._management_account_user_links_list(dry_run, &mut err); + } else if self.opt.cmd_account_user_links_update { + call_result = self._management_account_user_links_update(dry_run, &mut err); + } else if self.opt.cmd_accounts_list { + call_result = self._management_accounts_list(dry_run, &mut err); + } else if self.opt.cmd_custom_data_sources_list { + call_result = self._management_custom_data_sources_list(dry_run, &mut err); + } else if self.opt.cmd_custom_dimensions_get { + call_result = self._management_custom_dimensions_get(dry_run, &mut err); + } else if self.opt.cmd_custom_dimensions_insert { + call_result = self._management_custom_dimensions_insert(dry_run, &mut err); + } else if self.opt.cmd_custom_dimensions_list { + call_result = self._management_custom_dimensions_list(dry_run, &mut err); + } else if self.opt.cmd_custom_dimensions_patch { + call_result = self._management_custom_dimensions_patch(dry_run, &mut err); + } else if self.opt.cmd_custom_dimensions_update { + call_result = self._management_custom_dimensions_update(dry_run, &mut err); + } else if self.opt.cmd_custom_metrics_get { + call_result = self._management_custom_metrics_get(dry_run, &mut err); + } else if self.opt.cmd_custom_metrics_insert { + call_result = self._management_custom_metrics_insert(dry_run, &mut err); + } else if self.opt.cmd_custom_metrics_list { + call_result = self._management_custom_metrics_list(dry_run, &mut err); + } else if self.opt.cmd_custom_metrics_patch { + call_result = self._management_custom_metrics_patch(dry_run, &mut err); + } else if self.opt.cmd_custom_metrics_update { + call_result = self._management_custom_metrics_update(dry_run, &mut err); + } else if self.opt.cmd_experiments_delete { + call_result = self._management_experiments_delete(dry_run, &mut err); + } else if self.opt.cmd_experiments_get { + call_result = self._management_experiments_get(dry_run, &mut err); + } else if self.opt.cmd_experiments_insert { + call_result = self._management_experiments_insert(dry_run, &mut err); + } else if self.opt.cmd_experiments_list { + call_result = self._management_experiments_list(dry_run, &mut err); + } else if self.opt.cmd_experiments_patch { + call_result = self._management_experiments_patch(dry_run, &mut err); + } else if self.opt.cmd_experiments_update { + call_result = self._management_experiments_update(dry_run, &mut err); + } else if self.opt.cmd_filters_delete { + call_result = self._management_filters_delete(dry_run, &mut err); + } else if self.opt.cmd_filters_get { + call_result = self._management_filters_get(dry_run, &mut err); + } else if self.opt.cmd_filters_insert { + call_result = self._management_filters_insert(dry_run, &mut err); + } else if self.opt.cmd_filters_list { + call_result = self._management_filters_list(dry_run, &mut err); + } else if self.opt.cmd_filters_patch { + call_result = self._management_filters_patch(dry_run, &mut err); + } else if self.opt.cmd_filters_update { + call_result = self._management_filters_update(dry_run, &mut err); + } else if self.opt.cmd_goals_get { + call_result = self._management_goals_get(dry_run, &mut err); + } else if self.opt.cmd_goals_insert { + call_result = self._management_goals_insert(dry_run, &mut err); + } else if self.opt.cmd_goals_list { + call_result = self._management_goals_list(dry_run, &mut err); + } else if self.opt.cmd_goals_patch { + call_result = self._management_goals_patch(dry_run, &mut err); + } else if self.opt.cmd_goals_update { + call_result = self._management_goals_update(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_delete { + call_result = self._management_profile_filter_links_delete(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_get { + call_result = self._management_profile_filter_links_get(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_insert { + call_result = self._management_profile_filter_links_insert(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_list { + call_result = self._management_profile_filter_links_list(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_patch { + call_result = self._management_profile_filter_links_patch(dry_run, &mut err); + } else if self.opt.cmd_profile_filter_links_update { + call_result = self._management_profile_filter_links_update(dry_run, &mut err); + } else if self.opt.cmd_profile_user_links_delete { + call_result = self._management_profile_user_links_delete(dry_run, &mut err); + } else if self.opt.cmd_profile_user_links_insert { + call_result = self._management_profile_user_links_insert(dry_run, &mut err); + } else if self.opt.cmd_profile_user_links_list { + call_result = self._management_profile_user_links_list(dry_run, &mut err); + } else if self.opt.cmd_profile_user_links_update { + call_result = self._management_profile_user_links_update(dry_run, &mut err); + } else if self.opt.cmd_profiles_delete { + call_result = self._management_profiles_delete(dry_run, &mut err); + } else if self.opt.cmd_profiles_get { + call_result = self._management_profiles_get(dry_run, &mut err); + } else if self.opt.cmd_profiles_insert { + call_result = self._management_profiles_insert(dry_run, &mut err); + } else if self.opt.cmd_profiles_list { + call_result = self._management_profiles_list(dry_run, &mut err); + } else if self.opt.cmd_profiles_patch { + call_result = self._management_profiles_patch(dry_run, &mut err); + } else if self.opt.cmd_profiles_update { + call_result = self._management_profiles_update(dry_run, &mut err); + } else if self.opt.cmd_segments_list { + call_result = self._management_segments_list(dry_run, &mut err); + } else if self.opt.cmd_unsampled_reports_get { + call_result = self._management_unsampled_reports_get(dry_run, &mut err); + } else if self.opt.cmd_unsampled_reports_insert { + call_result = self._management_unsampled_reports_insert(dry_run, &mut err); + } else if self.opt.cmd_unsampled_reports_list { + call_result = self._management_unsampled_reports_list(dry_run, &mut err); + } else if self.opt.cmd_uploads_delete_upload_data { + call_result = self._management_uploads_delete_upload_data(dry_run, &mut err); + } else if self.opt.cmd_uploads_get { + call_result = self._management_uploads_get(dry_run, &mut err); + } else if self.opt.cmd_uploads_list { + call_result = self._management_uploads_list(dry_run, &mut err); + } else if self.opt.cmd_uploads_upload_data { + call_result = self._management_uploads_upload_data(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_delete { + call_result = self._management_web_property_ad_words_links_delete(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_get { + call_result = self._management_web_property_ad_words_links_get(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_insert { + call_result = self._management_web_property_ad_words_links_insert(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_list { + call_result = self._management_web_property_ad_words_links_list(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_patch { + call_result = self._management_web_property_ad_words_links_patch(dry_run, &mut err); + } else if self.opt.cmd_web_property_ad_words_links_update { + call_result = self._management_web_property_ad_words_links_update(dry_run, &mut err); + } else if self.opt.cmd_webproperties_get { + call_result = self._management_webproperties_get(dry_run, &mut err); + } else if self.opt.cmd_webproperties_insert { + call_result = self._management_webproperties_insert(dry_run, &mut err); + } else if self.opt.cmd_webproperties_list { + call_result = self._management_webproperties_list(dry_run, &mut err); + } else if self.opt.cmd_webproperties_patch { + call_result = self._management_webproperties_patch(dry_run, &mut err); + } else if self.opt.cmd_webproperties_update { + call_result = self._management_webproperties_update(dry_run, &mut err); + } else if self.opt.cmd_webproperty_user_links_delete { + call_result = self._management_webproperty_user_links_delete(dry_run, &mut err); + } else if self.opt.cmd_webproperty_user_links_insert { + call_result = self._management_webproperty_user_links_insert(dry_run, &mut err); + } else if self.opt.cmd_webproperty_user_links_list { + call_result = self._management_webproperty_user_links_list(dry_run, &mut err); + } else if self.opt.cmd_webproperty_user_links_update { + call_result = self._management_webproperty_user_links_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_metadata { + if self.opt.cmd_columns_list { + call_result = self._metadata_columns_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_provisioning { + if self.opt.cmd_create_account_ticket { + call_result = self._provisioning_create_account_ticket(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "analytics3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "analytics3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Analytics::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/androidenterprise1-cli/Cargo.toml b/gen/androidenterprise1-cli/Cargo.toml new file mode 100644 index 00000000000..5d46da6f69e --- /dev/null +++ b/gen/androidenterprise1-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-androidenterprise1-cli" +version = "0.0.1+20150309" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Android Enterprise (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/androidenterprise1-cli" +documentation = "http://byron.github.io/google-apis-rs/google_androidenterprise1_cli" +license = "MIT" +keywords = ["androidenterprise", "google", "cli"] + +[[bin]] +name = "androidenterprise1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-androidenterprise1] +path = "../androidenterprise1" diff --git a/gen/androidenterprise1-cli/LICENSE.md b/gen/androidenterprise1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/androidenterprise1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/androidenterprise1-cli/README.md b/gen/androidenterprise1-cli/README.md new file mode 100644 index 00000000000..9339062bb65 --- /dev/null +++ b/gen/androidenterprise1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ANDROIDENTERPRISE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/androidenterprise1-cli/mkdocs.yml b/gen/androidenterprise1-cli/mkdocs.yml new file mode 100644 index 00000000000..3f6adb7adf5 --- /dev/null +++ b/gen/androidenterprise1-cli/mkdocs.yml @@ -0,0 +1,60 @@ +site_name: Android Enterprise v0.0.1+20150309 +site_url: http://byron.github.io/google-apis-rs/google-androidenterprise1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/androidenterprise1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['collections_delete.md', 'Collections', 'Delete'] +- ['collections_get.md', 'Collections', 'Get'] +- ['collections_insert.md', 'Collections', 'Insert'] +- ['collections_list.md', 'Collections', 'List'] +- ['collections_patch.md', 'Collections', 'Patch'] +- ['collections_update.md', 'Collections', 'Update'] +- ['collectionviewers_delete.md', 'Collectionviewers', 'Delete'] +- ['collectionviewers_get.md', 'Collectionviewers', 'Get'] +- ['collectionviewers_list.md', 'Collectionviewers', 'List'] +- ['collectionviewers_patch.md', 'Collectionviewers', 'Patch'] +- ['collectionviewers_update.md', 'Collectionviewers', 'Update'] +- ['devices_get.md', 'Devices', 'Get'] +- ['devices_get-state.md', 'Devices', 'Get State'] +- ['devices_list.md', 'Devices', 'List'] +- ['devices_set-state.md', 'Devices', 'Set State'] +- ['enterprises_delete.md', 'Enterprises', 'Delete'] +- ['enterprises_enroll.md', 'Enterprises', 'Enroll'] +- ['enterprises_get.md', 'Enterprises', 'Get'] +- ['enterprises_insert.md', 'Enterprises', 'Insert'] +- ['enterprises_list.md', 'Enterprises', 'List'] +- ['enterprises_set-account.md', 'Enterprises', 'Set Account'] +- ['enterprises_unenroll.md', 'Enterprises', 'Unenroll'] +- ['entitlements_delete.md', 'Entitlements', 'Delete'] +- ['entitlements_get.md', 'Entitlements', 'Get'] +- ['entitlements_list.md', 'Entitlements', 'List'] +- ['entitlements_patch.md', 'Entitlements', 'Patch'] +- ['entitlements_update.md', 'Entitlements', 'Update'] +- ['grouplicenses_get.md', 'Grouplicenses', 'Get'] +- ['grouplicenses_list.md', 'Grouplicenses', 'List'] +- ['grouplicenseusers_list.md', 'Grouplicenseusers', 'List'] +- ['installs_delete.md', 'Installs', 'Delete'] +- ['installs_get.md', 'Installs', 'Get'] +- ['installs_list.md', 'Installs', 'List'] +- ['installs_patch.md', 'Installs', 'Patch'] +- ['installs_update.md', 'Installs', 'Update'] +- ['permissions_get.md', 'Permissions', 'Get'] +- ['products_get.md', 'Products', 'Get'] +- ['products_get-app-restrictions-schema.md', 'Products', 'Get App Restrictions Schema'] +- ['products_get-permissions.md', 'Products', 'Get Permissions'] +- ['products_update-permissions.md', 'Products', 'Update Permissions'] +- ['users_generate-token.md', 'Users', 'Generate Token'] +- ['users_get.md', 'Users', 'Get'] +- ['users_list.md', 'Users', 'List'] +- ['users_revoke-token.md', 'Users', 'Revoke Token'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/androidenterprise1-cli/src/cmn.rs b/gen/androidenterprise1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/androidenterprise1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/androidenterprise1-cli/src/main.rs b/gen/androidenterprise1-cli/src/main.rs new file mode 100644 index 00000000000..8fd152c6362 --- /dev/null +++ b/gen/androidenterprise1-cli/src/main.rs @@ -0,0 +1,2573 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_androidenterprise1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + androidenterprise1 [options] collections delete [-p ]... + androidenterprise1 [options] collections get [-p ]... [-o ] + androidenterprise1 [options] collections insert -r ... [-p ]... [-o ] + androidenterprise1 [options] collections list [-p ]... [-o ] + androidenterprise1 [options] collections patch -r ... [-p ]... [-o ] + androidenterprise1 [options] collections update -r ... [-p ]... [-o ] + androidenterprise1 [options] collectionviewers delete [-p ]... + androidenterprise1 [options] collectionviewers get [-p ]... [-o ] + androidenterprise1 [options] collectionviewers list [-p ]... [-o ] + androidenterprise1 [options] collectionviewers patch -r ... [-p ]... [-o ] + androidenterprise1 [options] collectionviewers update -r ... [-p ]... [-o ] + androidenterprise1 [options] devices get [-p ]... [-o ] + androidenterprise1 [options] devices get-state [-p ]... [-o ] + androidenterprise1 [options] devices list [-p ]... [-o ] + androidenterprise1 [options] devices set-state -r ... [-p ]... [-o ] + androidenterprise1 [options] enterprises delete [-p ]... + androidenterprise1 [options] enterprises enroll -r ... [-p ]... [-o ] + androidenterprise1 [options] enterprises get [-p ]... [-o ] + androidenterprise1 [options] enterprises insert -r ... [-p ]... [-o ] + androidenterprise1 [options] enterprises list [-p ]... [-o ] + androidenterprise1 [options] enterprises set-account -r ... [-p ]... [-o ] + androidenterprise1 [options] enterprises unenroll [-p ]... + androidenterprise1 [options] entitlements delete [-p ]... + androidenterprise1 [options] entitlements get [-p ]... [-o ] + androidenterprise1 [options] entitlements list [-p ]... [-o ] + androidenterprise1 [options] entitlements patch -r ... [-p ]... [-o ] + androidenterprise1 [options] entitlements update -r ... [-p ]... [-o ] + androidenterprise1 [options] grouplicenses get [-p ]... [-o ] + androidenterprise1 [options] grouplicenses list [-p ]... [-o ] + androidenterprise1 [options] grouplicenseusers list [-p ]... [-o ] + androidenterprise1 [options] installs delete [-p ]... + androidenterprise1 [options] installs get [-p ]... [-o ] + androidenterprise1 [options] installs list [-p ]... [-o ] + androidenterprise1 [options] installs patch -r ... [-p ]... [-o ] + androidenterprise1 [options] installs update -r ... [-p ]... [-o ] + androidenterprise1 [options] permissions get [-p ]... [-o ] + androidenterprise1 [options] products get [-p ]... [-o ] + androidenterprise1 [options] products get-app-restrictions-schema [-p ]... [-o ] + androidenterprise1 [options] products get-permissions [-p ]... [-o ] + androidenterprise1 [options] products update-permissions -r ... [-p ]... [-o ] + androidenterprise1 [options] users generate-token [-p ]... [-o ] + androidenterprise1 [options] users get [-p ]... [-o ] + androidenterprise1 [options] users list [-p ]... [-o ] + androidenterprise1 [options] users revoke-token [-p ]... + androidenterprise1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AndroidEnterprise>, +} + + +impl Engine { + fn _collections_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collections().delete(&self.opt.arg_enterprise_id, &self.opt.arg_collection_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _collections_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collections().get(&self.opt.arg_enterprise_id, &self.opt.arg_collection_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collections_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Collection = Default::default(); + let mut call = self.hub.collections().insert(&request, &self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + if request.product_id.is_none() { + request.product_id = Some(Default::default()); + } + request.product_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "collection-id" => { + request.collection_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collections_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collections().list(&self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collections_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Collection = Default::default(); + let mut call = self.hub.collections().patch(&request, &self.opt.arg_enterprise_id, &self.opt.arg_collection_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + if request.product_id.is_none() { + request.product_id = Some(Default::default()); + } + request.product_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "collection-id" => { + request.collection_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collections_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Collection = Default::default(); + let mut call = self.hub.collections().update(&request, &self.opt.arg_enterprise_id, &self.opt.arg_collection_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + if request.product_id.is_none() { + request.product_id = Some(Default::default()); + } + request.product_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "collection-id" => { + request.collection_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collectionviewers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collectionviewers().delete(&self.opt.arg_enterprise_id, &self.opt.arg_collection_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _collectionviewers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collectionviewers().get(&self.opt.arg_enterprise_id, &self.opt.arg_collection_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collectionviewers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.collectionviewers().list(&self.opt.arg_enterprise_id, &self.opt.arg_collection_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collectionviewers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::User = Default::default(); + let mut call = self.hub.collectionviewers().patch(&request, &self.opt.arg_enterprise_id, &self.opt.arg_collection_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _collectionviewers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::User = Default::default(); + let mut call = self.hub.collectionviewers().update(&request, &self.opt.arg_enterprise_id, &self.opt.arg_collection_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "primary-email" => { + request.primary_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _devices_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.devices().get(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _devices_get_state(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.devices().get_state(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _devices_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.devices().list(&self.opt.arg_enterprise_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _devices_set_state(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::DeviceState = Default::default(); + let mut call = self.hub.devices().set_state(&request, &self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-state" => { + request.account_state = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.enterprises().delete(&self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _enterprises_enroll(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Enterprise = Default::default(); + let mut call = self.hub.enterprises().enroll(&request, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "primary-domain" => { + request.primary_domain = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.enterprises().get(&self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Enterprise = Default::default(); + let mut call = self.hub.enterprises().insert(&request, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "primary-domain" => { + request.primary_domain = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.enterprises().list(&self.opt.arg_domain); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_set_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::EnterpriseAccount = Default::default(); + let mut call = self.hub.enterprises().set_account(&request, &self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-email" => { + request.account_email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _enterprises_unenroll(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.enterprises().unenroll(&self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _entitlements_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.entitlements().delete(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_entitlement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _entitlements_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.entitlements().get(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_entitlement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _entitlements_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.entitlements().list(&self.opt.arg_enterprise_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _entitlements_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Entitlement = Default::default(); + let mut call = self.hub.entitlements().patch(&request, &self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_entitlement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "install" => { + call = call.install(arg_from_str(value.unwrap_or("false"), err, "install", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "reason" => { + request.reason = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _entitlements_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Entitlement = Default::default(); + let mut call = self.hub.entitlements().update(&request, &self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_entitlement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "install" => { + call = call.install(arg_from_str(value.unwrap_or("false"), err, "install", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "reason" => { + request.reason = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _grouplicenses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.grouplicenses().get(&self.opt.arg_enterprise_id, &self.opt.arg_group_license_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _grouplicenses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.grouplicenses().list(&self.opt.arg_enterprise_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _grouplicenseusers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.grouplicenseusers().list(&self.opt.arg_enterprise_id, &self.opt.arg_group_license_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _installs_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.installs().delete(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id, &self.opt.arg_install_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _installs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.installs().get(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id, &self.opt.arg_install_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _installs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.installs().list(&self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _installs_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Install = Default::default(); + let mut call = self.hub.installs().patch(&request, &self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id, &self.opt.arg_install_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "install-state" => { + request.install_state = Some(value.unwrap_or("").to_string()); + }, + "version-code" => { + request.version_code = Some(arg_from_str(value.unwrap_or("-0"), err, "version-code", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _installs_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Install = Default::default(); + let mut call = self.hub.installs().update(&request, &self.opt.arg_enterprise_id, &self.opt.arg_user_id, &self.opt.arg_device_id, &self.opt.arg_install_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "install-state" => { + request.install_state = Some(value.unwrap_or("").to_string()); + }, + "version-code" => { + request.version_code = Some(arg_from_str(value.unwrap_or("-0"), err, "version-code", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.permissions().get(&self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().get(&self.opt.arg_enterprise_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_get_app_restrictions_schema(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().get_app_restrictions_schema(&self.opt.arg_enterprise_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_get_permissions(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().get_permissions(&self.opt.arg_enterprise_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_update_permissions(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProductPermissions = Default::default(); + let mut call = self.hub.products().update_permissions(&request, &self.opt.arg_enterprise_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_generate_token(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().generate_token(&self.opt.arg_enterprise_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().get(&self.opt.arg_enterprise_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().list(&self.opt.arg_enterprise_id, &self.opt.arg_email); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_revoke_token(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().revoke_token(&self.opt.arg_enterprise_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_collections { + if self.opt.cmd_delete { + call_result = self._collections_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._collections_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._collections_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._collections_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._collections_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._collections_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_collectionviewers { + if self.opt.cmd_delete { + call_result = self._collectionviewers_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._collectionviewers_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._collectionviewers_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._collectionviewers_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._collectionviewers_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_devices { + if self.opt.cmd_get { + call_result = self._devices_get(dry_run, &mut err); + } else if self.opt.cmd_get_state { + call_result = self._devices_get_state(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._devices_list(dry_run, &mut err); + } else if self.opt.cmd_set_state { + call_result = self._devices_set_state(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_enterprises { + if self.opt.cmd_delete { + call_result = self._enterprises_delete(dry_run, &mut err); + } else if self.opt.cmd_enroll { + call_result = self._enterprises_enroll(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._enterprises_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._enterprises_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._enterprises_list(dry_run, &mut err); + } else if self.opt.cmd_set_account { + call_result = self._enterprises_set_account(dry_run, &mut err); + } else if self.opt.cmd_unenroll { + call_result = self._enterprises_unenroll(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_entitlements { + if self.opt.cmd_delete { + call_result = self._entitlements_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._entitlements_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._entitlements_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._entitlements_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._entitlements_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_grouplicenses { + if self.opt.cmd_get { + call_result = self._grouplicenses_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._grouplicenses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_grouplicenseusers { + if self.opt.cmd_list { + call_result = self._grouplicenseusers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_installs { + if self.opt.cmd_delete { + call_result = self._installs_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._installs_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._installs_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._installs_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._installs_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_permissions { + if self.opt.cmd_get { + call_result = self._permissions_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_products { + if self.opt.cmd_get { + call_result = self._products_get(dry_run, &mut err); + } else if self.opt.cmd_get_app_restrictions_schema { + call_result = self._products_get_app_restrictions_schema(dry_run, &mut err); + } else if self.opt.cmd_get_permissions { + call_result = self._products_get_permissions(dry_run, &mut err); + } else if self.opt.cmd_update_permissions { + call_result = self._products_update_permissions(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_users { + if self.opt.cmd_generate_token { + call_result = self._users_generate_token(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._users_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._users_list(dry_run, &mut err); + } else if self.opt.cmd_revoke_token { + call_result = self._users_revoke_token(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "androidenterprise1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "androidenterprise1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AndroidEnterprise::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/androidpublisher2-cli/Cargo.toml b/gen/androidpublisher2-cli/Cargo.toml new file mode 100644 index 00000000000..ffc1f9fea62 --- /dev/null +++ b/gen/androidpublisher2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-androidpublisher2-cli" +version = "0.0.1+20150323" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Android Publisher (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/androidpublisher2-cli" +homepage = "https://developers.google.com/android-publisher" +documentation = "http://byron.github.io/google-apis-rs/google_androidpublisher2_cli" +license = "MIT" +keywords = ["androidpublisher", "google", "cli"] + +[[bin]] +name = "androidpublisher2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-androidpublisher2] +path = "../androidpublisher2" diff --git a/gen/androidpublisher2-cli/LICENSE.md b/gen/androidpublisher2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/androidpublisher2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/androidpublisher2-cli/README.md b/gen/androidpublisher2-cli/README.md new file mode 100644 index 00000000000..92ddc00a90f --- /dev/null +++ b/gen/androidpublisher2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO ANDROIDPUBLISHER:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/androidpublisher2-cli/mkdocs.yml b/gen/androidpublisher2-cli/mkdocs.yml new file mode 100644 index 00000000000..6014864ec01 --- /dev/null +++ b/gen/androidpublisher2-cli/mkdocs.yml @@ -0,0 +1,67 @@ +site_name: Android Publisher v0.0.1+20150323 +site_url: http://byron.github.io/google-apis-rs/google-androidpublisher2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/androidpublisher2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['edits_apklistings-delete.md', 'Edits', 'Apklistings Delete'] +- ['edits_apklistings-deleteall.md', 'Edits', 'Apklistings Deleteall'] +- ['edits_apklistings-get.md', 'Edits', 'Apklistings Get'] +- ['edits_apklistings-list.md', 'Edits', 'Apklistings List'] +- ['edits_apklistings-patch.md', 'Edits', 'Apklistings Patch'] +- ['edits_apklistings-update.md', 'Edits', 'Apklistings Update'] +- ['edits_apks-addexternallyhosted.md', 'Edits', 'Apks Addexternallyhosted'] +- ['edits_apks-list.md', 'Edits', 'Apks List'] +- ['edits_apks-upload.md', 'Edits', 'Apks Upload'] +- ['edits_commit.md', 'Edits', 'Commit'] +- ['edits_delete.md', 'Edits', 'Delete'] +- ['edits_details-get.md', 'Edits', 'Details Get'] +- ['edits_details-patch.md', 'Edits', 'Details Patch'] +- ['edits_details-update.md', 'Edits', 'Details Update'] +- ['edits_expansionfiles-get.md', 'Edits', 'Expansionfiles Get'] +- ['edits_expansionfiles-patch.md', 'Edits', 'Expansionfiles Patch'] +- ['edits_expansionfiles-update.md', 'Edits', 'Expansionfiles Update'] +- ['edits_expansionfiles-upload.md', 'Edits', 'Expansionfiles Upload'] +- ['edits_get.md', 'Edits', 'Get'] +- ['edits_images-delete.md', 'Edits', 'Images Delete'] +- ['edits_images-deleteall.md', 'Edits', 'Images Deleteall'] +- ['edits_images-list.md', 'Edits', 'Images List'] +- ['edits_images-upload.md', 'Edits', 'Images Upload'] +- ['edits_insert.md', 'Edits', 'Insert'] +- ['edits_listings-delete.md', 'Edits', 'Listings Delete'] +- ['edits_listings-deleteall.md', 'Edits', 'Listings Deleteall'] +- ['edits_listings-get.md', 'Edits', 'Listings Get'] +- ['edits_listings-list.md', 'Edits', 'Listings List'] +- ['edits_listings-patch.md', 'Edits', 'Listings Patch'] +- ['edits_listings-update.md', 'Edits', 'Listings Update'] +- ['edits_testers-get.md', 'Edits', 'Testers Get'] +- ['edits_testers-patch.md', 'Edits', 'Testers Patch'] +- ['edits_testers-update.md', 'Edits', 'Testers Update'] +- ['edits_tracks-get.md', 'Edits', 'Tracks Get'] +- ['edits_tracks-list.md', 'Edits', 'Tracks List'] +- ['edits_tracks-patch.md', 'Edits', 'Tracks Patch'] +- ['edits_tracks-update.md', 'Edits', 'Tracks Update'] +- ['edits_validate.md', 'Edits', 'Validate'] +- ['inappproducts_batch.md', 'Inappproducts', 'Batch'] +- ['inappproducts_delete.md', 'Inappproducts', 'Delete'] +- ['inappproducts_get.md', 'Inappproducts', 'Get'] +- ['inappproducts_insert.md', 'Inappproducts', 'Insert'] +- ['inappproducts_list.md', 'Inappproducts', 'List'] +- ['inappproducts_patch.md', 'Inappproducts', 'Patch'] +- ['inappproducts_update.md', 'Inappproducts', 'Update'] +- ['purchases_products-get.md', 'Purchases', 'Products Get'] +- ['purchases_subscriptions-cancel.md', 'Purchases', 'Subscriptions Cancel'] +- ['purchases_subscriptions-defer.md', 'Purchases', 'Subscriptions Defer'] +- ['purchases_subscriptions-get.md', 'Purchases', 'Subscriptions Get'] +- ['purchases_subscriptions-refund.md', 'Purchases', 'Subscriptions Refund'] +- ['purchases_subscriptions-revoke.md', 'Purchases', 'Subscriptions Revoke'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/androidpublisher2-cli/src/cmn.rs b/gen/androidpublisher2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/androidpublisher2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/androidpublisher2-cli/src/main.rs b/gen/androidpublisher2-cli/src/main.rs new file mode 100644 index 00000000000..0e354e8841f --- /dev/null +++ b/gen/androidpublisher2-cli/src/main.rs @@ -0,0 +1,3207 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_androidpublisher2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + androidpublisher2 [options] edits apklistings-delete [-p ]... + androidpublisher2 [options] edits apklistings-deleteall [-p ]... + androidpublisher2 [options] edits apklistings-get [-p ]... [-o ] + androidpublisher2 [options] edits apklistings-list [-p ]... [-o ] + androidpublisher2 [options] edits apklistings-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits apklistings-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits apks-addexternallyhosted -r ... [-p ]... [-o ] + androidpublisher2 [options] edits apks-list [-p ]... [-o ] + androidpublisher2 [options] edits apks-upload -u (simple|resumable) [-p ]... [-o ] + androidpublisher2 [options] edits commit [-p ]... [-o ] + androidpublisher2 [options] edits delete [-p ]... + androidpublisher2 [options] edits details-get [-p ]... [-o ] + androidpublisher2 [options] edits details-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits details-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits expansionfiles-get [-p ]... [-o ] + androidpublisher2 [options] edits expansionfiles-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits expansionfiles-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits expansionfiles-upload -u (simple|resumable) [-p ]... [-o ] + androidpublisher2 [options] edits get [-p ]... [-o ] + androidpublisher2 [options] edits images-delete [-p ]... + androidpublisher2 [options] edits images-deleteall [-p ]... [-o ] + androidpublisher2 [options] edits images-list [-p ]... [-o ] + androidpublisher2 [options] edits images-upload -u (simple|resumable) [-p ]... [-o ] + androidpublisher2 [options] edits insert -r ... [-p ]... [-o ] + androidpublisher2 [options] edits listings-delete [-p ]... + androidpublisher2 [options] edits listings-deleteall [-p ]... + androidpublisher2 [options] edits listings-get [-p ]... [-o ] + androidpublisher2 [options] edits listings-list [-p ]... [-o ] + androidpublisher2 [options] edits listings-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits listings-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits testers-get [-p ]... [-o ] + androidpublisher2 [options] edits testers-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits testers-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits tracks-get [-p ]... [-o ] + androidpublisher2 [options] edits tracks-list [-p ]... [-o ] + androidpublisher2 [options] edits tracks-patch -r ... [-p ]... [-o ] + androidpublisher2 [options] edits tracks-update -r ... [-p ]... [-o ] + androidpublisher2 [options] edits validate [-p ]... [-o ] + androidpublisher2 [options] inappproducts batch -r ... [-p ]... [-o ] + androidpublisher2 [options] inappproducts delete [-p ]... + androidpublisher2 [options] inappproducts get [-p ]... [-o ] + androidpublisher2 [options] inappproducts insert -r ... [-p ]... [-o ] + androidpublisher2 [options] inappproducts list [-p ]... [-o ] + androidpublisher2 [options] inappproducts patch -r ... [-p ]... [-o ] + androidpublisher2 [options] inappproducts update -r ... [-p ]... [-o ] + androidpublisher2 [options] purchases products-get [-p ]... [-o ] + androidpublisher2 [options] purchases subscriptions-cancel [-p ]... + androidpublisher2 [options] purchases subscriptions-defer -r ... [-p ]... [-o ] + androidpublisher2 [options] purchases subscriptions-get [-p ]... [-o ] + androidpublisher2 [options] purchases subscriptions-refund [-p ]... + androidpublisher2 [options] purchases subscriptions-revoke [-p ]... + androidpublisher2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AndroidPublisher>, +} + + +impl Engine { + fn _edits_apklistings_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_delete(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_apklistings_deleteall(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_deleteall(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_apklistings_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_get(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apklistings_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_list(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apklistings_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ApkListing = Default::default(); + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "recent-changes" => { + request.recent_changes = Some(value.unwrap_or("").to_string()); + }, + "language" => { + request.language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apklistings_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ApkListing = Default::default(); + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().apklistings_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "recent-changes" => { + request.recent_changes = Some(value.unwrap_or("").to_string()); + }, + "language" => { + request.language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apks_addexternallyhosted(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ApksAddExternallyHostedRequest = Default::default(); + let mut call = self.hub.edits().apks_addexternallyhosted(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_externally_hosted_apk_init(request: &mut api::ApksAddExternallyHostedRequest) { + if request.externally_hosted_apk.is_none() { + request.externally_hosted_apk = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "externally-hosted-apk.icon-base64" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().icon_base64 = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.certificate-base64s" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().certificate_base64s.push(value.unwrap_or("").to_string()); + }, + "externally-hosted-apk.externally-hosted-url" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().externally_hosted_url = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.maximum-sdk" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().maximum_sdk = arg_from_str(value.unwrap_or("-0"), err, "externally-hosted-apk.maximum-sdk", "integer"); + }, + "externally-hosted-apk.file-sha256-base64" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().file_sha256_base64 = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.file-sha1-base64" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().file_sha1_base64 = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.uses-features" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().uses_features.push(value.unwrap_or("").to_string()); + }, + "externally-hosted-apk.file-size" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().file_size = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.version-name" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().version_name = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.version-code" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().version_code = arg_from_str(value.unwrap_or("-0"), err, "externally-hosted-apk.version-code", "integer"); + }, + "externally-hosted-apk.package-name" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().package_name = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.minimum-sdk" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().minimum_sdk = arg_from_str(value.unwrap_or("-0"), err, "externally-hosted-apk.minimum-sdk", "integer"); + }, + "externally-hosted-apk.application-label" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().application_label = value.unwrap_or("").to_string(); + }, + "externally-hosted-apk.native-codes" => { + request_externally_hosted_apk_init(&mut request); + request.externally_hosted_apk.as_mut().unwrap().native_codes.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().apks_list(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_apks_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().apks_upload(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_commit(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().commit(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().delete(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_details_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().details_get(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_details_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AppDetails = Default::default(); + let mut call = self.hub.edits().details_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "contact-email" => { + request.contact_email = Some(value.unwrap_or("").to_string()); + }, + "contact-phone" => { + request.contact_phone = Some(value.unwrap_or("").to_string()); + }, + "contact-website" => { + request.contact_website = Some(value.unwrap_or("").to_string()); + }, + "default-language" => { + request.default_language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_details_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AppDetails = Default::default(); + let mut call = self.hub.edits().details_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "contact-email" => { + request.contact_email = Some(value.unwrap_or("").to_string()); + }, + "contact-phone" => { + request.contact_phone = Some(value.unwrap_or("").to_string()); + }, + "contact-website" => { + request.contact_website = Some(value.unwrap_or("").to_string()); + }, + "default-language" => { + request.default_language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_expansionfiles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().expansionfiles_get(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_expansion_file_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_expansionfiles_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ExpansionFile = Default::default(); + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().expansionfiles_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_expansion_file_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "references-version" => { + request.references_version = Some(arg_from_str(value.unwrap_or("-0"), err, "references-version", "integer")); + }, + "file-size" => { + request.file_size = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_expansionfiles_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ExpansionFile = Default::default(); + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().expansionfiles_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_expansion_file_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "references-version" => { + request.references_version = Some(arg_from_str(value.unwrap_or("-0"), err, "references-version", "integer")); + }, + "file-size" => { + request.file_size = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_expansionfiles_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let apk_version_code: i32 = arg_from_str(&self.opt.arg_apk_version_code, err, "", "integer"); + let mut call = self.hub.edits().expansionfiles_upload(&self.opt.arg_package_name, &self.opt.arg_edit_id, apk_version_code, &self.opt.arg_expansion_file_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().get(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_images_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().images_delete(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language, &self.opt.arg_image_type, &self.opt.arg_image_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_images_deleteall(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().images_deleteall(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language, &self.opt.arg_image_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_images_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().images_list(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language, &self.opt.arg_image_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_images_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().images_upload(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language, &self.opt.arg_image_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AppEdit = Default::default(); + let mut call = self.hub.edits().insert(&request, &self.opt.arg_package_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "expiry-time-seconds" => { + request.expiry_time_seconds = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_listings_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().listings_delete(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_listings_deleteall(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().listings_deleteall(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _edits_listings_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().listings_get(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_listings_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().listings_list(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_listings_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Listing = Default::default(); + let mut call = self.hub.edits().listings_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "short-description" => { + request.short_description = Some(value.unwrap_or("").to_string()); + }, + "video" => { + request.video = Some(value.unwrap_or("").to_string()); + }, + "full-description" => { + request.full_description = Some(value.unwrap_or("").to_string()); + }, + "language" => { + request.language = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_listings_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Listing = Default::default(); + let mut call = self.hub.edits().listings_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_language); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "short-description" => { + request.short_description = Some(value.unwrap_or("").to_string()); + }, + "video" => { + request.video = Some(value.unwrap_or("").to_string()); + }, + "full-description" => { + request.full_description = Some(value.unwrap_or("").to_string()); + }, + "language" => { + request.language = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_testers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().testers_get(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_testers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Testers = Default::default(); + let mut call = self.hub.edits().testers_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "google-groups" => { + if request.google_groups.is_none() { + request.google_groups = Some(Default::default()); + } + request.google_groups.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "google-plus-communities" => { + if request.google_plus_communities.is_none() { + request.google_plus_communities = Some(Default::default()); + } + request.google_plus_communities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_testers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Testers = Default::default(); + let mut call = self.hub.edits().testers_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "google-groups" => { + if request.google_groups.is_none() { + request.google_groups = Some(Default::default()); + } + request.google_groups.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "google-plus-communities" => { + if request.google_plus_communities.is_none() { + request.google_plus_communities = Some(Default::default()); + } + request.google_plus_communities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_tracks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().tracks_get(&self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_tracks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().tracks_list(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_tracks_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Track = Default::default(); + let mut call = self.hub.edits().tracks_patch(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "track" => { + request.track = Some(value.unwrap_or("").to_string()); + }, + "user-fraction" => { + request.user_fraction = Some(arg_from_str(value.unwrap_or("0.0"), err, "user-fraction", "number")); + }, + "version-codes" => { + if request.version_codes.is_none() { + request.version_codes = Some(Default::default()); + } + request.version_codes.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "version-codes", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_tracks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Track = Default::default(); + let mut call = self.hub.edits().tracks_update(&request, &self.opt.arg_package_name, &self.opt.arg_edit_id, &self.opt.arg_track); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "track" => { + request.track = Some(value.unwrap_or("").to_string()); + }, + "user-fraction" => { + request.user_fraction = Some(arg_from_str(value.unwrap_or("0.0"), err, "user-fraction", "number")); + }, + "version-codes" => { + if request.version_codes.is_none() { + request.version_codes = Some(Default::default()); + } + request.version_codes.as_mut().unwrap().push(arg_from_str(value.unwrap_or("-0"), err, "version-codes", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _edits_validate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.edits().validate(&self.opt.arg_package_name, &self.opt.arg_edit_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_batch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InappproductsBatchRequest = Default::default(); + let mut call = self.hub.inappproducts().batch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.inappproducts().delete(&self.opt.arg_package_name, &self.opt.arg_sku); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _inappproducts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.inappproducts().get(&self.opt.arg_package_name, &self.opt.arg_sku); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InAppProduct = Default::default(); + let mut call = self.hub.inappproducts().insert(&request, &self.opt.arg_package_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "auto-convert-missing-prices" => { + call = call.auto_convert_missing_prices(arg_from_str(value.unwrap_or("false"), err, "auto-convert-missing-prices", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_default_price_init(request: &mut api::InAppProduct) { + if request.default_price.is_none() { + request.default_price = Some(Default::default()); + } + } + + fn request_season_init(request: &mut api::InAppProduct) { + if request.season.is_none() { + request.season = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "sku" => { + request.sku = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "subscription-period" => { + request.subscription_period = Some(value.unwrap_or("").to_string()); + }, + "season.start.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.day = arg_from_str(value.unwrap_or("-0"), err, "season.start.day", "integer"); + }, + "season.start.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.month = arg_from_str(value.unwrap_or("-0"), err, "season.start.month", "integer"); + }, + "season.end.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.day = arg_from_str(value.unwrap_or("-0"), err, "season.end.day", "integer"); + }, + "season.end.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.month = arg_from_str(value.unwrap_or("-0"), err, "season.end.month", "integer"); + }, + "package-name" => { + request_season_init(&mut request); + request.package_name = Some(value.unwrap_or("").to_string()); + }, + "trial-period" => { + request_season_init(&mut request); + request.trial_period = Some(value.unwrap_or("").to_string()); + }, + "purchase-type" => { + request_season_init(&mut request); + request.purchase_type = Some(value.unwrap_or("").to_string()); + }, + "default-language" => { + request_season_init(&mut request); + request.default_language = Some(value.unwrap_or("").to_string()); + }, + "default-price.currency" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "default-price.price-micros" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().price_micros = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.inappproducts().list(&self.opt.arg_package_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "token" => { + call = call.token(value.unwrap_or("")); + }, + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InAppProduct = Default::default(); + let mut call = self.hub.inappproducts().patch(&request, &self.opt.arg_package_name, &self.opt.arg_sku); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "auto-convert-missing-prices" => { + call = call.auto_convert_missing_prices(arg_from_str(value.unwrap_or("false"), err, "auto-convert-missing-prices", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_default_price_init(request: &mut api::InAppProduct) { + if request.default_price.is_none() { + request.default_price = Some(Default::default()); + } + } + + fn request_season_init(request: &mut api::InAppProduct) { + if request.season.is_none() { + request.season = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "sku" => { + request.sku = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "subscription-period" => { + request.subscription_period = Some(value.unwrap_or("").to_string()); + }, + "season.start.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.day = arg_from_str(value.unwrap_or("-0"), err, "season.start.day", "integer"); + }, + "season.start.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.month = arg_from_str(value.unwrap_or("-0"), err, "season.start.month", "integer"); + }, + "season.end.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.day = arg_from_str(value.unwrap_or("-0"), err, "season.end.day", "integer"); + }, + "season.end.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.month = arg_from_str(value.unwrap_or("-0"), err, "season.end.month", "integer"); + }, + "package-name" => { + request_season_init(&mut request); + request.package_name = Some(value.unwrap_or("").to_string()); + }, + "trial-period" => { + request_season_init(&mut request); + request.trial_period = Some(value.unwrap_or("").to_string()); + }, + "purchase-type" => { + request_season_init(&mut request); + request.purchase_type = Some(value.unwrap_or("").to_string()); + }, + "default-language" => { + request_season_init(&mut request); + request.default_language = Some(value.unwrap_or("").to_string()); + }, + "default-price.currency" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "default-price.price-micros" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().price_micros = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inappproducts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InAppProduct = Default::default(); + let mut call = self.hub.inappproducts().update(&request, &self.opt.arg_package_name, &self.opt.arg_sku); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "auto-convert-missing-prices" => { + call = call.auto_convert_missing_prices(arg_from_str(value.unwrap_or("false"), err, "auto-convert-missing-prices", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_default_price_init(request: &mut api::InAppProduct) { + if request.default_price.is_none() { + request.default_price = Some(Default::default()); + } + } + + fn request_season_init(request: &mut api::InAppProduct) { + if request.season.is_none() { + request.season = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "sku" => { + request.sku = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "subscription-period" => { + request.subscription_period = Some(value.unwrap_or("").to_string()); + }, + "season.start.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.day = arg_from_str(value.unwrap_or("-0"), err, "season.start.day", "integer"); + }, + "season.start.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().start.month = arg_from_str(value.unwrap_or("-0"), err, "season.start.month", "integer"); + }, + "season.end.day" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.day = arg_from_str(value.unwrap_or("-0"), err, "season.end.day", "integer"); + }, + "season.end.month" => { + request_season_init(&mut request); + request.season.as_mut().unwrap().end.month = arg_from_str(value.unwrap_or("-0"), err, "season.end.month", "integer"); + }, + "package-name" => { + request_season_init(&mut request); + request.package_name = Some(value.unwrap_or("").to_string()); + }, + "trial-period" => { + request_season_init(&mut request); + request.trial_period = Some(value.unwrap_or("").to_string()); + }, + "purchase-type" => { + request_season_init(&mut request); + request.purchase_type = Some(value.unwrap_or("").to_string()); + }, + "default-language" => { + request_season_init(&mut request); + request.default_language = Some(value.unwrap_or("").to_string()); + }, + "default-price.currency" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "default-price.price-micros" => { + request_default_price_init(&mut request); + request.default_price.as_mut().unwrap().price_micros = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _purchases_products_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.purchases().products_get(&self.opt.arg_package_name, &self.opt.arg_product_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _purchases_subscriptions_cancel(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.purchases().subscriptions_cancel(&self.opt.arg_package_name, &self.opt.arg_subscription_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _purchases_subscriptions_defer(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::SubscriptionPurchasesDeferRequest = Default::default(); + let mut call = self.hub.purchases().subscriptions_defer(&request, &self.opt.arg_package_name, &self.opt.arg_subscription_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_deferral_info_init(request: &mut api::SubscriptionPurchasesDeferRequest) { + if request.deferral_info.is_none() { + request.deferral_info = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "deferral-info.expected-expiry-time-millis" => { + request_deferral_info_init(&mut request); + request.deferral_info.as_mut().unwrap().expected_expiry_time_millis = value.unwrap_or("").to_string(); + }, + "deferral-info.desired-expiry-time-millis" => { + request_deferral_info_init(&mut request); + request.deferral_info.as_mut().unwrap().desired_expiry_time_millis = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _purchases_subscriptions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.purchases().subscriptions_get(&self.opt.arg_package_name, &self.opt.arg_subscription_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _purchases_subscriptions_refund(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.purchases().subscriptions_refund(&self.opt.arg_package_name, &self.opt.arg_subscription_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _purchases_subscriptions_revoke(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.purchases().subscriptions_revoke(&self.opt.arg_package_name, &self.opt.arg_subscription_id, &self.opt.arg_token); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_edits { + if self.opt.cmd_apklistings_delete { + call_result = self._edits_apklistings_delete(dry_run, &mut err); + } else if self.opt.cmd_apklistings_deleteall { + call_result = self._edits_apklistings_deleteall(dry_run, &mut err); + } else if self.opt.cmd_apklistings_get { + call_result = self._edits_apklistings_get(dry_run, &mut err); + } else if self.opt.cmd_apklistings_list { + call_result = self._edits_apklistings_list(dry_run, &mut err); + } else if self.opt.cmd_apklistings_patch { + call_result = self._edits_apklistings_patch(dry_run, &mut err); + } else if self.opt.cmd_apklistings_update { + call_result = self._edits_apklistings_update(dry_run, &mut err); + } else if self.opt.cmd_apks_addexternallyhosted { + call_result = self._edits_apks_addexternallyhosted(dry_run, &mut err); + } else if self.opt.cmd_apks_list { + call_result = self._edits_apks_list(dry_run, &mut err); + } else if self.opt.cmd_apks_upload { + call_result = self._edits_apks_upload(dry_run, &mut err); + } else if self.opt.cmd_commit { + call_result = self._edits_commit(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._edits_delete(dry_run, &mut err); + } else if self.opt.cmd_details_get { + call_result = self._edits_details_get(dry_run, &mut err); + } else if self.opt.cmd_details_patch { + call_result = self._edits_details_patch(dry_run, &mut err); + } else if self.opt.cmd_details_update { + call_result = self._edits_details_update(dry_run, &mut err); + } else if self.opt.cmd_expansionfiles_get { + call_result = self._edits_expansionfiles_get(dry_run, &mut err); + } else if self.opt.cmd_expansionfiles_patch { + call_result = self._edits_expansionfiles_patch(dry_run, &mut err); + } else if self.opt.cmd_expansionfiles_update { + call_result = self._edits_expansionfiles_update(dry_run, &mut err); + } else if self.opt.cmd_expansionfiles_upload { + call_result = self._edits_expansionfiles_upload(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._edits_get(dry_run, &mut err); + } else if self.opt.cmd_images_delete { + call_result = self._edits_images_delete(dry_run, &mut err); + } else if self.opt.cmd_images_deleteall { + call_result = self._edits_images_deleteall(dry_run, &mut err); + } else if self.opt.cmd_images_list { + call_result = self._edits_images_list(dry_run, &mut err); + } else if self.opt.cmd_images_upload { + call_result = self._edits_images_upload(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._edits_insert(dry_run, &mut err); + } else if self.opt.cmd_listings_delete { + call_result = self._edits_listings_delete(dry_run, &mut err); + } else if self.opt.cmd_listings_deleteall { + call_result = self._edits_listings_deleteall(dry_run, &mut err); + } else if self.opt.cmd_listings_get { + call_result = self._edits_listings_get(dry_run, &mut err); + } else if self.opt.cmd_listings_list { + call_result = self._edits_listings_list(dry_run, &mut err); + } else if self.opt.cmd_listings_patch { + call_result = self._edits_listings_patch(dry_run, &mut err); + } else if self.opt.cmd_listings_update { + call_result = self._edits_listings_update(dry_run, &mut err); + } else if self.opt.cmd_testers_get { + call_result = self._edits_testers_get(dry_run, &mut err); + } else if self.opt.cmd_testers_patch { + call_result = self._edits_testers_patch(dry_run, &mut err); + } else if self.opt.cmd_testers_update { + call_result = self._edits_testers_update(dry_run, &mut err); + } else if self.opt.cmd_tracks_get { + call_result = self._edits_tracks_get(dry_run, &mut err); + } else if self.opt.cmd_tracks_list { + call_result = self._edits_tracks_list(dry_run, &mut err); + } else if self.opt.cmd_tracks_patch { + call_result = self._edits_tracks_patch(dry_run, &mut err); + } else if self.opt.cmd_tracks_update { + call_result = self._edits_tracks_update(dry_run, &mut err); + } else if self.opt.cmd_validate { + call_result = self._edits_validate(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_inappproducts { + if self.opt.cmd_batch { + call_result = self._inappproducts_batch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._inappproducts_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._inappproducts_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._inappproducts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._inappproducts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._inappproducts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._inappproducts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_purchases { + if self.opt.cmd_products_get { + call_result = self._purchases_products_get(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_cancel { + call_result = self._purchases_subscriptions_cancel(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_defer { + call_result = self._purchases_subscriptions_defer(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_get { + call_result = self._purchases_subscriptions_get(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_refund { + call_result = self._purchases_subscriptions_refund(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_revoke { + call_result = self._purchases_subscriptions_revoke(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "androidpublisher2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "androidpublisher2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AndroidPublisher::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/appsactivity1-cli/Cargo.toml b/gen/appsactivity1-cli/Cargo.toml new file mode 100644 index 00000000000..973b9bcbea7 --- /dev/null +++ b/gen/appsactivity1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-appsactivity1-cli" +version = "0.0.1+20140828" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with appsactivity (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/appsactivity1-cli" +homepage = "https://developers.google.com/google-apps/activity/" +documentation = "http://byron.github.io/google-apis-rs/google_appsactivity1_cli" +license = "MIT" +keywords = ["appsactivity", "google", "cli"] + +[[bin]] +name = "appsactivity1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-appsactivity1] +path = "../appsactivity1" diff --git a/gen/appsactivity1-cli/LICENSE.md b/gen/appsactivity1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/appsactivity1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/appsactivity1-cli/README.md b/gen/appsactivity1-cli/README.md new file mode 100644 index 00000000000..73dc6c238e0 --- /dev/null +++ b/gen/appsactivity1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO APPSACTIVITY:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/appsactivity1-cli/mkdocs.yml b/gen/appsactivity1-cli/mkdocs.yml new file mode 100644 index 00000000000..bb4c5c8a7c3 --- /dev/null +++ b/gen/appsactivity1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: appsactivity v0.0.1+20140828 +site_url: http://byron.github.io/google-apis-rs/google-appsactivity1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/appsactivity1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_list.md', 'Activities', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/appsactivity1-cli/src/cmn.rs b/gen/appsactivity1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/appsactivity1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/appsactivity1-cli/src/main.rs b/gen/appsactivity1-cli/src/main.rs new file mode 100644 index 00000000000..7f995878862 --- /dev/null +++ b/gen/appsactivity1-cli/src/main.rs @@ -0,0 +1,194 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_appsactivity1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + appsactivity1 [options] activities list [-p ]... [-o ] + appsactivity1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Appsactivity>, +} + + +impl Engine { + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.activities().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-id" => { + call = call.user_id(value.unwrap_or("")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "grouping-strategy" => { + call = call.grouping_strategy(value.unwrap_or("")); + }, + "drive-file-id" => { + call = call.drive_file_id(value.unwrap_or("")); + }, + "drive-ancestor-id" => { + call = call.drive_ancestor_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_activities { + if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "appsactivity1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "appsactivity1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Appsactivity::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/appstate1-cli/Cargo.toml b/gen/appstate1-cli/Cargo.toml new file mode 100644 index 00000000000..af7b62a0ec7 --- /dev/null +++ b/gen/appstate1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-appstate1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with App State (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/appstate1-cli" +homepage = "https://developers.google.com/games/services/web/api/states" +documentation = "http://byron.github.io/google-apis-rs/google_appstate1_cli" +license = "MIT" +keywords = ["appstate", "google", "cli"] + +[[bin]] +name = "appstate1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-appstate1] +path = "../appstate1" diff --git a/gen/appstate1-cli/LICENSE.md b/gen/appstate1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/appstate1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/appstate1-cli/README.md b/gen/appstate1-cli/README.md new file mode 100644 index 00000000000..7cd835a80d0 --- /dev/null +++ b/gen/appstate1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO APPSTATE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/appstate1-cli/mkdocs.yml b/gen/appstate1-cli/mkdocs.yml new file mode 100644 index 00000000000..09996fa33b7 --- /dev/null +++ b/gen/appstate1-cli/mkdocs.yml @@ -0,0 +1,21 @@ +site_name: App State v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-appstate1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/appstate1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['states_clear.md', 'States', 'Clear'] +- ['states_delete.md', 'States', 'Delete'] +- ['states_get.md', 'States', 'Get'] +- ['states_list.md', 'States', 'List'] +- ['states_update.md', 'States', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/appstate1-cli/src/cmn.rs b/gen/appstate1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/appstate1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/appstate1-cli/src/main.rs b/gen/appstate1-cli/src/main.rs new file mode 100644 index 00000000000..4441e7b652f --- /dev/null +++ b/gen/appstate1-cli/src/main.rs @@ -0,0 +1,391 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_appstate1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + appstate1 [options] states clear [-p ]... [-o ] + appstate1 [options] states delete [-p ]... + appstate1 [options] states get [-p ]... [-o ] + appstate1 [options] states list [-p ]... [-o ] + appstate1 [options] states update -r ... [-p ]... [-o ] + appstate1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AppState>, +} + + +impl Engine { + fn _states_clear(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let state_key: i32 = arg_from_str(&self.opt.arg_state_key, err, "", "integer"); + let mut call = self.hub.states().clear(state_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "current-data-version" => { + call = call.current_data_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _states_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let state_key: i32 = arg_from_str(&self.opt.arg_state_key, err, "", "integer"); + let mut call = self.hub.states().delete(state_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _states_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let state_key: i32 = arg_from_str(&self.opt.arg_state_key, err, "", "integer"); + let mut call = self.hub.states().get(state_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _states_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.states().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "include-data" => { + call = call.include_data(arg_from_str(value.unwrap_or("false"), err, "include-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _states_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UpdateRequest = Default::default(); + let state_key: i32 = arg_from_str(&self.opt.arg_state_key, err, "", "integer"); + let mut call = self.hub.states().update(&request, state_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "current-state-version" => { + call = call.current_state_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "data" => { + request.data = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_states { + if self.opt.cmd_clear { + call_result = self._states_clear(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._states_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._states_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._states_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._states_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "appstate1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "appstate1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AppState::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/audit1-cli/Cargo.toml b/gen/audit1-cli/Cargo.toml new file mode 100644 index 00000000000..f29b9f7a6ac --- /dev/null +++ b/gen/audit1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-audit1-cli" +version = "0.0.1+20130108" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with audit (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/audit1-cli" +homepage = "https://developers.google.com/google-apps/admin-audit/get_started" +documentation = "http://byron.github.io/google-apis-rs/google_audit1_cli" +license = "MIT" +keywords = ["audit", "google", "cli"] + +[[bin]] +name = "audit1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-audit1] +path = "../audit1" diff --git a/gen/audit1-cli/LICENSE.md b/gen/audit1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/audit1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/audit1-cli/README.md b/gen/audit1-cli/README.md new file mode 100644 index 00000000000..a9979376493 --- /dev/null +++ b/gen/audit1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO AUDIT:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/audit1-cli/mkdocs.yml b/gen/audit1-cli/mkdocs.yml new file mode 100644 index 00000000000..382f806e922 --- /dev/null +++ b/gen/audit1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: audit v0.0.1+20130108 +site_url: http://byron.github.io/google-apis-rs/google-audit1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/audit1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_list.md', 'Activities', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/audit1-cli/src/cmn.rs b/gen/audit1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/audit1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/audit1-cli/src/main.rs b/gen/audit1-cli/src/main.rs new file mode 100644 index 00000000000..55a67d0534c --- /dev/null +++ b/gen/audit1-cli/src/main.rs @@ -0,0 +1,196 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_audit1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + audit1 [options] activities list [-p ]... [-o ] + audit1 --help + +All documentation details can be found TODO: + +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] +"); + +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::Audit>, +} + + +impl Engine { + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.activities().list(&self.opt.arg_customer_id, &self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "event-name" => { + call = call.event_name(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "continuation-token" => { + call = call.continuation_token(value.unwrap_or("")); + }, + "caller" => { + call = call.caller(value.unwrap_or("")); + }, + "actor-ip-address" => { + call = call.actor_ip_address(value.unwrap_or("")); + }, + "actor-email" => { + call = call.actor_email(value.unwrap_or("")); + }, + "actor-application-id" => { + call = call.actor_application_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_activities { + if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "audit1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "audit1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Audit::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/autoscaler1_beta2-cli/Cargo.toml b/gen/autoscaler1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..dfa16d38270 --- /dev/null +++ b/gen/autoscaler1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-autoscaler1_beta2-cli" +version = "0.0.1+20141112" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with autoscaler (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/autoscaler1_beta2-cli" +homepage = "http://developers.google.com/compute/docs/autoscaler" +documentation = "http://byron.github.io/google-apis-rs/google_autoscaler1_beta2_cli" +license = "MIT" +keywords = ["autoscaler", "google", "cli"] + +[[bin]] +name = "autoscaler1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-autoscaler1_beta2] +path = "../autoscaler1_beta2" diff --git a/gen/autoscaler1_beta2-cli/LICENSE.md b/gen/autoscaler1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/autoscaler1_beta2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/autoscaler1_beta2-cli/README.md b/gen/autoscaler1_beta2-cli/README.md new file mode 100644 index 00000000000..61f8889ddde --- /dev/null +++ b/gen/autoscaler1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO AUTOSCALER:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/autoscaler1_beta2-cli/mkdocs.yml b/gen/autoscaler1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..23b13f56b6b --- /dev/null +++ b/gen/autoscaler1_beta2-cli/mkdocs.yml @@ -0,0 +1,26 @@ +site_name: autoscaler v0.0.1+20141112 +site_url: http://byron.github.io/google-apis-rs/google-autoscaler1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/autoscaler1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['autoscalers_delete.md', 'Autoscalers', 'Delete'] +- ['autoscalers_get.md', 'Autoscalers', 'Get'] +- ['autoscalers_insert.md', 'Autoscalers', 'Insert'] +- ['autoscalers_list.md', 'Autoscalers', 'List'] +- ['autoscalers_patch.md', 'Autoscalers', 'Patch'] +- ['autoscalers_update.md', 'Autoscalers', 'Update'] +- ['zone-operations_delete.md', 'Zone Operations', 'Delete'] +- ['zone-operations_get.md', 'Zone Operations', 'Get'] +- ['zone-operations_list.md', 'Zone Operations', 'List'] +- ['zones_list.md', 'Zones', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/autoscaler1_beta2-cli/src/cmn.rs b/gen/autoscaler1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/autoscaler1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/autoscaler1_beta2-cli/src/main.rs b/gen/autoscaler1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..912011986e3 --- /dev/null +++ b/gen/autoscaler1_beta2-cli/src/main.rs @@ -0,0 +1,824 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_autoscaler1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + autoscaler1-beta2 [options] autoscalers delete [-p ]... [-o ] + autoscaler1-beta2 [options] autoscalers get [-p ]... [-o ] + autoscaler1-beta2 [options] autoscalers insert -r ... [-p ]... [-o ] + autoscaler1-beta2 [options] autoscalers list [-p ]... [-o ] + autoscaler1-beta2 [options] autoscalers patch -r ... [-p ]... [-o ] + autoscaler1-beta2 [options] autoscalers update -r ... [-p ]... [-o ] + autoscaler1-beta2 [options] zone-operations delete [-p ]... + autoscaler1-beta2 [options] zone-operations get [-p ]... [-o ] + autoscaler1-beta2 [options] zone-operations list [-p ]... [-o ] + autoscaler1-beta2 [options] zones list [-p ]... [-o ] + autoscaler1-beta2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::AutoscalerHub>, +} + + +impl Engine { + fn _autoscalers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.autoscalers().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_autoscaler); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _autoscalers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.autoscalers().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_autoscaler); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _autoscalers_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Autoscaler = Default::default(); + let mut call = self.hub.autoscalers().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_autoscaling_policy_init(request: &mut api::Autoscaler) { + if request.autoscaling_policy.is_none() { + request.autoscaling_policy = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "autoscaling-policy.max-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().max_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.max-num-replicas", "integer"); + }, + "autoscaling-policy.cpu-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cpu_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.cpu-utilization.utilization-target", "number"); + }, + "autoscaling-policy.min-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().min_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.min-num-replicas", "integer"); + }, + "autoscaling-policy.cool-down-period-sec" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cool_down_period_sec = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.cool-down-period-sec", "integer"); + }, + "autoscaling-policy.load-balancing-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().load_balancing_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.load-balancing-utilization.utilization-target", "number"); + }, + "target" => { + request_autoscaling_policy_init(&mut request); + request.target = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request_autoscaling_policy_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_autoscaling_policy_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_autoscaling_policy_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_autoscaling_policy_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _autoscalers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.autoscalers().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _autoscalers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Autoscaler = Default::default(); + let mut call = self.hub.autoscalers().patch(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_autoscaler); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_autoscaling_policy_init(request: &mut api::Autoscaler) { + if request.autoscaling_policy.is_none() { + request.autoscaling_policy = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "autoscaling-policy.max-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().max_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.max-num-replicas", "integer"); + }, + "autoscaling-policy.cpu-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cpu_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.cpu-utilization.utilization-target", "number"); + }, + "autoscaling-policy.min-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().min_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.min-num-replicas", "integer"); + }, + "autoscaling-policy.cool-down-period-sec" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cool_down_period_sec = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.cool-down-period-sec", "integer"); + }, + "autoscaling-policy.load-balancing-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().load_balancing_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.load-balancing-utilization.utilization-target", "number"); + }, + "target" => { + request_autoscaling_policy_init(&mut request); + request.target = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request_autoscaling_policy_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_autoscaling_policy_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_autoscaling_policy_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_autoscaling_policy_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _autoscalers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Autoscaler = Default::default(); + let mut call = self.hub.autoscalers().update(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_autoscaler); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_autoscaling_policy_init(request: &mut api::Autoscaler) { + if request.autoscaling_policy.is_none() { + request.autoscaling_policy = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "autoscaling-policy.max-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().max_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.max-num-replicas", "integer"); + }, + "autoscaling-policy.cpu-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cpu_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.cpu-utilization.utilization-target", "number"); + }, + "autoscaling-policy.min-num-replicas" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().min_num_replicas = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.min-num-replicas", "integer"); + }, + "autoscaling-policy.cool-down-period-sec" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().cool_down_period_sec = arg_from_str(value.unwrap_or("-0"), err, "autoscaling-policy.cool-down-period-sec", "integer"); + }, + "autoscaling-policy.load-balancing-utilization.utilization-target" => { + request_autoscaling_policy_init(&mut request); + request.autoscaling_policy.as_mut().unwrap().load_balancing_utilization.utilization_target = arg_from_str(value.unwrap_or("0.0"), err, "autoscaling-policy.load-balancing-utilization.utilization-target", "number"); + }, + "target" => { + request_autoscaling_policy_init(&mut request); + request.target = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request_autoscaling_policy_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_autoscaling_policy_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_autoscaling_policy_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_autoscaling_policy_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _zone_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zones_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zones().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_autoscalers { + if self.opt.cmd_delete { + call_result = self._autoscalers_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._autoscalers_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._autoscalers_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._autoscalers_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._autoscalers_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._autoscalers_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zone_operations { + if self.opt.cmd_delete { + call_result = self._zone_operations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._zone_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zone_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zones { + if self.opt.cmd_list { + call_result = self._zones_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "autoscaler1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "autoscaler1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::AutoscalerHub::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/bigquery2-cli/Cargo.toml b/gen/bigquery2-cli/Cargo.toml new file mode 100644 index 00000000000..63715b65f97 --- /dev/null +++ b/gen/bigquery2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-bigquery2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with bigquery (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/bigquery2-cli" +homepage = "https://developers.google.com/bigquery/docs/overview" +documentation = "http://byron.github.io/google-apis-rs/google_bigquery2_cli" +license = "MIT" +keywords = ["bigquery", "google", "cli"] + +[[bin]] +name = "bigquery2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-bigquery2] +path = "../bigquery2" diff --git a/gen/bigquery2-cli/LICENSE.md b/gen/bigquery2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/bigquery2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/bigquery2-cli/README.md b/gen/bigquery2-cli/README.md new file mode 100644 index 00000000000..7e740871395 --- /dev/null +++ b/gen/bigquery2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO BIGQUERY:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/bigquery2-cli/mkdocs.yml b/gen/bigquery2-cli/mkdocs.yml new file mode 100644 index 00000000000..3ddf30c613a --- /dev/null +++ b/gen/bigquery2-cli/mkdocs.yml @@ -0,0 +1,36 @@ +site_name: bigquery v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-bigquery2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/bigquery2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['datasets_delete.md', 'Datasets', 'Delete'] +- ['datasets_get.md', 'Datasets', 'Get'] +- ['datasets_insert.md', 'Datasets', 'Insert'] +- ['datasets_list.md', 'Datasets', 'List'] +- ['datasets_patch.md', 'Datasets', 'Patch'] +- ['datasets_update.md', 'Datasets', 'Update'] +- ['jobs_get.md', 'Jobs', 'Get'] +- ['jobs_get-query-results.md', 'Jobs', 'Get Query Results'] +- ['jobs_insert.md', 'Jobs', 'Insert'] +- ['jobs_list.md', 'Jobs', 'List'] +- ['jobs_query.md', 'Jobs', 'Query'] +- ['projects_list.md', 'Projects', 'List'] +- ['tabledata_insert-all.md', 'Tabledata', 'Insert All'] +- ['tabledata_list.md', 'Tabledata', 'List'] +- ['tables_delete.md', 'Tables', 'Delete'] +- ['tables_get.md', 'Tables', 'Get'] +- ['tables_insert.md', 'Tables', 'Insert'] +- ['tables_list.md', 'Tables', 'List'] +- ['tables_patch.md', 'Tables', 'Patch'] +- ['tables_update.md', 'Tables', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/bigquery2-cli/src/cmn.rs b/gen/bigquery2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/bigquery2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/bigquery2-cli/src/main.rs b/gen/bigquery2-cli/src/main.rs new file mode 100644 index 00000000000..c1c65a89a46 --- /dev/null +++ b/gen/bigquery2-cli/src/main.rs @@ -0,0 +1,2008 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_bigquery2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + bigquery2 [options] datasets delete [-p ]... + bigquery2 [options] datasets get [-p ]... [-o ] + bigquery2 [options] datasets insert -r ... [-p ]... [-o ] + bigquery2 [options] datasets list [-p ]... [-o ] + bigquery2 [options] datasets patch -r ... [-p ]... [-o ] + bigquery2 [options] datasets update -r ... [-p ]... [-o ] + bigquery2 [options] jobs get [-p ]... [-o ] + bigquery2 [options] jobs get-query-results [-p ]... [-o ] + bigquery2 [options] jobs insert -r ... -u (simple|resumable) [-p ]... [-o ] + bigquery2 [options] jobs list [-p ]... [-o ] + bigquery2 [options] jobs query -r ... [-p ]... [-o ] + bigquery2 [options] projects list [-p ]... [-o ] + bigquery2 [options] tabledata insert-all -r ... [-p ]... [-o ] + bigquery2 [options] tabledata list [-p ]... [-o ] + bigquery2 [options] tables delete [-p ]... + bigquery2 [options] tables get [-p ]... [-o ] + bigquery2 [options] tables insert -r ... [-p ]... [-o ] + bigquery2 [options] tables list [-p ]... [-o ] + bigquery2 [options] tables patch -r ... [-p ]... [-o ] + bigquery2 [options] tables update -r ... [-p ]... [-o ] + bigquery2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Bigquery>, +} + + +impl Engine { + fn _datasets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datasets().delete(&self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "delete-contents" => { + call = call.delete_contents(arg_from_str(value.unwrap_or("false"), err, "delete-contents", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _datasets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datasets().get(&self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().insert(&request, &self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_dataset_reference_init(request: &mut api::Dataset) { + if request.dataset_reference.is_none() { + request.dataset_reference = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "dataset-reference.project-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "dataset-reference.dataset-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_dataset_reference_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "default-table-expiration-ms" => { + request_dataset_reference_init(&mut request); + request.default_table_expiration_ms = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_dataset_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_dataset_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_dataset_reference_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_dataset_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_dataset_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datasets().list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "all" => { + call = call.all(arg_from_str(value.unwrap_or("false"), err, "all", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().patch(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_dataset_reference_init(request: &mut api::Dataset) { + if request.dataset_reference.is_none() { + request.dataset_reference = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "dataset-reference.project-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "dataset-reference.dataset-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_dataset_reference_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "default-table-expiration-ms" => { + request_dataset_reference_init(&mut request); + request.default_table_expiration_ms = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_dataset_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_dataset_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_dataset_reference_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_dataset_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_dataset_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().update(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_dataset_reference_init(request: &mut api::Dataset) { + if request.dataset_reference.is_none() { + request.dataset_reference = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "dataset-reference.project-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "dataset-reference.dataset-id" => { + request_dataset_reference_init(&mut request); + request.dataset_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "creation-time" => { + request_dataset_reference_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "default-table-expiration-ms" => { + request_dataset_reference_init(&mut request); + request.default_table_expiration_ms = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_dataset_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_dataset_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_dataset_reference_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_dataset_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_dataset_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.jobs().get(&self.opt.arg_project_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_get_query_results(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.jobs().get_query_results(&self.opt.arg_project_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "timeout-ms" => { + call = call.timeout_ms(arg_from_str(value.unwrap_or("-0"), err, "timeout-ms", "integer")); + }, + "start-index" => { + call = call.start_index(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Job = Default::default(); + let mut call = self.hub.jobs().insert(&request, &self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_configuration_init(request: &mut api::Job) { + if request.configuration.is_none() { + request.configuration = Some(Default::default()); + } + } + + fn request_job_reference_init(request: &mut api::Job) { + if request.job_reference.is_none() { + request.job_reference = Some(Default::default()); + } + } + + fn request_statistics_init(request: &mut api::Job) { + if request.statistics.is_none() { + request.statistics = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Job) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.state" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().state = value.unwrap_or("").to_string(); + }, + "status.error-result.debug-info" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().error_result.debug_info = value.unwrap_or("").to_string(); + }, + "status.error-result.message" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().error_result.message = value.unwrap_or("").to_string(); + }, + "status.error-result.reason" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().error_result.reason = value.unwrap_or("").to_string(); + }, + "status.error-result.location" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().error_result.location = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "statistics.load.output-rows" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().load.output_rows = value.unwrap_or("").to_string(); + }, + "statistics.load.input-files" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().load.input_files = value.unwrap_or("").to_string(); + }, + "statistics.load.input-file-bytes" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().load.input_file_bytes = value.unwrap_or("").to_string(); + }, + "statistics.load.output-bytes" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().load.output_bytes = value.unwrap_or("").to_string(); + }, + "statistics.creation-time" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().creation_time = value.unwrap_or("").to_string(); + }, + "statistics.total-bytes-processed" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().total_bytes_processed = value.unwrap_or("").to_string(); + }, + "statistics.start-time" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().start_time = value.unwrap_or("").to_string(); + }, + "statistics.query.cache-hit" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().query.cache_hit = arg_from_str(value.unwrap_or("false"), err, "statistics.query.cache-hit", "boolean"); + }, + "statistics.query.total-bytes-processed" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().query.total_bytes_processed = value.unwrap_or("").to_string(); + }, + "statistics.end-time" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().end_time = value.unwrap_or("").to_string(); + }, + "statistics.extract.destination-uri-file-counts" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().extract.destination_uri_file_counts.push(arg_from_str(value.unwrap_or("-0"), err, "statistics.extract.destination-uri-file-counts", "int64")); + }, + "job-reference.project-id" => { + request_job_reference_init(&mut request); + request.job_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "job-reference.job-id" => { + request_job_reference_init(&mut request); + request.job_reference.as_mut().unwrap().job_id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_job_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "user-email" => { + request_job_reference_init(&mut request); + request.user_email = Some(value.unwrap_or("").to_string()); + }, + "configuration.load.encoding" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.encoding = value.unwrap_or("").to_string(); + }, + "configuration.load.skip-leading-rows" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.skip_leading_rows = arg_from_str(value.unwrap_or("-0"), err, "configuration.load.skip-leading-rows", "integer"); + }, + "configuration.load.quote" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.quote = value.unwrap_or("").to_string(); + }, + "configuration.load.source-format" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.source_format = value.unwrap_or("").to_string(); + }, + "configuration.load.destination-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.destination_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.load.destination-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.destination_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.load.destination-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.destination_table.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.load.max-bad-records" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.max_bad_records = arg_from_str(value.unwrap_or("-0"), err, "configuration.load.max-bad-records", "integer"); + }, + "configuration.load.allow-jagged-rows" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.allow_jagged_rows = arg_from_str(value.unwrap_or("false"), err, "configuration.load.allow-jagged-rows", "boolean"); + }, + "configuration.load.write-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.write_disposition = value.unwrap_or("").to_string(); + }, + "configuration.load.source-uris" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.source_uris.push(value.unwrap_or("").to_string()); + }, + "configuration.load.field-delimiter" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.field_delimiter = value.unwrap_or("").to_string(); + }, + "configuration.load.create-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.create_disposition = value.unwrap_or("").to_string(); + }, + "configuration.load.schema-inline-format" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.schema_inline_format = value.unwrap_or("").to_string(); + }, + "configuration.load.schema-inline" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.schema_inline = value.unwrap_or("").to_string(); + }, + "configuration.load.allow-quoted-newlines" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.allow_quoted_newlines = arg_from_str(value.unwrap_or("false"), err, "configuration.load.allow-quoted-newlines", "boolean"); + }, + "configuration.load.projection-fields" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.projection_fields.push(value.unwrap_or("").to_string()); + }, + "configuration.load.ignore-unknown-values" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().load.ignore_unknown_values = arg_from_str(value.unwrap_or("false"), err, "configuration.load.ignore-unknown-values", "boolean"); + }, + "configuration.dry-run" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().dry_run = arg_from_str(value.unwrap_or("false"), err, "configuration.dry-run", "boolean"); + }, + "configuration.link.create-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.create_disposition = value.unwrap_or("").to_string(); + }, + "configuration.link.write-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.write_disposition = value.unwrap_or("").to_string(); + }, + "configuration.link.destination-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.destination_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.link.destination-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.destination_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.link.destination-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.destination_table.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.link.source-uri" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().link.source_uri.push(value.unwrap_or("").to_string()); + }, + "configuration.query.flatten-results" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.flatten_results = arg_from_str(value.unwrap_or("false"), err, "configuration.query.flatten-results", "boolean"); + }, + "configuration.query.use-query-cache" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.use_query_cache = arg_from_str(value.unwrap_or("false"), err, "configuration.query.use-query-cache", "boolean"); + }, + "configuration.query.default-dataset.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.default_dataset.project_id = value.unwrap_or("").to_string(); + }, + "configuration.query.default-dataset.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.default_dataset.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.query.destination-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.destination_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.query.destination-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.destination_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.query.destination-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.destination_table.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.query.priority" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.priority = value.unwrap_or("").to_string(); + }, + "configuration.query.write-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.write_disposition = value.unwrap_or("").to_string(); + }, + "configuration.query.allow-large-results" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.allow_large_results = arg_from_str(value.unwrap_or("false"), err, "configuration.query.allow-large-results", "boolean"); + }, + "configuration.query.create-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.create_disposition = value.unwrap_or("").to_string(); + }, + "configuration.query.query" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.query = value.unwrap_or("").to_string(); + }, + "configuration.query.preserve-nulls" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().query.preserve_nulls = arg_from_str(value.unwrap_or("false"), err, "configuration.query.preserve-nulls", "boolean"); + }, + "configuration.copy.create-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.create_disposition = value.unwrap_or("").to_string(); + }, + "configuration.copy.write-disposition" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.write_disposition = value.unwrap_or("").to_string(); + }, + "configuration.copy.destination-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.destination_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.copy.destination-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.destination_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.copy.destination-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.destination_table.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.copy.source-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.source_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.copy.source-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.source_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.copy.source-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().copy.source_table.dataset_id = value.unwrap_or("").to_string(); + }, + "configuration.extract.destination-uri" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.destination_uri = value.unwrap_or("").to_string(); + }, + "configuration.extract.compression" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.compression = value.unwrap_or("").to_string(); + }, + "configuration.extract.field-delimiter" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.field_delimiter = value.unwrap_or("").to_string(); + }, + "configuration.extract.destination-format" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.destination_format = value.unwrap_or("").to_string(); + }, + "configuration.extract.print-header" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.print_header = arg_from_str(value.unwrap_or("false"), err, "configuration.extract.print-header", "boolean"); + }, + "configuration.extract.destination-uris" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.destination_uris.push(value.unwrap_or("").to_string()); + }, + "configuration.extract.source-table.project-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.source_table.project_id = value.unwrap_or("").to_string(); + }, + "configuration.extract.source-table.table-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.source_table.table_id = value.unwrap_or("").to_string(); + }, + "configuration.extract.source-table.dataset-id" => { + request_configuration_init(&mut request); + request.configuration.as_mut().unwrap().extract.source_table.dataset_id = value.unwrap_or("").to_string(); + }, + "id" => { + request_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_configuration_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.jobs().list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "state-filter" => { + call = call.add_state_filter(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "all-users" => { + call = call.all_users(arg_from_str(value.unwrap_or("false"), err, "all-users", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::QueryRequest = Default::default(); + let mut call = self.hub.jobs().query(&request, &self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_default_dataset_init(request: &mut api::QueryRequest) { + if request.default_dataset.is_none() { + request.default_dataset = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "timeout-ms" => { + request.timeout_ms = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-ms", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "dry-run" => { + request.dry_run = Some(arg_from_str(value.unwrap_or("false"), err, "dry-run", "boolean")); + }, + "use-query-cache" => { + request.use_query_cache = Some(arg_from_str(value.unwrap_or("false"), err, "use-query-cache", "boolean")); + }, + "default-dataset.project-id" => { + request_default_dataset_init(&mut request); + request.default_dataset.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "default-dataset.dataset-id" => { + request_default_dataset_init(&mut request); + request.default_dataset.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "max-results" => { + request_default_dataset_init(&mut request); + request.max_results = Some(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "query" => { + request_default_dataset_init(&mut request); + request.query = Some(value.unwrap_or("").to_string()); + }, + "preserve-nulls" => { + request_default_dataset_init(&mut request); + request.preserve_nulls = Some(arg_from_str(value.unwrap_or("false"), err, "preserve-nulls", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tabledata_insert_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TableDataInsertAllRequest = Default::default(); + let mut call = self.hub.tabledata().insert_all(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ignore-unknown-values" => { + request.ignore_unknown_values = Some(arg_from_str(value.unwrap_or("false"), err, "ignore-unknown-values", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "skip-invalid-rows" => { + request.skip_invalid_rows = Some(arg_from_str(value.unwrap_or("false"), err, "skip-invalid-rows", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tabledata_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tabledata().list(&self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tables().delete(&self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tables().get(&self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().insert(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_table_reference_init(request: &mut api::Table) { + if request.table_reference.is_none() { + request.table_reference = Some(Default::default()); + } + } + + fn request_view_init(request: &mut api::Table) { + if request.view.is_none() { + request.view = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "table-reference.project-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "table-reference.table-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().table_id = value.unwrap_or("").to_string(); + }, + "table-reference.dataset-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "num-rows" => { + request_table_reference_init(&mut request); + request.num_rows = Some(value.unwrap_or("").to_string()); + }, + "num-bytes" => { + request_table_reference_init(&mut request); + request.num_bytes = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_table_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_table_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "expiration-time" => { + request_table_reference_init(&mut request); + request.expiration_time = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_table_reference_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_table_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_table_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "view.query" => { + request_view_init(&mut request); + request.view.as_mut().unwrap().query = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.tables().list(&self.opt.arg_project_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().patch(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_table_reference_init(request: &mut api::Table) { + if request.table_reference.is_none() { + request.table_reference = Some(Default::default()); + } + } + + fn request_view_init(request: &mut api::Table) { + if request.view.is_none() { + request.view = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "table-reference.project-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "table-reference.table-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().table_id = value.unwrap_or("").to_string(); + }, + "table-reference.dataset-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "num-rows" => { + request_table_reference_init(&mut request); + request.num_rows = Some(value.unwrap_or("").to_string()); + }, + "num-bytes" => { + request_table_reference_init(&mut request); + request.num_bytes = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_table_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_table_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "expiration-time" => { + request_table_reference_init(&mut request); + request.expiration_time = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_table_reference_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_table_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_table_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "view.query" => { + request_view_init(&mut request); + request.view.as_mut().unwrap().query = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().update(&request, &self.opt.arg_project_id, &self.opt.arg_dataset_id, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_table_reference_init(request: &mut api::Table) { + if request.table_reference.is_none() { + request.table_reference = Some(Default::default()); + } + } + + fn request_view_init(request: &mut api::Table) { + if request.view.is_none() { + request.view = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "table-reference.project-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().project_id = value.unwrap_or("").to_string(); + }, + "table-reference.table-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().table_id = value.unwrap_or("").to_string(); + }, + "table-reference.dataset-id" => { + request_table_reference_init(&mut request); + request.table_reference.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "num-rows" => { + request_table_reference_init(&mut request); + request.num_rows = Some(value.unwrap_or("").to_string()); + }, + "num-bytes" => { + request_table_reference_init(&mut request); + request.num_bytes = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_table_reference_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "friendly-name" => { + request_table_reference_init(&mut request); + request.friendly_name = Some(value.unwrap_or("").to_string()); + }, + "expiration-time" => { + request_table_reference_init(&mut request); + request.expiration_time = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_table_reference_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_table_reference_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_table_reference_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "view.query" => { + request_view_init(&mut request); + request.view.as_mut().unwrap().query = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_datasets { + if self.opt.cmd_delete { + call_result = self._datasets_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._datasets_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._datasets_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._datasets_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._datasets_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._datasets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_jobs { + if self.opt.cmd_get { + call_result = self._jobs_get(dry_run, &mut err); + } else if self.opt.cmd_get_query_results { + call_result = self._jobs_get_query_results(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._jobs_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._jobs_list(dry_run, &mut err); + } else if self.opt.cmd_query { + call_result = self._jobs_query(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_projects { + if self.opt.cmd_list { + call_result = self._projects_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tabledata { + if self.opt.cmd_insert_all { + call_result = self._tabledata_insert_all(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tabledata_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tables { + if self.opt.cmd_delete { + call_result = self._tables_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tables_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._tables_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tables_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tables_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._tables_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "bigquery2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "bigquery2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Bigquery::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/blogger3-cli/Cargo.toml b/gen/blogger3-cli/Cargo.toml new file mode 100644 index 00000000000..d05dca55b2e --- /dev/null +++ b/gen/blogger3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-blogger3-cli" +version = "0.0.1+20150208" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with blogger (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/blogger3-cli" +homepage = "https://developers.google.com/blogger/docs/3.0/getting_started" +documentation = "http://byron.github.io/google-apis-rs/google_blogger3_cli" +license = "MIT" +keywords = ["blogger", "google", "cli"] + +[[bin]] +name = "blogger3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-blogger3] +path = "../blogger3" diff --git a/gen/blogger3-cli/LICENSE.md b/gen/blogger3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/blogger3-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/blogger3-cli/README.md b/gen/blogger3-cli/README.md new file mode 100644 index 00000000000..f2320b7f986 --- /dev/null +++ b/gen/blogger3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO BLOGGER:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/blogger3-cli/mkdocs.yml b/gen/blogger3-cli/mkdocs.yml new file mode 100644 index 00000000000..2166dc0af31 --- /dev/null +++ b/gen/blogger3-cli/mkdocs.yml @@ -0,0 +1,49 @@ +site_name: blogger v0.0.1+20150208 +site_url: http://byron.github.io/google-apis-rs/google-blogger3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/blogger3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['blog-user-infos_get.md', 'Blog User Infos', 'Get'] +- ['blogs_get.md', 'Blogs', 'Get'] +- ['blogs_get-by-url.md', 'Blogs', 'Get By Url'] +- ['blogs_list-by-user.md', 'Blogs', 'List By User'] +- ['comments_approve.md', 'Comments', 'Approve'] +- ['comments_delete.md', 'Comments', 'Delete'] +- ['comments_get.md', 'Comments', 'Get'] +- ['comments_list.md', 'Comments', 'List'] +- ['comments_list-by-blog.md', 'Comments', 'List By Blog'] +- ['comments_mark-as-spam.md', 'Comments', 'Mark As Spam'] +- ['comments_remove-content.md', 'Comments', 'Remove Content'] +- ['page-views_get.md', 'Page Views', 'Get'] +- ['pages_delete.md', 'Pages', 'Delete'] +- ['pages_get.md', 'Pages', 'Get'] +- ['pages_insert.md', 'Pages', 'Insert'] +- ['pages_list.md', 'Pages', 'List'] +- ['pages_patch.md', 'Pages', 'Patch'] +- ['pages_publish.md', 'Pages', 'Publish'] +- ['pages_revert.md', 'Pages', 'Revert'] +- ['pages_update.md', 'Pages', 'Update'] +- ['post-user-infos_get.md', 'Post User Infos', 'Get'] +- ['post-user-infos_list.md', 'Post User Infos', 'List'] +- ['posts_delete.md', 'Posts', 'Delete'] +- ['posts_get.md', 'Posts', 'Get'] +- ['posts_get-by-path.md', 'Posts', 'Get By Path'] +- ['posts_insert.md', 'Posts', 'Insert'] +- ['posts_list.md', 'Posts', 'List'] +- ['posts_patch.md', 'Posts', 'Patch'] +- ['posts_publish.md', 'Posts', 'Publish'] +- ['posts_revert.md', 'Posts', 'Revert'] +- ['posts_search.md', 'Posts', 'Search'] +- ['posts_update.md', 'Posts', 'Update'] +- ['users_get.md', 'Users', 'Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/blogger3-cli/src/cmn.rs b/gen/blogger3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/blogger3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/blogger3-cli/src/main.rs b/gen/blogger3-cli/src/main.rs new file mode 100644 index 00000000000..621cc9b6d23 --- /dev/null +++ b/gen/blogger3-cli/src/main.rs @@ -0,0 +1,2581 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_blogger3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + blogger3 [options] blog-user-infos get [-p ]... [-o ] + blogger3 [options] blogs get [-p ]... [-o ] + blogger3 [options] blogs get-by-url [-p ]... [-o ] + blogger3 [options] blogs list-by-user [-p ]... [-o ] + blogger3 [options] comments approve [-p ]... [-o ] + blogger3 [options] comments delete [-p ]... + blogger3 [options] comments get [-p ]... [-o ] + blogger3 [options] comments list [-p ]... [-o ] + blogger3 [options] comments list-by-blog [-p ]... [-o ] + blogger3 [options] comments mark-as-spam [-p ]... [-o ] + blogger3 [options] comments remove-content [-p ]... [-o ] + blogger3 [options] page-views get [-p ]... [-o ] + blogger3 [options] pages delete [-p ]... + blogger3 [options] pages get [-p ]... [-o ] + blogger3 [options] pages insert -r ... [-p ]... [-o ] + blogger3 [options] pages list [-p ]... [-o ] + blogger3 [options] pages patch -r ... [-p ]... [-o ] + blogger3 [options] pages publish [-p ]... [-o ] + blogger3 [options] pages revert [-p ]... [-o ] + blogger3 [options] pages update -r ... [-p ]... [-o ] + blogger3 [options] post-user-infos get [-p ]... [-o ] + blogger3 [options] post-user-infos list [-p ]... [-o ] + blogger3 [options] posts delete [-p ]... + blogger3 [options] posts get [-p ]... [-o ] + blogger3 [options] posts get-by-path [-p ]... [-o ] + blogger3 [options] posts insert -r ... [-p ]... [-o ] + blogger3 [options] posts list [-p ]... [-o ] + blogger3 [options] posts patch -r ... [-p ]... [-o ] + blogger3 [options] posts publish [-p ]... [-o ] + blogger3 [options] posts revert [-p ]... [-o ] + blogger3 [options] posts search [-p ]... [-o ] + blogger3 [options] posts update -r ... [-p ]... [-o ] + blogger3 [options] users get [-p ]... [-o ] + blogger3 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Blogger>, +} + + +impl Engine { + fn _blog_user_infos_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.blog_user_infos().get(&self.opt.arg_user_id, &self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "max-posts" => { + call = call.max_posts(arg_from_str(value.unwrap_or("-0"), err, "max-posts", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _blogs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.blogs().get(&self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "max-posts" => { + call = call.max_posts(arg_from_str(value.unwrap_or("-0"), err, "max-posts", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _blogs_get_by_url(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.blogs().get_by_url(&self.opt.arg_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _blogs_list_by_user(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.blogs().list_by_user(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "role" => { + call = call.add_role(value.unwrap_or("")); + }, + "fetch-user-info" => { + call = call.fetch_user_info(arg_from_str(value.unwrap_or("false"), err, "fetch-user-info", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_approve(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().approve(&self.opt.arg_blog_id, &self.opt.arg_post_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().delete(&self.opt.arg_blog_id, &self.opt.arg_post_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _comments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().get(&self.opt.arg_blog_id, &self.opt.arg_post_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().list(&self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "start-date" => { + call = call.start_date(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "end-date" => { + call = call.end_date(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list_by_blog(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().list_by_blog(&self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "start-date" => { + call = call.start_date(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "end-date" => { + call = call.end_date(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_mark_as_spam(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().mark_as_spam(&self.opt.arg_blog_id, &self.opt.arg_post_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_remove_content(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.comments().remove_content(&self.opt.arg_blog_id, &self.opt.arg_post_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _page_views_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.page_views().get(&self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "range" => { + call = call.add_range(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pages().delete(&self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _pages_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pages().get(&self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Page = Default::default(); + let mut call = self.hub.pages().insert(&request, &self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "is-draft" => { + call = call.is_draft(arg_from_str(value.unwrap_or("false"), err, "is-draft", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Page) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Page) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_author_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_author_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_blog_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_blog_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_blog_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pages().list(&self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Page = Default::default(); + let mut call = self.hub.pages().patch(&request, &self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "revert" => { + call = call.revert(arg_from_str(value.unwrap_or("false"), err, "revert", "boolean")); + }, + "publish" => { + call = call.publish(arg_from_str(value.unwrap_or("false"), err, "publish", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Page) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Page) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_author_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_author_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_blog_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_blog_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_blog_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pages().publish(&self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_revert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.pages().revert(&self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pages_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Page = Default::default(); + let mut call = self.hub.pages().update(&request, &self.opt.arg_blog_id, &self.opt.arg_page_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "revert" => { + call = call.revert(arg_from_str(value.unwrap_or("false"), err, "revert", "boolean")); + }, + "publish" => { + call = call.publish(arg_from_str(value.unwrap_or("false"), err, "publish", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Page) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Page) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_author_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_author_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_blog_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_blog_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_blog_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _post_user_infos_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.post_user_infos().get(&self.opt.arg_user_id, &self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "max-comments" => { + call = call.max_comments(arg_from_str(value.unwrap_or("-0"), err, "max-comments", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _post_user_infos_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.post_user_infos().list(&self.opt.arg_user_id, &self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "start-date" => { + call = call.start_date(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "labels" => { + call = call.labels(value.unwrap_or("")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "end-date" => { + call = call.end_date(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().delete(&self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _posts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().get(&self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "max-comments" => { + call = call.max_comments(arg_from_str(value.unwrap_or("-0"), err, "max-comments", "integer")); + }, + "fetch-images" => { + call = call.fetch_images(arg_from_str(value.unwrap_or("false"), err, "fetch-images", "boolean")); + }, + "fetch-body" => { + call = call.fetch_body(arg_from_str(value.unwrap_or("false"), err, "fetch-body", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_get_by_path(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().get_by_path(&self.opt.arg_blog_id, &self.opt.arg_path); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "max-comments" => { + call = call.max_comments(arg_from_str(value.unwrap_or("-0"), err, "max-comments", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Post = Default::default(); + let mut call = self.hub.posts().insert(&request, &self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "is-draft" => { + call = call.is_draft(arg_from_str(value.unwrap_or("false"), err, "is-draft", "boolean")); + }, + "fetch-images" => { + call = call.fetch_images(arg_from_str(value.unwrap_or("false"), err, "fetch-images", "boolean")); + }, + "fetch-body" => { + call = call.fetch_body(arg_from_str(value.unwrap_or("false"), err, "fetch-body", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Post) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Post) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::Post) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_replies_init(request: &mut api::Post) { + if request.replies.is_none() { + request.replies = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "title-link" => { + request.title_link = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "reader-comments" => { + request_author_init(&mut request); + request.reader_comments = Some(value.unwrap_or("").to_string()); + }, + "labels" => { + request_author_init(&mut request); + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + request.labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "custom-meta-data" => { + request_author_init(&mut request); + request.custom_meta_data = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_author_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location.lat" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lat = arg_from_str(value.unwrap_or("0.0"), err, "location.lat", "number"); + }, + "location.lng" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lng = arg_from_str(value.unwrap_or("0.0"), err, "location.lng", "number"); + }, + "location.span" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().span = value.unwrap_or("").to_string(); + }, + "location.name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "replies.total-items" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().total_items = value.unwrap_or("").to_string(); + }, + "replies.self-link" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "title" => { + request_replies_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_replies_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replies_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_replies_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().list(&self.opt.arg_blog_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "view" => { + call = call.view(value.unwrap_or("")); + }, + "status" => { + call = call.add_status(value.unwrap_or("")); + }, + "start-date" => { + call = call.start_date(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "labels" => { + call = call.labels(value.unwrap_or("")); + }, + "fetch-images" => { + call = call.fetch_images(arg_from_str(value.unwrap_or("false"), err, "fetch-images", "boolean")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "end-date" => { + call = call.end_date(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Post = Default::default(); + let mut call = self.hub.posts().patch(&request, &self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "revert" => { + call = call.revert(arg_from_str(value.unwrap_or("false"), err, "revert", "boolean")); + }, + "publish" => { + call = call.publish(arg_from_str(value.unwrap_or("false"), err, "publish", "boolean")); + }, + "max-comments" => { + call = call.max_comments(arg_from_str(value.unwrap_or("-0"), err, "max-comments", "integer")); + }, + "fetch-images" => { + call = call.fetch_images(arg_from_str(value.unwrap_or("false"), err, "fetch-images", "boolean")); + }, + "fetch-body" => { + call = call.fetch_body(arg_from_str(value.unwrap_or("false"), err, "fetch-body", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Post) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Post) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::Post) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_replies_init(request: &mut api::Post) { + if request.replies.is_none() { + request.replies = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "title-link" => { + request.title_link = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "reader-comments" => { + request_author_init(&mut request); + request.reader_comments = Some(value.unwrap_or("").to_string()); + }, + "labels" => { + request_author_init(&mut request); + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + request.labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "custom-meta-data" => { + request_author_init(&mut request); + request.custom_meta_data = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_author_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location.lat" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lat = arg_from_str(value.unwrap_or("0.0"), err, "location.lat", "number"); + }, + "location.lng" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lng = arg_from_str(value.unwrap_or("0.0"), err, "location.lng", "number"); + }, + "location.span" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().span = value.unwrap_or("").to_string(); + }, + "location.name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "replies.total-items" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().total_items = value.unwrap_or("").to_string(); + }, + "replies.self-link" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "title" => { + request_replies_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_replies_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replies_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_replies_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().publish(&self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "publish-date" => { + call = call.publish_date(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_revert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().revert(&self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.posts().search(&self.opt.arg_blog_id, &self.opt.arg_q); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "fetch-bodies" => { + call = call.fetch_bodies(arg_from_str(value.unwrap_or("false"), err, "fetch-bodies", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _posts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Post = Default::default(); + let mut call = self.hub.posts().update(&request, &self.opt.arg_blog_id, &self.opt.arg_post_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "revert" => { + call = call.revert(arg_from_str(value.unwrap_or("false"), err, "revert", "boolean")); + }, + "publish" => { + call = call.publish(arg_from_str(value.unwrap_or("false"), err, "publish", "boolean")); + }, + "max-comments" => { + call = call.max_comments(arg_from_str(value.unwrap_or("-0"), err, "max-comments", "integer")); + }, + "fetch-images" => { + call = call.fetch_images(arg_from_str(value.unwrap_or("false"), err, "fetch-images", "boolean")); + }, + "fetch-body" => { + call = call.fetch_body(arg_from_str(value.unwrap_or("false"), err, "fetch-body", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Post) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_blog_init(request: &mut api::Post) { + if request.blog.is_none() { + request.blog = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::Post) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_replies_init(request: &mut api::Post) { + if request.replies.is_none() { + request.replies = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request.content = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "title-link" => { + request.title_link = Some(value.unwrap_or("").to_string()); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "reader-comments" => { + request_author_init(&mut request); + request.reader_comments = Some(value.unwrap_or("").to_string()); + }, + "labels" => { + request_author_init(&mut request); + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + request.labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "custom-meta-data" => { + request_author_init(&mut request); + request.custom_meta_data = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_author_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "blog.id" => { + request_blog_init(&mut request); + request.blog.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "etag" => { + request_blog_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location.lat" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lat = arg_from_str(value.unwrap_or("0.0"), err, "location.lat", "number"); + }, + "location.lng" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().lng = arg_from_str(value.unwrap_or("0.0"), err, "location.lng", "number"); + }, + "location.span" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().span = value.unwrap_or("").to_string(); + }, + "location.name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "replies.total-items" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().total_items = value.unwrap_or("").to_string(); + }, + "replies.self-link" => { + request_replies_init(&mut request); + request.replies.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "title" => { + request_replies_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_replies_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replies_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_replies_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.users().get(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_blog_user_infos { + if self.opt.cmd_get { + call_result = self._blog_user_infos_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_blogs { + if self.opt.cmd_get { + call_result = self._blogs_get(dry_run, &mut err); + } else if self.opt.cmd_get_by_url { + call_result = self._blogs_get_by_url(dry_run, &mut err); + } else if self.opt.cmd_list_by_user { + call_result = self._blogs_list_by_user(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_comments { + if self.opt.cmd_approve { + call_result = self._comments_approve(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._comments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._comments_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._comments_list(dry_run, &mut err); + } else if self.opt.cmd_list_by_blog { + call_result = self._comments_list_by_blog(dry_run, &mut err); + } else if self.opt.cmd_mark_as_spam { + call_result = self._comments_mark_as_spam(dry_run, &mut err); + } else if self.opt.cmd_remove_content { + call_result = self._comments_remove_content(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_page_views { + if self.opt.cmd_get { + call_result = self._page_views_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_pages { + if self.opt.cmd_delete { + call_result = self._pages_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._pages_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._pages_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._pages_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._pages_patch(dry_run, &mut err); + } else if self.opt.cmd_publish { + call_result = self._pages_publish(dry_run, &mut err); + } else if self.opt.cmd_revert { + call_result = self._pages_revert(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._pages_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_post_user_infos { + if self.opt.cmd_get { + call_result = self._post_user_infos_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._post_user_infos_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_posts { + if self.opt.cmd_delete { + call_result = self._posts_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._posts_get(dry_run, &mut err); + } else if self.opt.cmd_get_by_path { + call_result = self._posts_get_by_path(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._posts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._posts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._posts_patch(dry_run, &mut err); + } else if self.opt.cmd_publish { + call_result = self._posts_publish(dry_run, &mut err); + } else if self.opt.cmd_revert { + call_result = self._posts_revert(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._posts_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._posts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_users { + if self.opt.cmd_get { + call_result = self._users_get(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "blogger3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "blogger3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Blogger::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/books1-cli/Cargo.toml b/gen/books1-cli/Cargo.toml new file mode 100644 index 00000000000..a4c0b8b2aa1 --- /dev/null +++ b/gen/books1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-books1-cli" +version = "0.0.1+20150309" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with books (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/books1-cli" +homepage = "https://developers.google.com/books/docs/v1/getting_started" +documentation = "http://byron.github.io/google-apis-rs/google_books1_cli" +license = "MIT" +keywords = ["books", "google", "cli"] + +[[bin]] +name = "books1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-books1] +path = "../books1" diff --git a/gen/books1-cli/LICENSE.md b/gen/books1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/books1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/books1-cli/README.md b/gen/books1-cli/README.md new file mode 100644 index 00000000000..08b6452f313 --- /dev/null +++ b/gen/books1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO BOOKS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/books1-cli/mkdocs.yml b/gen/books1-cli/mkdocs.yml new file mode 100644 index 00000000000..ffefb03fb9a --- /dev/null +++ b/gen/books1-cli/mkdocs.yml @@ -0,0 +1,60 @@ +site_name: books v0.0.1+20150309 +site_url: http://byron.github.io/google-apis-rs/google-books1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/books1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['bookshelves_get.md', 'Bookshelves', 'Get'] +- ['bookshelves_list.md', 'Bookshelves', 'List'] +- ['bookshelves_volumes-list.md', 'Bookshelves', 'Volumes List'] +- ['cloudloading_add-book.md', 'Cloudloading', 'Add Book'] +- ['cloudloading_delete-book.md', 'Cloudloading', 'Delete Book'] +- ['cloudloading_update-book.md', 'Cloudloading', 'Update Book'] +- ['dictionary_list-offline-metadata.md', 'Dictionary', 'List Offline Metadata'] +- ['layers_annotation-data-get.md', 'Layers', 'Annotation Data Get'] +- ['layers_annotation-data-list.md', 'Layers', 'Annotation Data List'] +- ['layers_get.md', 'Layers', 'Get'] +- ['layers_list.md', 'Layers', 'List'] +- ['layers_volume-annotations-get.md', 'Layers', 'Volume Annotations Get'] +- ['layers_volume-annotations-list.md', 'Layers', 'Volume Annotations List'] +- ['myconfig_get-user-settings.md', 'Myconfig', 'Get User Settings'] +- ['myconfig_release-download-access.md', 'Myconfig', 'Release Download Access'] +- ['myconfig_request-access.md', 'Myconfig', 'Request Access'] +- ['myconfig_sync-volume-licenses.md', 'Myconfig', 'Sync Volume Licenses'] +- ['myconfig_update-user-settings.md', 'Myconfig', 'Update User Settings'] +- ['mylibrary_annotations-delete.md', 'Mylibrary', 'Annotations Delete'] +- ['mylibrary_annotations-insert.md', 'Mylibrary', 'Annotations Insert'] +- ['mylibrary_annotations-list.md', 'Mylibrary', 'Annotations List'] +- ['mylibrary_annotations-summary.md', 'Mylibrary', 'Annotations Summary'] +- ['mylibrary_annotations-update.md', 'Mylibrary', 'Annotations Update'] +- ['mylibrary_bookshelves-add-volume.md', 'Mylibrary', 'Bookshelves Add Volume'] +- ['mylibrary_bookshelves-clear-volumes.md', 'Mylibrary', 'Bookshelves Clear Volumes'] +- ['mylibrary_bookshelves-get.md', 'Mylibrary', 'Bookshelves Get'] +- ['mylibrary_bookshelves-list.md', 'Mylibrary', 'Bookshelves List'] +- ['mylibrary_bookshelves-move-volume.md', 'Mylibrary', 'Bookshelves Move Volume'] +- ['mylibrary_bookshelves-remove-volume.md', 'Mylibrary', 'Bookshelves Remove Volume'] +- ['mylibrary_bookshelves-volumes-list.md', 'Mylibrary', 'Bookshelves Volumes List'] +- ['mylibrary_readingpositions-get.md', 'Mylibrary', 'Readingpositions Get'] +- ['mylibrary_readingpositions-set-position.md', 'Mylibrary', 'Readingpositions Set Position'] +- ['onboarding_list-categories.md', 'Onboarding', 'List Categories'] +- ['onboarding_list-category-volumes.md', 'Onboarding', 'List Category Volumes'] +- ['promooffer_accept.md', 'Promooffer', 'Accept'] +- ['promooffer_dismiss.md', 'Promooffer', 'Dismiss'] +- ['promooffer_get.md', 'Promooffer', 'Get'] +- ['volumes_associated-list.md', 'Volumes', 'Associated List'] +- ['volumes_get.md', 'Volumes', 'Get'] +- ['volumes_list.md', 'Volumes', 'List'] +- ['volumes_mybooks-list.md', 'Volumes', 'Mybooks List'] +- ['volumes_recommended-list.md', 'Volumes', 'Recommended List'] +- ['volumes_recommended-rate.md', 'Volumes', 'Recommended Rate'] +- ['volumes_useruploaded-list.md', 'Volumes', 'Useruploaded List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/books1-cli/src/cmn.rs b/gen/books1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/books1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/books1-cli/src/main.rs b/gen/books1-cli/src/main.rs new file mode 100644 index 00000000000..d93a9c594b1 --- /dev/null +++ b/gen/books1-cli/src/main.rs @@ -0,0 +1,3186 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_books1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + books1 [options] bookshelves get [-p ]... [-o ] + books1 [options] bookshelves list [-p ]... [-o ] + books1 [options] bookshelves volumes-list [-p ]... [-o ] + books1 [options] cloudloading add-book [-p ]... [-o ] + books1 [options] cloudloading delete-book [-p ]... + books1 [options] cloudloading update-book -r ... [-p ]... [-o ] + books1 [options] dictionary list-offline-metadata [-p ]... [-o ] + books1 [options] layers annotation-data-get [-p ]... [-o ] + books1 [options] layers annotation-data-list [-p ]... [-o ] + books1 [options] layers get [-p ]... [-o ] + books1 [options] layers list [-p ]... [-o ] + books1 [options] layers volume-annotations-get [-p ]... [-o ] + books1 [options] layers volume-annotations-list [-p ]... [-o ] + books1 [options] myconfig get-user-settings [-p ]... [-o ] + books1 [options] myconfig release-download-access [-p ]... [-o ] + books1 [options] myconfig request-access [-p ]... [-o ] + books1 [options] myconfig sync-volume-licenses [-p ]... [-o ] + books1 [options] myconfig update-user-settings -r ... [-p ]... [-o ] + books1 [options] mylibrary annotations-delete [-p ]... + books1 [options] mylibrary annotations-insert -r ... [-p ]... [-o ] + books1 [options] mylibrary annotations-list [-p ]... [-o ] + books1 [options] mylibrary annotations-summary [-p ]... [-o ] + books1 [options] mylibrary annotations-update -r ... [-p ]... [-o ] + books1 [options] mylibrary bookshelves-add-volume [-p ]... + books1 [options] mylibrary bookshelves-clear-volumes [-p ]... + books1 [options] mylibrary bookshelves-get [-p ]... [-o ] + books1 [options] mylibrary bookshelves-list [-p ]... [-o ] + books1 [options] mylibrary bookshelves-move-volume [-p ]... + books1 [options] mylibrary bookshelves-remove-volume [-p ]... + books1 [options] mylibrary bookshelves-volumes-list [-p ]... [-o ] + books1 [options] mylibrary readingpositions-get [-p ]... [-o ] + books1 [options] mylibrary readingpositions-set-position [-p ]... + books1 [options] onboarding list-categories [-p ]... [-o ] + books1 [options] onboarding list-category-volumes [-p ]... [-o ] + books1 [options] promooffer accept [-p ]... + books1 [options] promooffer dismiss [-p ]... + books1 [options] promooffer get [-p ]... [-o ] + books1 [options] volumes associated-list [-p ]... [-o ] + books1 [options] volumes get [-p ]... [-o ] + books1 [options] volumes list [-p ]... [-o ] + books1 [options] volumes mybooks-list [-p ]... [-o ] + books1 [options] volumes recommended-list [-p ]... [-o ] + books1 [options] volumes recommended-rate [-p ]... [-o ] + books1 [options] volumes useruploaded-list [-p ]... [-o ] + books1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Books>, +} + + +impl Engine { + fn _bookshelves_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.bookshelves().get(&self.opt.arg_user_id, &self.opt.arg_shelf); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bookshelves_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.bookshelves().list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bookshelves_volumes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.bookshelves().volumes_list(&self.opt.arg_user_id, &self.opt.arg_shelf); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-preorders" => { + call = call.show_preorders(arg_from_str(value.unwrap_or("false"), err, "show-preorders", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _cloudloading_add_book(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.cloudloading().add_book(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "upload-client-token" => { + call = call.upload_client_token(value.unwrap_or("")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "mime-type" => { + call = call.mime_type(value.unwrap_or("")); + }, + "drive-document-id" => { + call = call.drive_document_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _cloudloading_delete_book(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.cloudloading().delete_book(&self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _cloudloading_update_book(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::BooksCloudloadingResource = Default::default(); + let mut call = self.hub.cloudloading().update_book(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "processing-state" => { + request.processing_state = Some(value.unwrap_or("").to_string()); + }, + "volume-id" => { + request.volume_id = Some(value.unwrap_or("").to_string()); + }, + "author" => { + request.author = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _dictionary_list_offline_metadata(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.dictionary().list_offline_metadata(&self.opt.arg_cpksver); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_annotation_data_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().annotation_data_get(&self.opt.arg_volume_id, &self.opt.arg_layer_id, &self.opt.arg_annotation_data_id, &self.opt.arg_content_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "w" => { + call = call.w(arg_from_str(value.unwrap_or("-0"), err, "w", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "scale" => { + call = call.scale(arg_from_str(value.unwrap_or("-0"), err, "scale", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "h" => { + call = call.h(arg_from_str(value.unwrap_or("-0"), err, "h", "integer")); + }, + "allow-web-definitions" => { + call = call.allow_web_definitions(arg_from_str(value.unwrap_or("false"), err, "allow-web-definitions", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_annotation_data_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().annotation_data_list(&self.opt.arg_volume_id, &self.opt.arg_layer_id, &self.opt.arg_content_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "w" => { + call = call.w(arg_from_str(value.unwrap_or("-0"), err, "w", "integer")); + }, + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "updated-max" => { + call = call.updated_max(value.unwrap_or("")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "scale" => { + call = call.scale(arg_from_str(value.unwrap_or("-0"), err, "scale", "integer")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "h" => { + call = call.h(arg_from_str(value.unwrap_or("-0"), err, "h", "integer")); + }, + "annotation-data-id" => { + call = call.add_annotation_data_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().get(&self.opt.arg_volume_id, &self.opt.arg_summary_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "content-version" => { + call = call.content_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().list(&self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "content-version" => { + call = call.content_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_volume_annotations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().volume_annotations_get(&self.opt.arg_volume_id, &self.opt.arg_layer_id, &self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_volume_annotations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.layers().volume_annotations_list(&self.opt.arg_volume_id, &self.opt.arg_layer_id, &self.opt.arg_content_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "volume-annotations-version" => { + call = call.volume_annotations_version(value.unwrap_or("")); + }, + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "updated-max" => { + call = call.updated_max(value.unwrap_or("")); + }, + "start-position" => { + call = call.start_position(value.unwrap_or("")); + }, + "start-offset" => { + call = call.start_offset(value.unwrap_or("")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "end-position" => { + call = call.end_position(value.unwrap_or("")); + }, + "end-offset" => { + call = call.end_offset(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _myconfig_get_user_settings(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.myconfig().get_user_settings(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _myconfig_release_download_access(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.myconfig().release_download_access(&self.opt.arg_volume_ids, &self.opt.arg_cpksver); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _myconfig_request_access(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.myconfig().request_access(&self.opt.arg_source, &self.opt.arg_volume_id, &self.opt.arg_nonce, &self.opt.arg_cpksver); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "license-types" => { + call = call.license_types(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _myconfig_sync_volume_licenses(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.myconfig().sync_volume_licenses(&self.opt.arg_source, &self.opt.arg_nonce, &self.opt.arg_cpksver); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "volume-ids" => { + call = call.add_volume_ids(value.unwrap_or("")); + }, + "show-preorders" => { + call = call.show_preorders(arg_from_str(value.unwrap_or("false"), err, "show-preorders", "boolean")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "features" => { + call = call.add_features(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _myconfig_update_user_settings(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Usersettings = Default::default(); + let mut call = self.hub.myconfig().update_user_settings(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_notes_export_init(request: &mut api::Usersettings) { + if request.notes_export.is_none() { + request.notes_export = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notes-export.is-enabled" => { + request_notes_export_init(&mut request); + request.notes_export.as_mut().unwrap().is_enabled = arg_from_str(value.unwrap_or("false"), err, "notes-export.is-enabled", "boolean"); + }, + "notes-export.folder-name" => { + request_notes_export_init(&mut request); + request.notes_export.as_mut().unwrap().folder_name = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_annotations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().annotations_delete(&self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mylibrary_annotations_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Annotation = Default::default(); + let mut call = self.hub.mylibrary().annotations_insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-only-summary-in-response" => { + call = call.show_only_summary_in_response(arg_from_str(value.unwrap_or("false"), err, "show-only-summary-in-response", "boolean")); + }, + "country" => { + call = call.country(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_client_version_ranges_init(request: &mut api::Annotation) { + if request.client_version_ranges.is_none() { + request.client_version_ranges = Some(Default::default()); + } + } + + fn request_current_version_ranges_init(request: &mut api::Annotation) { + if request.current_version_ranges.is_none() { + request.current_version_ranges = Some(Default::default()); + } + } + + fn request_layer_summary_init(request: &mut api::Annotation) { + if request.layer_summary.is_none() { + request.layer_summary = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "page-ids" => { + if request.page_ids.is_none() { + request.page_ids = Some(Default::default()); + } + request.page_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "before-selected-text" => { + request.before_selected_text = Some(value.unwrap_or("").to_string()); + }, + "current-version-ranges.image-cfi-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.content-version" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().content_version = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.end_offset = value.unwrap_or("").to_string(); + }, + "after-selected-text" => { + request_current_version_ranges_init(&mut request); + request.after_selected_text = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_current_version_ranges_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "volume-id" => { + request_current_version_ranges_init(&mut request); + request.volume_id = Some(value.unwrap_or("").to_string()); + }, + "layer-summary.limit-type" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().limit_type = value.unwrap_or("").to_string(); + }, + "layer-summary.remaining-character-count" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().remaining_character_count = arg_from_str(value.unwrap_or("-0"), err, "layer-summary.remaining-character-count", "integer"); + }, + "layer-summary.allowed-character-count" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().allowed_character_count = arg_from_str(value.unwrap_or("-0"), err, "layer-summary.allowed-character-count", "integer"); + }, + "selected-text" => { + request_layer_summary_init(&mut request); + request.selected_text = Some(value.unwrap_or("").to_string()); + }, + "client-version-ranges.image-cfi-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.content-version" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().content_version = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.end_offset = value.unwrap_or("").to_string(); + }, + "layer-id" => { + request_client_version_ranges_init(&mut request); + request.layer_id = Some(value.unwrap_or("").to_string()); + }, + "highlight-style" => { + request_client_version_ranges_init(&mut request); + request.highlight_style = Some(value.unwrap_or("").to_string()); + }, + "data" => { + request_client_version_ranges_init(&mut request); + request.data = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_client_version_ranges_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_client_version_ranges_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_annotations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().annotations_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "volume-id" => { + call = call.volume_id(value.unwrap_or("")); + }, + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "updated-max" => { + call = call.updated_max(value.unwrap_or("")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "layer-ids" => { + call = call.add_layer_ids(value.unwrap_or("")); + }, + "layer-id" => { + call = call.layer_id(value.unwrap_or("")); + }, + "content-version" => { + call = call.content_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_annotations_summary(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().annotations_summary(&self.opt.arg_layer_ids, &self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_annotations_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Annotation = Default::default(); + let mut call = self.hub.mylibrary().annotations_update(&request, &self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_client_version_ranges_init(request: &mut api::Annotation) { + if request.client_version_ranges.is_none() { + request.client_version_ranges = Some(Default::default()); + } + } + + fn request_current_version_ranges_init(request: &mut api::Annotation) { + if request.current_version_ranges.is_none() { + request.current_version_ranges = Some(Default::default()); + } + } + + fn request_layer_summary_init(request: &mut api::Annotation) { + if request.layer_summary.is_none() { + request.layer_summary = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "page-ids" => { + if request.page_ids.is_none() { + request.page_ids = Some(Default::default()); + } + request.page_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "before-selected-text" => { + request.before_selected_text = Some(value.unwrap_or("").to_string()); + }, + "current-version-ranges.image-cfi-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.image-cfi-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().image_cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-text-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_text_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.content-version" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().content_version = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.cfi-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.start-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.start_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.end-position" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.end_position = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.start-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.start_offset = value.unwrap_or("").to_string(); + }, + "current-version-ranges.gb-image-range.end-offset" => { + request_current_version_ranges_init(&mut request); + request.current_version_ranges.as_mut().unwrap().gb_image_range.end_offset = value.unwrap_or("").to_string(); + }, + "after-selected-text" => { + request_current_version_ranges_init(&mut request); + request.after_selected_text = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_current_version_ranges_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "volume-id" => { + request_current_version_ranges_init(&mut request); + request.volume_id = Some(value.unwrap_or("").to_string()); + }, + "layer-summary.limit-type" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().limit_type = value.unwrap_or("").to_string(); + }, + "layer-summary.remaining-character-count" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().remaining_character_count = arg_from_str(value.unwrap_or("-0"), err, "layer-summary.remaining-character-count", "integer"); + }, + "layer-summary.allowed-character-count" => { + request_layer_summary_init(&mut request); + request.layer_summary.as_mut().unwrap().allowed_character_count = arg_from_str(value.unwrap_or("-0"), err, "layer-summary.allowed-character-count", "integer"); + }, + "selected-text" => { + request_layer_summary_init(&mut request); + request.selected_text = Some(value.unwrap_or("").to_string()); + }, + "client-version-ranges.image-cfi-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.image-cfi-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().image_cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-text-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_text_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.content-version" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().content_version = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.cfi-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().cfi_range.end_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.start-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.start_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.end-position" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.end_position = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.start-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.start_offset = value.unwrap_or("").to_string(); + }, + "client-version-ranges.gb-image-range.end-offset" => { + request_client_version_ranges_init(&mut request); + request.client_version_ranges.as_mut().unwrap().gb_image_range.end_offset = value.unwrap_or("").to_string(); + }, + "layer-id" => { + request_client_version_ranges_init(&mut request); + request.layer_id = Some(value.unwrap_or("").to_string()); + }, + "highlight-style" => { + request_client_version_ranges_init(&mut request); + request.highlight_style = Some(value.unwrap_or("").to_string()); + }, + "data" => { + request_client_version_ranges_init(&mut request); + request.data = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_client_version_ranges_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_client_version_ranges_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_bookshelves_add_volume(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_add_volume(&self.opt.arg_shelf, &self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "reason" => { + call = call.reason(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mylibrary_bookshelves_clear_volumes(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_clear_volumes(&self.opt.arg_shelf); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mylibrary_bookshelves_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_get(&self.opt.arg_shelf); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_bookshelves_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_bookshelves_move_volume(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let volume_position: i32 = arg_from_str(&self.opt.arg_volume_position, err, "", "integer"); + let mut call = self.hub.mylibrary().bookshelves_move_volume(&self.opt.arg_shelf, &self.opt.arg_volume_id, volume_position); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mylibrary_bookshelves_remove_volume(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_remove_volume(&self.opt.arg_shelf, &self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "reason" => { + call = call.reason(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _mylibrary_bookshelves_volumes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().bookshelves_volumes_list(&self.opt.arg_shelf); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-preorders" => { + call = call.show_preorders(arg_from_str(value.unwrap_or("false"), err, "show-preorders", "boolean")); + }, + "q" => { + call = call.q(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "country" => { + call = call.country(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_readingpositions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().readingpositions_get(&self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "content-version" => { + call = call.content_version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mylibrary_readingpositions_set_position(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.mylibrary().readingpositions_set_position(&self.opt.arg_volume_id, &self.opt.arg_timestamp, &self.opt.arg_position); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "device-cookie" => { + call = call.device_cookie(value.unwrap_or("")); + }, + "content-version" => { + call = call.content_version(value.unwrap_or("")); + }, + "action" => { + call = call.action(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _onboarding_list_categories(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.onboarding().list_categories(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _onboarding_list_category_volumes(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.onboarding().list_category_volumes(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "category-id" => { + call = call.add_category_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _promooffer_accept(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.promooffer().accept(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "volume-id" => { + call = call.volume_id(value.unwrap_or("")); + }, + "serial" => { + call = call.serial(value.unwrap_or("")); + }, + "product" => { + call = call.product(value.unwrap_or("")); + }, + "offer-id" => { + call = call.offer_id(value.unwrap_or("")); + }, + "model" => { + call = call.model(value.unwrap_or("")); + }, + "manufacturer" => { + call = call.manufacturer(value.unwrap_or("")); + }, + "device" => { + call = call.device(value.unwrap_or("")); + }, + "android-id" => { + call = call.android_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _promooffer_dismiss(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.promooffer().dismiss(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "serial" => { + call = call.serial(value.unwrap_or("")); + }, + "product" => { + call = call.product(value.unwrap_or("")); + }, + "offer-id" => { + call = call.offer_id(value.unwrap_or("")); + }, + "model" => { + call = call.model(value.unwrap_or("")); + }, + "manufacturer" => { + call = call.manufacturer(value.unwrap_or("")); + }, + "device" => { + call = call.device(value.unwrap_or("")); + }, + "android-id" => { + call = call.android_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _promooffer_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.promooffer().get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "serial" => { + call = call.serial(value.unwrap_or("")); + }, + "product" => { + call = call.product(value.unwrap_or("")); + }, + "model" => { + call = call.model(value.unwrap_or("")); + }, + "manufacturer" => { + call = call.manufacturer(value.unwrap_or("")); + }, + "device" => { + call = call.device(value.unwrap_or("")); + }, + "android-id" => { + call = call.android_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_associated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().associated_list(&self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "association" => { + call = call.association(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().get(&self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-library-consistent-read" => { + call = call.user_library_consistent_read(arg_from_str(value.unwrap_or("false"), err, "user-library-consistent-read", "boolean")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "partner" => { + call = call.partner(value.unwrap_or("")); + }, + "country" => { + call = call.country(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().list(&self.opt.arg_q); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "show-preorders" => { + call = call.show_preorders(arg_from_str(value.unwrap_or("false"), err, "show-preorders", "boolean")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "print-type" => { + call = call.print_type(value.unwrap_or("")); + }, + "partner" => { + call = call.partner(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "library-restrict" => { + call = call.library_restrict(value.unwrap_or("")); + }, + "lang-restrict" => { + call = call.lang_restrict(value.unwrap_or("")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "download" => { + call = call.download(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_mybooks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().mybooks_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "processing-state" => { + call = call.add_processing_state(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "acquire-method" => { + call = call.add_acquire_method(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_recommended_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().recommended_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_recommended_rate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().recommended_rate(&self.opt.arg_rating, &self.opt.arg_volume_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _volumes_useruploaded_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.volumes().useruploaded_list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "volume-id" => { + call = call.add_volume_id(value.unwrap_or("")); + }, + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "source" => { + call = call.source(value.unwrap_or("")); + }, + "processing-state" => { + call = call.add_processing_state(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_bookshelves { + if self.opt.cmd_get { + call_result = self._bookshelves_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._bookshelves_list(dry_run, &mut err); + } else if self.opt.cmd_volumes_list { + call_result = self._bookshelves_volumes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_cloudloading { + if self.opt.cmd_add_book { + call_result = self._cloudloading_add_book(dry_run, &mut err); + } else if self.opt.cmd_delete_book { + call_result = self._cloudloading_delete_book(dry_run, &mut err); + } else if self.opt.cmd_update_book { + call_result = self._cloudloading_update_book(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_dictionary { + if self.opt.cmd_list_offline_metadata { + call_result = self._dictionary_list_offline_metadata(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_layers { + if self.opt.cmd_annotation_data_get { + call_result = self._layers_annotation_data_get(dry_run, &mut err); + } else if self.opt.cmd_annotation_data_list { + call_result = self._layers_annotation_data_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._layers_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._layers_list(dry_run, &mut err); + } else if self.opt.cmd_volume_annotations_get { + call_result = self._layers_volume_annotations_get(dry_run, &mut err); + } else if self.opt.cmd_volume_annotations_list { + call_result = self._layers_volume_annotations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_myconfig { + if self.opt.cmd_get_user_settings { + call_result = self._myconfig_get_user_settings(dry_run, &mut err); + } else if self.opt.cmd_release_download_access { + call_result = self._myconfig_release_download_access(dry_run, &mut err); + } else if self.opt.cmd_request_access { + call_result = self._myconfig_request_access(dry_run, &mut err); + } else if self.opt.cmd_sync_volume_licenses { + call_result = self._myconfig_sync_volume_licenses(dry_run, &mut err); + } else if self.opt.cmd_update_user_settings { + call_result = self._myconfig_update_user_settings(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_mylibrary { + if self.opt.cmd_annotations_delete { + call_result = self._mylibrary_annotations_delete(dry_run, &mut err); + } else if self.opt.cmd_annotations_insert { + call_result = self._mylibrary_annotations_insert(dry_run, &mut err); + } else if self.opt.cmd_annotations_list { + call_result = self._mylibrary_annotations_list(dry_run, &mut err); + } else if self.opt.cmd_annotations_summary { + call_result = self._mylibrary_annotations_summary(dry_run, &mut err); + } else if self.opt.cmd_annotations_update { + call_result = self._mylibrary_annotations_update(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_add_volume { + call_result = self._mylibrary_bookshelves_add_volume(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_clear_volumes { + call_result = self._mylibrary_bookshelves_clear_volumes(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_get { + call_result = self._mylibrary_bookshelves_get(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_list { + call_result = self._mylibrary_bookshelves_list(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_move_volume { + call_result = self._mylibrary_bookshelves_move_volume(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_remove_volume { + call_result = self._mylibrary_bookshelves_remove_volume(dry_run, &mut err); + } else if self.opt.cmd_bookshelves_volumes_list { + call_result = self._mylibrary_bookshelves_volumes_list(dry_run, &mut err); + } else if self.opt.cmd_readingpositions_get { + call_result = self._mylibrary_readingpositions_get(dry_run, &mut err); + } else if self.opt.cmd_readingpositions_set_position { + call_result = self._mylibrary_readingpositions_set_position(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_onboarding { + if self.opt.cmd_list_categories { + call_result = self._onboarding_list_categories(dry_run, &mut err); + } else if self.opt.cmd_list_category_volumes { + call_result = self._onboarding_list_category_volumes(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_promooffer { + if self.opt.cmd_accept { + call_result = self._promooffer_accept(dry_run, &mut err); + } else if self.opt.cmd_dismiss { + call_result = self._promooffer_dismiss(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._promooffer_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_volumes { + if self.opt.cmd_associated_list { + call_result = self._volumes_associated_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._volumes_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._volumes_list(dry_run, &mut err); + } else if self.opt.cmd_mybooks_list { + call_result = self._volumes_mybooks_list(dry_run, &mut err); + } else if self.opt.cmd_recommended_list { + call_result = self._volumes_recommended_list(dry_run, &mut err); + } else if self.opt.cmd_recommended_rate { + call_result = self._volumes_recommended_rate(dry_run, &mut err); + } else if self.opt.cmd_useruploaded_list { + call_result = self._volumes_useruploaded_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "books1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "books1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Books::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/calendar3-cli/Cargo.toml b/gen/calendar3-cli/Cargo.toml new file mode 100644 index 00000000000..05c5ddb14f5 --- /dev/null +++ b/gen/calendar3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-calendar3-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with calendar (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/calendar3-cli" +homepage = "https://developers.google.com/google-apps/calendar/firstapp" +documentation = "http://byron.github.io/google-apis-rs/google_calendar3_cli" +license = "MIT" +keywords = ["calendar", "google", "cli"] + +[[bin]] +name = "calendar3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-calendar3] +path = "../calendar3" diff --git a/gen/calendar3-cli/LICENSE.md b/gen/calendar3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/calendar3-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/calendar3-cli/README.md b/gen/calendar3-cli/README.md new file mode 100644 index 00000000000..e7983d9c71e --- /dev/null +++ b/gen/calendar3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CALENDAR:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/calendar3-cli/mkdocs.yml b/gen/calendar3-cli/mkdocs.yml new file mode 100644 index 00000000000..5697e6a870a --- /dev/null +++ b/gen/calendar3-cli/mkdocs.yml @@ -0,0 +1,53 @@ +site_name: calendar v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-calendar3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/calendar3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['acl_delete.md', 'Acl', 'Delete'] +- ['acl_get.md', 'Acl', 'Get'] +- ['acl_insert.md', 'Acl', 'Insert'] +- ['acl_list.md', 'Acl', 'List'] +- ['acl_patch.md', 'Acl', 'Patch'] +- ['acl_update.md', 'Acl', 'Update'] +- ['acl_watch.md', 'Acl', 'Watch'] +- ['calendar-list_delete.md', 'Calendar List', 'Delete'] +- ['calendar-list_get.md', 'Calendar List', 'Get'] +- ['calendar-list_insert.md', 'Calendar List', 'Insert'] +- ['calendar-list_list.md', 'Calendar List', 'List'] +- ['calendar-list_patch.md', 'Calendar List', 'Patch'] +- ['calendar-list_update.md', 'Calendar List', 'Update'] +- ['calendar-list_watch.md', 'Calendar List', 'Watch'] +- ['calendars_clear.md', 'Calendars', 'Clear'] +- ['calendars_delete.md', 'Calendars', 'Delete'] +- ['calendars_get.md', 'Calendars', 'Get'] +- ['calendars_insert.md', 'Calendars', 'Insert'] +- ['calendars_patch.md', 'Calendars', 'Patch'] +- ['calendars_update.md', 'Calendars', 'Update'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['colors_get.md', 'Colors', 'Get'] +- ['events_delete.md', 'Events', 'Delete'] +- ['events_get.md', 'Events', 'Get'] +- ['events_import.md', 'Events', 'Import'] +- ['events_insert.md', 'Events', 'Insert'] +- ['events_instances.md', 'Events', 'Instances'] +- ['events_list.md', 'Events', 'List'] +- ['events_move.md', 'Events', 'Move'] +- ['events_patch.md', 'Events', 'Patch'] +- ['events_quick-add.md', 'Events', 'Quick Add'] +- ['events_update.md', 'Events', 'Update'] +- ['events_watch.md', 'Events', 'Watch'] +- ['freebusy_query.md', 'Freebusy', 'Query'] +- ['settings_get.md', 'Settings', 'Get'] +- ['settings_list.md', 'Settings', 'List'] +- ['settings_watch.md', 'Settings', 'Watch'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/calendar3-cli/src/cmn.rs b/gen/calendar3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/calendar3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/calendar3-cli/src/main.rs b/gen/calendar3-cli/src/main.rs new file mode 100644 index 00000000000..9c795f6f67d --- /dev/null +++ b/gen/calendar3-cli/src/main.rs @@ -0,0 +1,3987 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_calendar3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + calendar3 [options] acl delete [-p ]... + calendar3 [options] acl get [-p ]... [-o ] + calendar3 [options] acl insert -r ... [-p ]... [-o ] + calendar3 [options] acl list [-p ]... [-o ] + calendar3 [options] acl patch -r ... [-p ]... [-o ] + calendar3 [options] acl update -r ... [-p ]... [-o ] + calendar3 [options] acl watch -r ... [-p ]... [-o ] + calendar3 [options] calendar-list delete [-p ]... + calendar3 [options] calendar-list get [-p ]... [-o ] + calendar3 [options] calendar-list insert -r ... [-p ]... [-o ] + calendar3 [options] calendar-list list [-p ]... [-o ] + calendar3 [options] calendar-list patch -r ... [-p ]... [-o ] + calendar3 [options] calendar-list update -r ... [-p ]... [-o ] + calendar3 [options] calendar-list watch -r ... [-p ]... [-o ] + calendar3 [options] calendars clear [-p ]... + calendar3 [options] calendars delete [-p ]... + calendar3 [options] calendars get [-p ]... [-o ] + calendar3 [options] calendars insert -r ... [-p ]... [-o ] + calendar3 [options] calendars patch -r ... [-p ]... [-o ] + calendar3 [options] calendars update -r ... [-p ]... [-o ] + calendar3 [options] channels stop -r ... [-p ]... + calendar3 [options] colors get [-p ]... [-o ] + calendar3 [options] events delete [-p ]... + calendar3 [options] events get [-p ]... [-o ] + calendar3 [options] events import -r ... [-p ]... [-o ] + calendar3 [options] events insert -r ... [-p ]... [-o ] + calendar3 [options] events instances [-p ]... [-o ] + calendar3 [options] events list [-p ]... [-o ] + calendar3 [options] events move [-p ]... [-o ] + calendar3 [options] events patch -r ... [-p ]... [-o ] + calendar3 [options] events quick-add [-p ]... [-o ] + calendar3 [options] events update -r ... [-p ]... [-o ] + calendar3 [options] events watch -r ... [-p ]... [-o ] + calendar3 [options] freebusy query -r ... [-p ]... [-o ] + calendar3 [options] settings get [-p ]... [-o ] + calendar3 [options] settings list [-p ]... [-o ] + calendar3 [options] settings watch -r ... [-p ]... [-o ] + calendar3 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::CalendarHub>, +} + + +impl Engine { + fn _acl_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.acl().delete(&self.opt.arg_calendar_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _acl_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.acl().get(&self.opt.arg_calendar_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _acl_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AclRule = Default::default(); + let mut call = self.hub.acl().insert(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_scope_init(request: &mut api::AclRule) { + if request.scope.is_none() { + request.scope = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "scope.type" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "scope.value" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "kind" => { + request_scope_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_scope_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request_scope_init(&mut request); + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_scope_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _acl_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.acl().list(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _acl_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AclRule = Default::default(); + let mut call = self.hub.acl().patch(&request, &self.opt.arg_calendar_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_scope_init(request: &mut api::AclRule) { + if request.scope.is_none() { + request.scope = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "scope.type" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "scope.value" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "kind" => { + request_scope_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_scope_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request_scope_init(&mut request); + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_scope_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _acl_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AclRule = Default::default(); + let mut call = self.hub.acl().update(&request, &self.opt.arg_calendar_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_scope_init(request: &mut api::AclRule) { + if request.scope.is_none() { + request.scope = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "scope.type" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "scope.value" => { + request_scope_init(&mut request); + request.scope.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "kind" => { + request_scope_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_scope_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request_scope_init(&mut request); + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_scope_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _acl_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.acl().watch(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendar_list().delete(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _calendar_list_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendar_list().get(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CalendarListEntry = Default::default(); + let mut call = self.hub.calendar_list().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "color-rgb-format" => { + call = call.color_rgb_format(arg_from_str(value.unwrap_or("false"), err, "color-rgb-format", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "foreground-color" => { + request.foreground_color = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "color-id" => { + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "selected" => { + request.selected = Some(arg_from_str(value.unwrap_or("false"), err, "selected", "boolean")); + }, + "primary" => { + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "background-color" => { + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "summary-override" => { + request.summary_override = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "access-role" => { + request.access_role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendar_list().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "show-hidden" => { + call = call.show_hidden(arg_from_str(value.unwrap_or("false"), err, "show-hidden", "boolean")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-access-role" => { + call = call.min_access_role(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CalendarListEntry = Default::default(); + let mut call = self.hub.calendar_list().patch(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "color-rgb-format" => { + call = call.color_rgb_format(arg_from_str(value.unwrap_or("false"), err, "color-rgb-format", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "foreground-color" => { + request.foreground_color = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "color-id" => { + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "selected" => { + request.selected = Some(arg_from_str(value.unwrap_or("false"), err, "selected", "boolean")); + }, + "primary" => { + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "background-color" => { + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "summary-override" => { + request.summary_override = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "access-role" => { + request.access_role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CalendarListEntry = Default::default(); + let mut call = self.hub.calendar_list().update(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "color-rgb-format" => { + call = call.color_rgb_format(arg_from_str(value.unwrap_or("false"), err, "color-rgb-format", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "foreground-color" => { + request.foreground_color = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "color-id" => { + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "selected" => { + request.selected = Some(arg_from_str(value.unwrap_or("false"), err, "selected", "boolean")); + }, + "primary" => { + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "background-color" => { + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "summary-override" => { + request.summary_override = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "access-role" => { + request.access_role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendar_list_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.calendar_list().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "show-hidden" => { + call = call.show_hidden(arg_from_str(value.unwrap_or("false"), err, "show-hidden", "boolean")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-access-role" => { + call = call.min_access_role(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendars_clear(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendars().clear(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _calendars_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendars().delete(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _calendars_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.calendars().get(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendars_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Calendar = Default::default(); + let mut call = self.hub.calendars().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendars_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Calendar = Default::default(); + let mut call = self.hub.calendars().patch(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _calendars_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Calendar = Default::default(); + let mut call = self.hub.calendars().update(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "summary" => { + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request.location = Some(value.unwrap_or("").to_string()); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _colors_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.colors().get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().delete(&self.opt.arg_calendar_id, &self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().get(&self.opt.arg_calendar_id, &self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "time-zone" => { + call = call.time_zone(value.unwrap_or("")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_import(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Event = Default::default(); + let mut call = self.hub.events().import(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::Event) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_end_init(request: &mut api::Event) { + if request.end.is_none() { + request.end = Some(Default::default()); + } + } + + fn request_extended_properties_init(request: &mut api::Event) { + if request.extended_properties.is_none() { + request.extended_properties = Some(Default::default()); + } + } + + fn request_gadget_init(request: &mut api::Event) { + if request.gadget.is_none() { + request.gadget = Some(Default::default()); + } + } + + fn request_organizer_init(request: &mut api::Event) { + if request.organizer.is_none() { + request.organizer = Some(Default::default()); + } + } + + fn request_original_start_time_init(request: &mut api::Event) { + if request.original_start_time.is_none() { + request.original_start_time = Some(Default::default()); + } + } + + fn request_reminders_init(request: &mut api::Event) { + if request.reminders.is_none() { + request.reminders = Some(Default::default()); + } + } + + fn request_source_init(request: &mut api::Event) { + if request.source.is_none() { + request.source = Some(Default::default()); + } + } + + fn request_start_init(request: &mut api::Event) { + if request.start.is_none() { + request.start = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "extended-properties.shared" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().shared.push(value.unwrap_or("").to_string()); + }, + "extended-properties.private" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().private.push(value.unwrap_or("").to_string()); + }, + "creator.self" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "creator.self", "boolean"); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "creator.email" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "organizer.self" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "organizer.self", "boolean"); + }, + "organizer.display-name" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "organizer.email" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "organizer.id" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_organizer_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "hangout-link" => { + request_organizer_init(&mut request); + request.hangout_link = Some(value.unwrap_or("").to_string()); + }, + "end.date" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "end.time-zone" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "end.date-time" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "source.url" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "source.title" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "html-link" => { + request_source_init(&mut request); + request.html_link = Some(value.unwrap_or("").to_string()); + }, + "recurrence" => { + request_source_init(&mut request); + if request.recurrence.is_none() { + request.recurrence = Some(Default::default()); + } + request.recurrence.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start.date" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "start.time-zone" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "start.date-time" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "etag" => { + request_start_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_start_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "recurring-event-id" => { + request_start_init(&mut request); + request.recurring_event_id = Some(value.unwrap_or("").to_string()); + }, + "original-start-time.date" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "original-start-time.time-zone" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "original-start-time.date-time" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "status" => { + request_original_start_time_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_original_start_time_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_original_start_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "i-cal-uid" => { + request_original_start_time_init(&mut request); + request.i_cal_uid = Some(value.unwrap_or("").to_string()); + }, + "gadget.preferences" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().preferences.push(value.unwrap_or("").to_string()); + }, + "gadget.title" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "gadget.height" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "gadget.height", "integer"); + }, + "gadget.width" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "gadget.width", "integer"); + }, + "gadget.link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().link = value.unwrap_or("").to_string(); + }, + "gadget.type" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "gadget.display" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().display = value.unwrap_or("").to_string(); + }, + "gadget.icon-link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().icon_link = value.unwrap_or("").to_string(); + }, + "end-time-unspecified" => { + request_gadget_init(&mut request); + request.end_time_unspecified = Some(arg_from_str(value.unwrap_or("false"), err, "end-time-unspecified", "boolean")); + }, + "sequence" => { + request_gadget_init(&mut request); + request.sequence = Some(arg_from_str(value.unwrap_or("-0"), err, "sequence", "integer")); + }, + "visibility" => { + request_gadget_init(&mut request); + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "guests-can-modify" => { + request_gadget_init(&mut request); + request.guests_can_modify = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-modify", "boolean")); + }, + "attendees-omitted" => { + request_gadget_init(&mut request); + request.attendees_omitted = Some(arg_from_str(value.unwrap_or("false"), err, "attendees-omitted", "boolean")); + }, + "kind" => { + request_gadget_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "locked" => { + request_gadget_init(&mut request); + request.locked = Some(arg_from_str(value.unwrap_or("false"), err, "locked", "boolean")); + }, + "created" => { + request_gadget_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "color-id" => { + request_gadget_init(&mut request); + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "anyone-can-add-self" => { + request_gadget_init(&mut request); + request.anyone_can_add_self = Some(arg_from_str(value.unwrap_or("false"), err, "anyone-can-add-self", "boolean")); + }, + "reminders.use-default" => { + request_reminders_init(&mut request); + request.reminders.as_mut().unwrap().use_default = arg_from_str(value.unwrap_or("false"), err, "reminders.use-default", "boolean"); + }, + "guests-can-see-other-guests" => { + request_reminders_init(&mut request); + request.guests_can_see_other_guests = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-see-other-guests", "boolean")); + }, + "summary" => { + request_reminders_init(&mut request); + request.summary = Some(value.unwrap_or("").to_string()); + }, + "guests-can-invite-others" => { + request_reminders_init(&mut request); + request.guests_can_invite_others = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-invite-others", "boolean")); + }, + "transparency" => { + request_reminders_init(&mut request); + request.transparency = Some(value.unwrap_or("").to_string()); + }, + "private-copy" => { + request_reminders_init(&mut request); + request.private_copy = Some(arg_from_str(value.unwrap_or("false"), err, "private-copy", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Event = Default::default(); + let mut call = self.hub.events().insert(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::Event) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_end_init(request: &mut api::Event) { + if request.end.is_none() { + request.end = Some(Default::default()); + } + } + + fn request_extended_properties_init(request: &mut api::Event) { + if request.extended_properties.is_none() { + request.extended_properties = Some(Default::default()); + } + } + + fn request_gadget_init(request: &mut api::Event) { + if request.gadget.is_none() { + request.gadget = Some(Default::default()); + } + } + + fn request_organizer_init(request: &mut api::Event) { + if request.organizer.is_none() { + request.organizer = Some(Default::default()); + } + } + + fn request_original_start_time_init(request: &mut api::Event) { + if request.original_start_time.is_none() { + request.original_start_time = Some(Default::default()); + } + } + + fn request_reminders_init(request: &mut api::Event) { + if request.reminders.is_none() { + request.reminders = Some(Default::default()); + } + } + + fn request_source_init(request: &mut api::Event) { + if request.source.is_none() { + request.source = Some(Default::default()); + } + } + + fn request_start_init(request: &mut api::Event) { + if request.start.is_none() { + request.start = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "extended-properties.shared" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().shared.push(value.unwrap_or("").to_string()); + }, + "extended-properties.private" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().private.push(value.unwrap_or("").to_string()); + }, + "creator.self" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "creator.self", "boolean"); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "creator.email" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "organizer.self" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "organizer.self", "boolean"); + }, + "organizer.display-name" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "organizer.email" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "organizer.id" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_organizer_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "hangout-link" => { + request_organizer_init(&mut request); + request.hangout_link = Some(value.unwrap_or("").to_string()); + }, + "end.date" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "end.time-zone" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "end.date-time" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "source.url" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "source.title" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "html-link" => { + request_source_init(&mut request); + request.html_link = Some(value.unwrap_or("").to_string()); + }, + "recurrence" => { + request_source_init(&mut request); + if request.recurrence.is_none() { + request.recurrence = Some(Default::default()); + } + request.recurrence.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start.date" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "start.time-zone" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "start.date-time" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "etag" => { + request_start_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_start_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "recurring-event-id" => { + request_start_init(&mut request); + request.recurring_event_id = Some(value.unwrap_or("").to_string()); + }, + "original-start-time.date" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "original-start-time.time-zone" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "original-start-time.date-time" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "status" => { + request_original_start_time_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_original_start_time_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_original_start_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "i-cal-uid" => { + request_original_start_time_init(&mut request); + request.i_cal_uid = Some(value.unwrap_or("").to_string()); + }, + "gadget.preferences" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().preferences.push(value.unwrap_or("").to_string()); + }, + "gadget.title" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "gadget.height" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "gadget.height", "integer"); + }, + "gadget.width" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "gadget.width", "integer"); + }, + "gadget.link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().link = value.unwrap_or("").to_string(); + }, + "gadget.type" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "gadget.display" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().display = value.unwrap_or("").to_string(); + }, + "gadget.icon-link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().icon_link = value.unwrap_or("").to_string(); + }, + "end-time-unspecified" => { + request_gadget_init(&mut request); + request.end_time_unspecified = Some(arg_from_str(value.unwrap_or("false"), err, "end-time-unspecified", "boolean")); + }, + "sequence" => { + request_gadget_init(&mut request); + request.sequence = Some(arg_from_str(value.unwrap_or("-0"), err, "sequence", "integer")); + }, + "visibility" => { + request_gadget_init(&mut request); + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "guests-can-modify" => { + request_gadget_init(&mut request); + request.guests_can_modify = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-modify", "boolean")); + }, + "attendees-omitted" => { + request_gadget_init(&mut request); + request.attendees_omitted = Some(arg_from_str(value.unwrap_or("false"), err, "attendees-omitted", "boolean")); + }, + "kind" => { + request_gadget_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "locked" => { + request_gadget_init(&mut request); + request.locked = Some(arg_from_str(value.unwrap_or("false"), err, "locked", "boolean")); + }, + "created" => { + request_gadget_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "color-id" => { + request_gadget_init(&mut request); + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "anyone-can-add-self" => { + request_gadget_init(&mut request); + request.anyone_can_add_self = Some(arg_from_str(value.unwrap_or("false"), err, "anyone-can-add-self", "boolean")); + }, + "reminders.use-default" => { + request_reminders_init(&mut request); + request.reminders.as_mut().unwrap().use_default = arg_from_str(value.unwrap_or("false"), err, "reminders.use-default", "boolean"); + }, + "guests-can-see-other-guests" => { + request_reminders_init(&mut request); + request.guests_can_see_other_guests = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-see-other-guests", "boolean")); + }, + "summary" => { + request_reminders_init(&mut request); + request.summary = Some(value.unwrap_or("").to_string()); + }, + "guests-can-invite-others" => { + request_reminders_init(&mut request); + request.guests_can_invite_others = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-invite-others", "boolean")); + }, + "transparency" => { + request_reminders_init(&mut request); + request.transparency = Some(value.unwrap_or("").to_string()); + }, + "private-copy" => { + request_reminders_init(&mut request); + request.private_copy = Some(arg_from_str(value.unwrap_or("false"), err, "private-copy", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_instances(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().instances(&self.opt.arg_calendar_id, &self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "time-zone" => { + call = call.time_zone(value.unwrap_or("")); + }, + "time-min" => { + call = call.time_min(value.unwrap_or("")); + }, + "time-max" => { + call = call.time_max(value.unwrap_or("")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "original-start" => { + call = call.original_start(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().list(&self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "time-zone" => { + call = call.time_zone(value.unwrap_or("")); + }, + "time-min" => { + call = call.time_min(value.unwrap_or("")); + }, + "time-max" => { + call = call.time_max(value.unwrap_or("")); + }, + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "single-events" => { + call = call.single_events(arg_from_str(value.unwrap_or("false"), err, "single-events", "boolean")); + }, + "show-hidden-invitations" => { + call = call.show_hidden_invitations(arg_from_str(value.unwrap_or("false"), err, "show-hidden-invitations", "boolean")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "shared-extended-property" => { + call = call.add_shared_extended_property(value.unwrap_or("")); + }, + "q" => { + call = call.q(value.unwrap_or("")); + }, + "private-extended-property" => { + call = call.add_private_extended_property(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "i-cal-uid" => { + call = call.i_cal_uid(value.unwrap_or("")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_move(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().move_(&self.opt.arg_calendar_id, &self.opt.arg_event_id, &self.opt.arg_destination); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Event = Default::default(); + let mut call = self.hub.events().patch(&request, &self.opt.arg_calendar_id, &self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::Event) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_end_init(request: &mut api::Event) { + if request.end.is_none() { + request.end = Some(Default::default()); + } + } + + fn request_extended_properties_init(request: &mut api::Event) { + if request.extended_properties.is_none() { + request.extended_properties = Some(Default::default()); + } + } + + fn request_gadget_init(request: &mut api::Event) { + if request.gadget.is_none() { + request.gadget = Some(Default::default()); + } + } + + fn request_organizer_init(request: &mut api::Event) { + if request.organizer.is_none() { + request.organizer = Some(Default::default()); + } + } + + fn request_original_start_time_init(request: &mut api::Event) { + if request.original_start_time.is_none() { + request.original_start_time = Some(Default::default()); + } + } + + fn request_reminders_init(request: &mut api::Event) { + if request.reminders.is_none() { + request.reminders = Some(Default::default()); + } + } + + fn request_source_init(request: &mut api::Event) { + if request.source.is_none() { + request.source = Some(Default::default()); + } + } + + fn request_start_init(request: &mut api::Event) { + if request.start.is_none() { + request.start = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "extended-properties.shared" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().shared.push(value.unwrap_or("").to_string()); + }, + "extended-properties.private" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().private.push(value.unwrap_or("").to_string()); + }, + "creator.self" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "creator.self", "boolean"); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "creator.email" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "organizer.self" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "organizer.self", "boolean"); + }, + "organizer.display-name" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "organizer.email" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "organizer.id" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_organizer_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "hangout-link" => { + request_organizer_init(&mut request); + request.hangout_link = Some(value.unwrap_or("").to_string()); + }, + "end.date" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "end.time-zone" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "end.date-time" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "source.url" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "source.title" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "html-link" => { + request_source_init(&mut request); + request.html_link = Some(value.unwrap_or("").to_string()); + }, + "recurrence" => { + request_source_init(&mut request); + if request.recurrence.is_none() { + request.recurrence = Some(Default::default()); + } + request.recurrence.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start.date" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "start.time-zone" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "start.date-time" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "etag" => { + request_start_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_start_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "recurring-event-id" => { + request_start_init(&mut request); + request.recurring_event_id = Some(value.unwrap_or("").to_string()); + }, + "original-start-time.date" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "original-start-time.time-zone" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "original-start-time.date-time" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "status" => { + request_original_start_time_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_original_start_time_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_original_start_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "i-cal-uid" => { + request_original_start_time_init(&mut request); + request.i_cal_uid = Some(value.unwrap_or("").to_string()); + }, + "gadget.preferences" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().preferences.push(value.unwrap_or("").to_string()); + }, + "gadget.title" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "gadget.height" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "gadget.height", "integer"); + }, + "gadget.width" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "gadget.width", "integer"); + }, + "gadget.link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().link = value.unwrap_or("").to_string(); + }, + "gadget.type" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "gadget.display" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().display = value.unwrap_or("").to_string(); + }, + "gadget.icon-link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().icon_link = value.unwrap_or("").to_string(); + }, + "end-time-unspecified" => { + request_gadget_init(&mut request); + request.end_time_unspecified = Some(arg_from_str(value.unwrap_or("false"), err, "end-time-unspecified", "boolean")); + }, + "sequence" => { + request_gadget_init(&mut request); + request.sequence = Some(arg_from_str(value.unwrap_or("-0"), err, "sequence", "integer")); + }, + "visibility" => { + request_gadget_init(&mut request); + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "guests-can-modify" => { + request_gadget_init(&mut request); + request.guests_can_modify = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-modify", "boolean")); + }, + "attendees-omitted" => { + request_gadget_init(&mut request); + request.attendees_omitted = Some(arg_from_str(value.unwrap_or("false"), err, "attendees-omitted", "boolean")); + }, + "kind" => { + request_gadget_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "locked" => { + request_gadget_init(&mut request); + request.locked = Some(arg_from_str(value.unwrap_or("false"), err, "locked", "boolean")); + }, + "created" => { + request_gadget_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "color-id" => { + request_gadget_init(&mut request); + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "anyone-can-add-self" => { + request_gadget_init(&mut request); + request.anyone_can_add_self = Some(arg_from_str(value.unwrap_or("false"), err, "anyone-can-add-self", "boolean")); + }, + "reminders.use-default" => { + request_reminders_init(&mut request); + request.reminders.as_mut().unwrap().use_default = arg_from_str(value.unwrap_or("false"), err, "reminders.use-default", "boolean"); + }, + "guests-can-see-other-guests" => { + request_reminders_init(&mut request); + request.guests_can_see_other_guests = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-see-other-guests", "boolean")); + }, + "summary" => { + request_reminders_init(&mut request); + request.summary = Some(value.unwrap_or("").to_string()); + }, + "guests-can-invite-others" => { + request_reminders_init(&mut request); + request.guests_can_invite_others = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-invite-others", "boolean")); + }, + "transparency" => { + request_reminders_init(&mut request); + request.transparency = Some(value.unwrap_or("").to_string()); + }, + "private-copy" => { + request_reminders_init(&mut request); + request.private_copy = Some(arg_from_str(value.unwrap_or("false"), err, "private-copy", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_quick_add(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.events().quick_add(&self.opt.arg_calendar_id, &self.opt.arg_text); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Event = Default::default(); + let mut call = self.hub.events().update(&request, &self.opt.arg_calendar_id, &self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notifications" => { + call = call.send_notifications(arg_from_str(value.unwrap_or("false"), err, "send-notifications", "boolean")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::Event) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_end_init(request: &mut api::Event) { + if request.end.is_none() { + request.end = Some(Default::default()); + } + } + + fn request_extended_properties_init(request: &mut api::Event) { + if request.extended_properties.is_none() { + request.extended_properties = Some(Default::default()); + } + } + + fn request_gadget_init(request: &mut api::Event) { + if request.gadget.is_none() { + request.gadget = Some(Default::default()); + } + } + + fn request_organizer_init(request: &mut api::Event) { + if request.organizer.is_none() { + request.organizer = Some(Default::default()); + } + } + + fn request_original_start_time_init(request: &mut api::Event) { + if request.original_start_time.is_none() { + request.original_start_time = Some(Default::default()); + } + } + + fn request_reminders_init(request: &mut api::Event) { + if request.reminders.is_none() { + request.reminders = Some(Default::default()); + } + } + + fn request_source_init(request: &mut api::Event) { + if request.source.is_none() { + request.source = Some(Default::default()); + } + } + + fn request_start_init(request: &mut api::Event) { + if request.start.is_none() { + request.start = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "extended-properties.shared" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().shared.push(value.unwrap_or("").to_string()); + }, + "extended-properties.private" => { + request_extended_properties_init(&mut request); + request.extended_properties.as_mut().unwrap().private.push(value.unwrap_or("").to_string()); + }, + "creator.self" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "creator.self", "boolean"); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "creator.email" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "organizer.self" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().self_ = arg_from_str(value.unwrap_or("false"), err, "organizer.self", "boolean"); + }, + "organizer.display-name" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "organizer.email" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().email = value.unwrap_or("").to_string(); + }, + "organizer.id" => { + request_organizer_init(&mut request); + request.organizer.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "id" => { + request_organizer_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "hangout-link" => { + request_organizer_init(&mut request); + request.hangout_link = Some(value.unwrap_or("").to_string()); + }, + "end.date" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "end.time-zone" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "end.date-time" => { + request_end_init(&mut request); + request.end.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "source.url" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "source.title" => { + request_source_init(&mut request); + request.source.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "html-link" => { + request_source_init(&mut request); + request.html_link = Some(value.unwrap_or("").to_string()); + }, + "recurrence" => { + request_source_init(&mut request); + if request.recurrence.is_none() { + request.recurrence = Some(Default::default()); + } + request.recurrence.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start.date" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "start.time-zone" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "start.date-time" => { + request_start_init(&mut request); + request.start.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "etag" => { + request_start_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_start_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "recurring-event-id" => { + request_start_init(&mut request); + request.recurring_event_id = Some(value.unwrap_or("").to_string()); + }, + "original-start-time.date" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "original-start-time.time-zone" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "original-start-time.date-time" => { + request_original_start_time_init(&mut request); + request.original_start_time.as_mut().unwrap().date_time = value.unwrap_or("").to_string(); + }, + "status" => { + request_original_start_time_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_original_start_time_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_original_start_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "i-cal-uid" => { + request_original_start_time_init(&mut request); + request.i_cal_uid = Some(value.unwrap_or("").to_string()); + }, + "gadget.preferences" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().preferences.push(value.unwrap_or("").to_string()); + }, + "gadget.title" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "gadget.height" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "gadget.height", "integer"); + }, + "gadget.width" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "gadget.width", "integer"); + }, + "gadget.link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().link = value.unwrap_or("").to_string(); + }, + "gadget.type" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "gadget.display" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().display = value.unwrap_or("").to_string(); + }, + "gadget.icon-link" => { + request_gadget_init(&mut request); + request.gadget.as_mut().unwrap().icon_link = value.unwrap_or("").to_string(); + }, + "end-time-unspecified" => { + request_gadget_init(&mut request); + request.end_time_unspecified = Some(arg_from_str(value.unwrap_or("false"), err, "end-time-unspecified", "boolean")); + }, + "sequence" => { + request_gadget_init(&mut request); + request.sequence = Some(arg_from_str(value.unwrap_or("-0"), err, "sequence", "integer")); + }, + "visibility" => { + request_gadget_init(&mut request); + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "guests-can-modify" => { + request_gadget_init(&mut request); + request.guests_can_modify = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-modify", "boolean")); + }, + "attendees-omitted" => { + request_gadget_init(&mut request); + request.attendees_omitted = Some(arg_from_str(value.unwrap_or("false"), err, "attendees-omitted", "boolean")); + }, + "kind" => { + request_gadget_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "locked" => { + request_gadget_init(&mut request); + request.locked = Some(arg_from_str(value.unwrap_or("false"), err, "locked", "boolean")); + }, + "created" => { + request_gadget_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "color-id" => { + request_gadget_init(&mut request); + request.color_id = Some(value.unwrap_or("").to_string()); + }, + "anyone-can-add-self" => { + request_gadget_init(&mut request); + request.anyone_can_add_self = Some(arg_from_str(value.unwrap_or("false"), err, "anyone-can-add-self", "boolean")); + }, + "reminders.use-default" => { + request_reminders_init(&mut request); + request.reminders.as_mut().unwrap().use_default = arg_from_str(value.unwrap_or("false"), err, "reminders.use-default", "boolean"); + }, + "guests-can-see-other-guests" => { + request_reminders_init(&mut request); + request.guests_can_see_other_guests = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-see-other-guests", "boolean")); + }, + "summary" => { + request_reminders_init(&mut request); + request.summary = Some(value.unwrap_or("").to_string()); + }, + "guests-can-invite-others" => { + request_reminders_init(&mut request); + request.guests_can_invite_others = Some(arg_from_str(value.unwrap_or("false"), err, "guests-can-invite-others", "boolean")); + }, + "transparency" => { + request_reminders_init(&mut request); + request.transparency = Some(value.unwrap_or("").to_string()); + }, + "private-copy" => { + request_reminders_init(&mut request); + request.private_copy = Some(arg_from_str(value.unwrap_or("false"), err, "private-copy", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.events().watch(&request, &self.opt.arg_calendar_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "time-zone" => { + call = call.time_zone(value.unwrap_or("")); + }, + "time-min" => { + call = call.time_min(value.unwrap_or("")); + }, + "time-max" => { + call = call.time_max(value.unwrap_or("")); + }, + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "single-events" => { + call = call.single_events(arg_from_str(value.unwrap_or("false"), err, "single-events", "boolean")); + }, + "show-hidden-invitations" => { + call = call.show_hidden_invitations(arg_from_str(value.unwrap_or("false"), err, "show-hidden-invitations", "boolean")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "shared-extended-property" => { + call = call.add_shared_extended_property(value.unwrap_or("")); + }, + "q" => { + call = call.q(value.unwrap_or("")); + }, + "private-extended-property" => { + call = call.add_private_extended_property(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-attendees" => { + call = call.max_attendees(arg_from_str(value.unwrap_or("-0"), err, "max-attendees", "integer")); + }, + "i-cal-uid" => { + call = call.i_cal_uid(value.unwrap_or("")); + }, + "always-include-email" => { + call = call.always_include_email(arg_from_str(value.unwrap_or("false"), err, "always-include-email", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _freebusy_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::FreeBusyRequest = Default::default(); + let mut call = self.hub.freebusy().query(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time-max" => { + request.time_max = Some(value.unwrap_or("").to_string()); + }, + "calendar-expansion-max" => { + request.calendar_expansion_max = Some(arg_from_str(value.unwrap_or("-0"), err, "calendar-expansion-max", "integer")); + }, + "time-zone" => { + request.time_zone = Some(value.unwrap_or("").to_string()); + }, + "time-min" => { + request.time_min = Some(value.unwrap_or("").to_string()); + }, + "group-expansion-max" => { + request.group_expansion_max = Some(arg_from_str(value.unwrap_or("-0"), err, "group-expansion-max", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _settings_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.settings().get(&self.opt.arg_setting); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _settings_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.settings().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _settings_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.settings().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync-token" => { + call = call.sync_token(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_acl { + if self.opt.cmd_delete { + call_result = self._acl_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._acl_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._acl_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._acl_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._acl_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._acl_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._acl_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_calendar_list { + if self.opt.cmd_delete { + call_result = self._calendar_list_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._calendar_list_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._calendar_list_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._calendar_list_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._calendar_list_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._calendar_list_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._calendar_list_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_calendars { + if self.opt.cmd_clear { + call_result = self._calendars_clear(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._calendars_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._calendars_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._calendars_insert(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._calendars_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._calendars_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_colors { + if self.opt.cmd_get { + call_result = self._colors_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_events { + if self.opt.cmd_delete { + call_result = self._events_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._events_get(dry_run, &mut err); + } else if self.opt.cmd_import { + call_result = self._events_import(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._events_insert(dry_run, &mut err); + } else if self.opt.cmd_instances { + call_result = self._events_instances(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._events_list(dry_run, &mut err); + } else if self.opt.cmd_move { + call_result = self._events_move(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._events_patch(dry_run, &mut err); + } else if self.opt.cmd_quick_add { + call_result = self._events_quick_add(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._events_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._events_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_freebusy { + if self.opt.cmd_query { + call_result = self._freebusy_query(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_settings { + if self.opt.cmd_get { + call_result = self._settings_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._settings_list(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._settings_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "calendar3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "calendar3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::CalendarHub::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/civicinfo2-cli/Cargo.toml b/gen/civicinfo2-cli/Cargo.toml new file mode 100644 index 00000000000..602bf30fe8e --- /dev/null +++ b/gen/civicinfo2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-civicinfo2-cli" +version = "0.0.1+20150302" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Civic Info (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/civicinfo2-cli" +homepage = "https://developers.google.com/civic-information" +documentation = "http://byron.github.io/google-apis-rs/google_civicinfo2_cli" +license = "MIT" +keywords = ["civicinfo", "google", "cli"] + +[[bin]] +name = "civicinfo2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-civicinfo2] +path = "../civicinfo2" diff --git a/gen/civicinfo2-cli/LICENSE.md b/gen/civicinfo2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/civicinfo2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/civicinfo2-cli/README.md b/gen/civicinfo2-cli/README.md new file mode 100644 index 00000000000..6d55c3afcf2 --- /dev/null +++ b/gen/civicinfo2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CIVICINFO:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/civicinfo2-cli/mkdocs.yml b/gen/civicinfo2-cli/mkdocs.yml new file mode 100644 index 00000000000..3f277970cdd --- /dev/null +++ b/gen/civicinfo2-cli/mkdocs.yml @@ -0,0 +1,21 @@ +site_name: Civic Info v0.0.1+20150302 +site_url: http://byron.github.io/google-apis-rs/google-civicinfo2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/civicinfo2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['divisions_search.md', 'Divisions', 'Search'] +- ['elections_election-query.md', 'Elections', 'Election Query'] +- ['elections_voter-info-query.md', 'Elections', 'Voter Info Query'] +- ['representatives_representative-info-by-address.md', 'Representatives', 'Representative Info By Address'] +- ['representatives_representative-info-by-division.md', 'Representatives', 'Representative Info By Division'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/civicinfo2-cli/src/cmn.rs b/gen/civicinfo2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/civicinfo2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/civicinfo2-cli/src/main.rs b/gen/civicinfo2-cli/src/main.rs new file mode 100644 index 00000000000..3616811488c --- /dev/null +++ b/gen/civicinfo2-cli/src/main.rs @@ -0,0 +1,395 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_civicinfo2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + civicinfo2 [options] divisions search [-p ]... [-o ] + civicinfo2 [options] elections election-query [-p ]... [-o ] + civicinfo2 [options] elections voter-info-query
[-p ]... [-o ] + civicinfo2 [options] representatives representative-info-by-address [-p ]... [-o ] + civicinfo2 [options] representatives representative-info-by-division [-p ]... [-o ] + civicinfo2 --help + +All documentation details can be found TODO: + +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] +"); + +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::CivicInfo>, +} + + +impl Engine { + fn _divisions_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.divisions().search(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "query" => { + call = call.query(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _elections_election_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.elections().election_query(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _elections_voter_info_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.elections().voter_info_query(&self.opt.arg_address); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "official-only" => { + call = call.official_only(arg_from_str(value.unwrap_or("false"), err, "official-only", "boolean")); + }, + "election-id" => { + call = call.election_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _representatives_representative_info_by_address(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.representatives().representative_info_by_address(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "roles" => { + call = call.add_roles(value.unwrap_or("")); + }, + "levels" => { + call = call.add_levels(value.unwrap_or("")); + }, + "include-offices" => { + call = call.include_offices(arg_from_str(value.unwrap_or("false"), err, "include-offices", "boolean")); + }, + "address" => { + call = call.address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _representatives_representative_info_by_division(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.representatives().representative_info_by_division(&self.opt.arg_ocd_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "roles" => { + call = call.add_roles(value.unwrap_or("")); + }, + "recursive" => { + call = call.recursive(arg_from_str(value.unwrap_or("false"), err, "recursive", "boolean")); + }, + "levels" => { + call = call.add_levels(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_divisions { + if self.opt.cmd_search { + call_result = self._divisions_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_elections { + if self.opt.cmd_election_query { + call_result = self._elections_election_query(dry_run, &mut err); + } else if self.opt.cmd_voter_info_query { + call_result = self._elections_voter_info_query(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_representatives { + if self.opt.cmd_representative_info_by_address { + call_result = self._representatives_representative_info_by_address(dry_run, &mut err); + } else if self.opt.cmd_representative_info_by_division { + call_result = self._representatives_representative_info_by_division(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "civicinfo2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "civicinfo2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::CivicInfo::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/cloudlatencytest2-cli/Cargo.toml b/gen/cloudlatencytest2-cli/Cargo.toml new file mode 100644 index 00000000000..0d715c16e62 --- /dev/null +++ b/gen/cloudlatencytest2-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-cloudlatencytest2-cli" +version = "0.0.1+20150206" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with cloudlatencytest (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/cloudlatencytest2-cli" +documentation = "http://byron.github.io/google-apis-rs/google_cloudlatencytest2_cli" +license = "MIT" +keywords = ["cloudlatencytest", "google", "cli"] + +[[bin]] +name = "cloudlatencytest2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-cloudlatencytest2] +path = "../cloudlatencytest2" diff --git a/gen/cloudlatencytest2-cli/LICENSE.md b/gen/cloudlatencytest2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/cloudlatencytest2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/cloudlatencytest2-cli/README.md b/gen/cloudlatencytest2-cli/README.md new file mode 100644 index 00000000000..f905faf8618 --- /dev/null +++ b/gen/cloudlatencytest2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CLOUDLATENCYTEST:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/cloudlatencytest2-cli/mkdocs.yml b/gen/cloudlatencytest2-cli/mkdocs.yml new file mode 100644 index 00000000000..0c1e2f9a96e --- /dev/null +++ b/gen/cloudlatencytest2-cli/mkdocs.yml @@ -0,0 +1,18 @@ +site_name: cloudlatencytest v0.0.1+20150206 +site_url: http://byron.github.io/google-apis-rs/google-cloudlatencytest2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/cloudlatencytest2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['statscollection_updateaggregatedstats.md', 'Statscollection', 'Updateaggregatedstats'] +- ['statscollection_updatestats.md', 'Statscollection', 'Updatestats'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/cloudlatencytest2-cli/src/cmn.rs b/gen/cloudlatencytest2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/cloudlatencytest2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/cloudlatencytest2-cli/src/main.rs b/gen/cloudlatencytest2-cli/src/main.rs new file mode 100644 index 00000000000..f1352391238 --- /dev/null +++ b/gen/cloudlatencytest2-cli/src/main.rs @@ -0,0 +1,249 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_cloudlatencytest2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + cloudlatencytest2 [options] statscollection updateaggregatedstats -r ... [-p ]... [-o ] + cloudlatencytest2 [options] statscollection updatestats -r ... [-p ]... [-o ] + cloudlatencytest2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Cloudlatencytest>, +} + + +impl Engine { + fn _statscollection_updateaggregatedstats(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AggregatedStats = Default::default(); + let mut call = self.hub.statscollection().updateaggregatedstats(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _statscollection_updatestats(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Stats = Default::default(); + let mut call = self.hub.statscollection().updatestats(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time" => { + request.time = Some(arg_from_str(value.unwrap_or("0.0"), err, "time", "number")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_statscollection { + if self.opt.cmd_updateaggregatedstats { + call_result = self._statscollection_updateaggregatedstats(dry_run, &mut err); + } else if self.opt.cmd_updatestats { + call_result = self._statscollection_updatestats(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "cloudlatencytest2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "cloudlatencytest2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Cloudlatencytest::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/cloudmonitoring2_beta2-cli/Cargo.toml b/gen/cloudmonitoring2_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..7c42eed5fb7 --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-cloudmonitoring2_beta2-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Cloud Monitoring (protocol v2beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/cloudmonitoring2_beta2-cli" +homepage = "https://cloud.google.com/monitoring/v2beta2/" +documentation = "http://byron.github.io/google-apis-rs/google_cloudmonitoring2_beta2_cli" +license = "MIT" +keywords = ["cloudmonitoring", "google", "cli"] + +[[bin]] +name = "cloudmonitoring2-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-cloudmonitoring2_beta2] +path = "../cloudmonitoring2_beta2" diff --git a/gen/cloudmonitoring2_beta2-cli/LICENSE.md b/gen/cloudmonitoring2_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/cloudmonitoring2_beta2-cli/README.md b/gen/cloudmonitoring2_beta2-cli/README.md new file mode 100644 index 00000000000..6a0abc727d5 --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CLOUDMONITORING:V2BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/cloudmonitoring2_beta2-cli/mkdocs.yml b/gen/cloudmonitoring2_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..61709342d5f --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/mkdocs.yml @@ -0,0 +1,22 @@ +site_name: Cloud Monitoring v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-cloudmonitoring2_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/cloudmonitoring2_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['metric-descriptors_create.md', 'Metric Descriptors', 'Create'] +- ['metric-descriptors_delete.md', 'Metric Descriptors', 'Delete'] +- ['metric-descriptors_list.md', 'Metric Descriptors', 'List'] +- ['timeseries_list.md', 'Timeseries', 'List'] +- ['timeseries_write.md', 'Timeseries', 'Write'] +- ['timeseries-descriptors_list.md', 'Timeseries Descriptors', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/cloudmonitoring2_beta2-cli/src/cmn.rs b/gen/cloudmonitoring2_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/cloudmonitoring2_beta2-cli/src/main.rs b/gen/cloudmonitoring2_beta2-cli/src/main.rs new file mode 100644 index 00000000000..91470c57511 --- /dev/null +++ b/gen/cloudmonitoring2_beta2-cli/src/main.rs @@ -0,0 +1,572 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_cloudmonitoring2_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + cloudmonitoring2-beta2 [options] metric-descriptors create -r ... [-p ]... [-o ] + cloudmonitoring2-beta2 [options] metric-descriptors delete [-p ]... [-o ] + cloudmonitoring2-beta2 [options] metric-descriptors list -r ... [-p ]... [-o ] + cloudmonitoring2-beta2 [options] timeseries list -r ... [-p ]... [-o ] + cloudmonitoring2-beta2 [options] timeseries write -r ... [-p ]... [-o ] + cloudmonitoring2-beta2 [options] timeseries-descriptors list -r ... [-p ]... [-o ] + cloudmonitoring2-beta2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::CloudMonitoring>, +} + + +impl Engine { + fn _metric_descriptors_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::MetricDescriptor = Default::default(); + let mut call = self.hub.metric_descriptors().create(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_type_descriptor_init(request: &mut api::MetricDescriptor) { + if request.type_descriptor.is_none() { + request.type_descriptor = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "type-descriptor.value-type" => { + request_type_descriptor_init(&mut request); + request.type_descriptor.as_mut().unwrap().value_type = value.unwrap_or("").to_string(); + }, + "type-descriptor.metric-type" => { + request_type_descriptor_init(&mut request); + request.type_descriptor.as_mut().unwrap().metric_type = value.unwrap_or("").to_string(); + }, + "description" => { + request_type_descriptor_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_type_descriptor_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metric_descriptors_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.metric_descriptors().delete(&self.opt.arg_project, &self.opt.arg_metric); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metric_descriptors_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ListMetricDescriptorsRequest = Default::default(); + let mut call = self.hub.metric_descriptors().list(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "query" => { + call = call.query(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "count" => { + call = call.count(arg_from_str(value.unwrap_or("-0"), err, "count", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeseries_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ListTimeseriesRequest = Default::default(); + let mut call = self.hub.timeseries().list(&request, &self.opt.arg_project, &self.opt.arg_metric, &self.opt.arg_youngest); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "window" => { + call = call.window(value.unwrap_or("")); + }, + "timespan" => { + call = call.timespan(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "oldest" => { + call = call.oldest(value.unwrap_or("")); + }, + "labels" => { + call = call.add_labels(value.unwrap_or("")); + }, + "count" => { + call = call.count(arg_from_str(value.unwrap_or("-0"), err, "count", "integer")); + }, + "aggregator" => { + call = call.aggregator(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeseries_write(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::WriteTimeseriesRequest = Default::default(); + let mut call = self.hub.timeseries().write(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "common-labels" => { + if request.common_labels.is_none() { + request.common_labels = Some(Default::default()); + } + request.common_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeseries_descriptors_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ListTimeseriesDescriptorsRequest = Default::default(); + let mut call = self.hub.timeseries_descriptors().list(&request, &self.opt.arg_project, &self.opt.arg_metric, &self.opt.arg_youngest); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "window" => { + call = call.window(value.unwrap_or("")); + }, + "timespan" => { + call = call.timespan(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "oldest" => { + call = call.oldest(value.unwrap_or("")); + }, + "labels" => { + call = call.add_labels(value.unwrap_or("")); + }, + "count" => { + call = call.count(arg_from_str(value.unwrap_or("-0"), err, "count", "integer")); + }, + "aggregator" => { + call = call.aggregator(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_metric_descriptors { + if self.opt.cmd_create { + call_result = self._metric_descriptors_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._metric_descriptors_delete(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._metric_descriptors_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_timeseries { + if self.opt.cmd_list { + call_result = self._timeseries_list(dry_run, &mut err); + } else if self.opt.cmd_write { + call_result = self._timeseries_write(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_timeseries_descriptors { + if self.opt.cmd_list { + call_result = self._timeseries_descriptors_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "cloudmonitoring2-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "cloudmonitoring2-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::CloudMonitoring::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/cloudsearch1-cli/Cargo.toml b/gen/cloudsearch1-cli/Cargo.toml new file mode 100644 index 00000000000..52f8b401a33 --- /dev/null +++ b/gen/cloudsearch1-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-cloudsearch1-cli" +version = "0.0.1+20150309" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with cloudsearch (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/cloudsearch1-cli" +documentation = "http://byron.github.io/google-apis-rs/google_cloudsearch1_cli" +license = "MIT" +keywords = ["cloudsearch", "google", "cli"] + +[[bin]] +name = "cloudsearch1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-cloudsearch1] +path = "../cloudsearch1" diff --git a/gen/cloudsearch1-cli/LICENSE.md b/gen/cloudsearch1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/cloudsearch1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/cloudsearch1-cli/README.md b/gen/cloudsearch1-cli/README.md new file mode 100644 index 00000000000..7b0247d3fdd --- /dev/null +++ b/gen/cloudsearch1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CLOUDSEARCH:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/cloudsearch1-cli/mkdocs.yml b/gen/cloudsearch1-cli/mkdocs.yml new file mode 100644 index 00000000000..a7ab174bdb5 --- /dev/null +++ b/gen/cloudsearch1-cli/mkdocs.yml @@ -0,0 +1,22 @@ +site_name: cloudsearch v0.0.1+20150309 +site_url: http://byron.github.io/google-apis-rs/google-cloudsearch1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/cloudsearch1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['projects_indexes-documents-create.md', 'Projects', 'Indexes Documents Create'] +- ['projects_indexes-documents-delete.md', 'Projects', 'Indexes Documents Delete'] +- ['projects_indexes-documents-get.md', 'Projects', 'Indexes Documents Get'] +- ['projects_indexes-documents-list.md', 'Projects', 'Indexes Documents List'] +- ['projects_indexes-list.md', 'Projects', 'Indexes List'] +- ['projects_indexes-search.md', 'Projects', 'Indexes Search'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/cloudsearch1-cli/src/cmn.rs b/gen/cloudsearch1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/cloudsearch1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/cloudsearch1-cli/src/main.rs b/gen/cloudsearch1-cli/src/main.rs new file mode 100644 index 00000000000..7cbf7e57a66 --- /dev/null +++ b/gen/cloudsearch1-cli/src/main.rs @@ -0,0 +1,469 @@ +// 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 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 [options] projects indexes-documents-create -r ... [-p ]... [-o ] + cloudsearch1 [options] projects indexes-documents-delete [-p ]... [-o ] + cloudsearch1 [options] projects indexes-documents-get [-p ]... [-o ] + cloudsearch1 [options] projects indexes-documents-list [-p ]... [-o ] + cloudsearch1 [options] projects indexes-list [-p ]... [-o ] + cloudsearch1 [options] projects indexes-search [-p ]... [-o ] + cloudsearch1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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 _projects_indexes_documents_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Document = Default::default(); + let mut call = self.hub.projects().indexes_documents_create(&request, &self.opt.arg_project_id, &self.opt.arg_index_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "doc-id" => { + request.doc_id = Some(value.unwrap_or("").to_string()); + }, + "rank" => { + request.rank = Some(arg_from_str(value.unwrap_or("-0"), err, "rank", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_indexes_documents_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().indexes_documents_delete(&self.opt.arg_project_id, &self.opt.arg_index_id, &self.opt.arg_doc_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_indexes_documents_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().indexes_documents_get(&self.opt.arg_project_id, &self.opt.arg_index_id, &self.opt.arg_doc_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_indexes_documents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let page_size: i32 = arg_from_str(&self.opt.arg_page_size, err, "", "integer"); + let mut call = self.hub.projects().indexes_documents_list(&self.opt.arg_project_id, &self.opt.arg_index_id, page_size, &self.opt.arg_page_token, &self.opt.arg_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_indexes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let page_size: i32 = arg_from_str(&self.opt.arg_page_size, err, "", "integer"); + let mut call = self.hub.projects().indexes_list(&self.opt.arg_project_id, &self.opt.arg_index_name_prefix, page_size, &self.opt.arg_page_token, &self.opt.arg_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_indexes_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let page_size: i32 = arg_from_str(&self.opt.arg_page_size, err, "", "integer"); + let offset: i32 = arg_from_str(&self.opt.arg_offset, err, "", "integer"); + let matched_count_accuracy: i32 = arg_from_str(&self.opt.arg_matched_count_accuracy, err, "", "integer"); + let scorer_size: i32 = arg_from_str(&self.opt.arg_scorer_size, err, "", "integer"); + let mut call = self.hub.projects().indexes_search(&self.opt.arg_project_id, &self.opt.arg_index_id, &self.opt.arg_query, &self.opt.arg_field_expressions, page_size, &self.opt.arg_page_token, offset, matched_count_accuracy, &self.opt.arg_order_by, &self.opt.arg_scorer, scorer_size, &self.opt.arg_return_fields); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_projects { + if self.opt.cmd_indexes_documents_create { + call_result = self._projects_indexes_documents_create(dry_run, &mut err); + } else if self.opt.cmd_indexes_documents_delete { + call_result = self._projects_indexes_documents_delete(dry_run, &mut err); + } else if self.opt.cmd_indexes_documents_get { + call_result = self._projects_indexes_documents_get(dry_run, &mut err); + } else if self.opt.cmd_indexes_documents_list { + call_result = self._projects_indexes_documents_list(dry_run, &mut err); + } else if self.opt.cmd_indexes_list { + call_result = self._projects_indexes_list(dry_run, &mut err); + } else if self.opt.cmd_indexes_search { + call_result = self._projects_indexes_search(dry_run, &mut err); + } else { + unreachable!(); + } + } 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") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "cloudsearch1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Cloudsearch::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/compute1-cli/Cargo.toml b/gen/compute1-cli/Cargo.toml new file mode 100644 index 00000000000..b74e76f33ca --- /dev/null +++ b/gen/compute1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-compute1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with compute (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/compute1-cli" +homepage = "https://developers.google.com/compute/docs/reference/latest/" +documentation = "http://byron.github.io/google-apis-rs/google_compute1_cli" +license = "MIT" +keywords = ["compute", "google", "cli"] + +[[bin]] +name = "compute1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-compute1] +path = "../compute1" diff --git a/gen/compute1-cli/LICENSE.md b/gen/compute1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/compute1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/compute1-cli/README.md b/gen/compute1-cli/README.md new file mode 100644 index 00000000000..0589fe2c9ed --- /dev/null +++ b/gen/compute1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO COMPUTE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/compute1-cli/mkdocs.yml b/gen/compute1-cli/mkdocs.yml new file mode 100644 index 00000000000..62d86dc9e01 --- /dev/null +++ b/gen/compute1-cli/mkdocs.yml @@ -0,0 +1,162 @@ +site_name: compute v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-compute1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/compute1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['addresses_aggregated-list.md', 'Addresses', 'Aggregated List'] +- ['addresses_delete.md', 'Addresses', 'Delete'] +- ['addresses_get.md', 'Addresses', 'Get'] +- ['addresses_insert.md', 'Addresses', 'Insert'] +- ['addresses_list.md', 'Addresses', 'List'] +- ['backend-services_delete.md', 'Backend Services', 'Delete'] +- ['backend-services_get.md', 'Backend Services', 'Get'] +- ['backend-services_get-health.md', 'Backend Services', 'Get Health'] +- ['backend-services_insert.md', 'Backend Services', 'Insert'] +- ['backend-services_list.md', 'Backend Services', 'List'] +- ['backend-services_patch.md', 'Backend Services', 'Patch'] +- ['backend-services_update.md', 'Backend Services', 'Update'] +- ['disk-types_aggregated-list.md', 'Disk Types', 'Aggregated List'] +- ['disk-types_get.md', 'Disk Types', 'Get'] +- ['disk-types_list.md', 'Disk Types', 'List'] +- ['disks_aggregated-list.md', 'Disks', 'Aggregated List'] +- ['disks_create-snapshot.md', 'Disks', 'Create Snapshot'] +- ['disks_delete.md', 'Disks', 'Delete'] +- ['disks_get.md', 'Disks', 'Get'] +- ['disks_insert.md', 'Disks', 'Insert'] +- ['disks_list.md', 'Disks', 'List'] +- ['firewalls_delete.md', 'Firewalls', 'Delete'] +- ['firewalls_get.md', 'Firewalls', 'Get'] +- ['firewalls_insert.md', 'Firewalls', 'Insert'] +- ['firewalls_list.md', 'Firewalls', 'List'] +- ['firewalls_patch.md', 'Firewalls', 'Patch'] +- ['firewalls_update.md', 'Firewalls', 'Update'] +- ['forwarding-rules_aggregated-list.md', 'Forwarding Rules', 'Aggregated List'] +- ['forwarding-rules_delete.md', 'Forwarding Rules', 'Delete'] +- ['forwarding-rules_get.md', 'Forwarding Rules', 'Get'] +- ['forwarding-rules_insert.md', 'Forwarding Rules', 'Insert'] +- ['forwarding-rules_list.md', 'Forwarding Rules', 'List'] +- ['forwarding-rules_set-target.md', 'Forwarding Rules', 'Set Target'] +- ['global-addresses_delete.md', 'Global Addresses', 'Delete'] +- ['global-addresses_get.md', 'Global Addresses', 'Get'] +- ['global-addresses_insert.md', 'Global Addresses', 'Insert'] +- ['global-addresses_list.md', 'Global Addresses', 'List'] +- ['global-forwarding-rules_delete.md', 'Global Forwarding Rules', 'Delete'] +- ['global-forwarding-rules_get.md', 'Global Forwarding Rules', 'Get'] +- ['global-forwarding-rules_insert.md', 'Global Forwarding Rules', 'Insert'] +- ['global-forwarding-rules_list.md', 'Global Forwarding Rules', 'List'] +- ['global-forwarding-rules_set-target.md', 'Global Forwarding Rules', 'Set Target'] +- ['global-operations_aggregated-list.md', 'Global Operations', 'Aggregated List'] +- ['global-operations_delete.md', 'Global Operations', 'Delete'] +- ['global-operations_get.md', 'Global Operations', 'Get'] +- ['global-operations_list.md', 'Global Operations', 'List'] +- ['http-health-checks_delete.md', 'Http Health Checks', 'Delete'] +- ['http-health-checks_get.md', 'Http Health Checks', 'Get'] +- ['http-health-checks_insert.md', 'Http Health Checks', 'Insert'] +- ['http-health-checks_list.md', 'Http Health Checks', 'List'] +- ['http-health-checks_patch.md', 'Http Health Checks', 'Patch'] +- ['http-health-checks_update.md', 'Http Health Checks', 'Update'] +- ['images_delete.md', 'Images', 'Delete'] +- ['images_deprecate.md', 'Images', 'Deprecate'] +- ['images_get.md', 'Images', 'Get'] +- ['images_insert.md', 'Images', 'Insert'] +- ['images_list.md', 'Images', 'List'] +- ['instance-templates_delete.md', 'Instance Templates', 'Delete'] +- ['instance-templates_get.md', 'Instance Templates', 'Get'] +- ['instance-templates_insert.md', 'Instance Templates', 'Insert'] +- ['instance-templates_list.md', 'Instance Templates', 'List'] +- ['instances_add-access-config.md', 'Instances', 'Add Access Config'] +- ['instances_aggregated-list.md', 'Instances', 'Aggregated List'] +- ['instances_attach-disk.md', 'Instances', 'Attach Disk'] +- ['instances_delete.md', 'Instances', 'Delete'] +- ['instances_delete-access-config.md', 'Instances', 'Delete Access Config'] +- ['instances_detach-disk.md', 'Instances', 'Detach Disk'] +- ['instances_get.md', 'Instances', 'Get'] +- ['instances_get-serial-port-output.md', 'Instances', 'Get Serial Port Output'] +- ['instances_insert.md', 'Instances', 'Insert'] +- ['instances_list.md', 'Instances', 'List'] +- ['instances_reset.md', 'Instances', 'Reset'] +- ['instances_set-disk-auto-delete.md', 'Instances', 'Set Disk Auto Delete'] +- ['instances_set-metadata.md', 'Instances', 'Set Metadata'] +- ['instances_set-scheduling.md', 'Instances', 'Set Scheduling'] +- ['instances_set-tags.md', 'Instances', 'Set Tags'] +- ['instances_start.md', 'Instances', 'Start'] +- ['instances_stop.md', 'Instances', 'Stop'] +- ['licenses_get.md', 'Licenses', 'Get'] +- ['machine-types_aggregated-list.md', 'Machine Types', 'Aggregated List'] +- ['machine-types_get.md', 'Machine Types', 'Get'] +- ['machine-types_list.md', 'Machine Types', 'List'] +- ['networks_delete.md', 'Networks', 'Delete'] +- ['networks_get.md', 'Networks', 'Get'] +- ['networks_insert.md', 'Networks', 'Insert'] +- ['networks_list.md', 'Networks', 'List'] +- ['projects_get.md', 'Projects', 'Get'] +- ['projects_move-disk.md', 'Projects', 'Move Disk'] +- ['projects_move-instance.md', 'Projects', 'Move Instance'] +- ['projects_set-common-instance-metadata.md', 'Projects', 'Set Common Instance Metadata'] +- ['projects_set-usage-export-bucket.md', 'Projects', 'Set Usage Export Bucket'] +- ['region-operations_delete.md', 'Region Operations', 'Delete'] +- ['region-operations_get.md', 'Region Operations', 'Get'] +- ['region-operations_list.md', 'Region Operations', 'List'] +- ['regions_get.md', 'Regions', 'Get'] +- ['regions_list.md', 'Regions', 'List'] +- ['routes_delete.md', 'Routes', 'Delete'] +- ['routes_get.md', 'Routes', 'Get'] +- ['routes_insert.md', 'Routes', 'Insert'] +- ['routes_list.md', 'Routes', 'List'] +- ['snapshots_delete.md', 'Snapshots', 'Delete'] +- ['snapshots_get.md', 'Snapshots', 'Get'] +- ['snapshots_list.md', 'Snapshots', 'List'] +- ['target-http-proxies_delete.md', 'Target Http Proxies', 'Delete'] +- ['target-http-proxies_get.md', 'Target Http Proxies', 'Get'] +- ['target-http-proxies_insert.md', 'Target Http Proxies', 'Insert'] +- ['target-http-proxies_list.md', 'Target Http Proxies', 'List'] +- ['target-http-proxies_set-url-map.md', 'Target Http Proxies', 'Set Url Map'] +- ['target-instances_aggregated-list.md', 'Target Instances', 'Aggregated List'] +- ['target-instances_delete.md', 'Target Instances', 'Delete'] +- ['target-instances_get.md', 'Target Instances', 'Get'] +- ['target-instances_insert.md', 'Target Instances', 'Insert'] +- ['target-instances_list.md', 'Target Instances', 'List'] +- ['target-pools_add-health-check.md', 'Target Pools', 'Add Health Check'] +- ['target-pools_add-instance.md', 'Target Pools', 'Add Instance'] +- ['target-pools_aggregated-list.md', 'Target Pools', 'Aggregated List'] +- ['target-pools_delete.md', 'Target Pools', 'Delete'] +- ['target-pools_get.md', 'Target Pools', 'Get'] +- ['target-pools_get-health.md', 'Target Pools', 'Get Health'] +- ['target-pools_insert.md', 'Target Pools', 'Insert'] +- ['target-pools_list.md', 'Target Pools', 'List'] +- ['target-pools_remove-health-check.md', 'Target Pools', 'Remove Health Check'] +- ['target-pools_remove-instance.md', 'Target Pools', 'Remove Instance'] +- ['target-pools_set-backup.md', 'Target Pools', 'Set Backup'] +- ['target-vpn-gateways_aggregated-list.md', 'Target Vpn Gateways', 'Aggregated List'] +- ['target-vpn-gateways_delete.md', 'Target Vpn Gateways', 'Delete'] +- ['target-vpn-gateways_get.md', 'Target Vpn Gateways', 'Get'] +- ['target-vpn-gateways_insert.md', 'Target Vpn Gateways', 'Insert'] +- ['target-vpn-gateways_list.md', 'Target Vpn Gateways', 'List'] +- ['url-maps_delete.md', 'Url Maps', 'Delete'] +- ['url-maps_get.md', 'Url Maps', 'Get'] +- ['url-maps_insert.md', 'Url Maps', 'Insert'] +- ['url-maps_list.md', 'Url Maps', 'List'] +- ['url-maps_patch.md', 'Url Maps', 'Patch'] +- ['url-maps_update.md', 'Url Maps', 'Update'] +- ['url-maps_validate.md', 'Url Maps', 'Validate'] +- ['vpn-tunnels_aggregated-list.md', 'Vpn Tunnels', 'Aggregated List'] +- ['vpn-tunnels_delete.md', 'Vpn Tunnels', 'Delete'] +- ['vpn-tunnels_get.md', 'Vpn Tunnels', 'Get'] +- ['vpn-tunnels_insert.md', 'Vpn Tunnels', 'Insert'] +- ['vpn-tunnels_list.md', 'Vpn Tunnels', 'List'] +- ['zone-operations_delete.md', 'Zone Operations', 'Delete'] +- ['zone-operations_get.md', 'Zone Operations', 'Get'] +- ['zone-operations_list.md', 'Zone Operations', 'List'] +- ['zones_get.md', 'Zones', 'Get'] +- ['zones_list.md', 'Zones', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/compute1-cli/src/cmn.rs b/gen/compute1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/compute1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/compute1-cli/src/main.rs b/gen/compute1-cli/src/main.rs new file mode 100644 index 00000000000..c5612a405e8 --- /dev/null +++ b/gen/compute1-cli/src/main.rs @@ -0,0 +1,9416 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_compute1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + compute1 [options] addresses aggregated-list [-p ]... [-o ] + compute1 [options] addresses delete
[-p ]... [-o ] + compute1 [options] addresses get
[-p ]... [-o ] + compute1 [options] addresses insert -r ... [-p ]... [-o ] + compute1 [options] addresses list [-p ]... [-o ] + compute1 [options] backend-services delete [-p ]... [-o ] + compute1 [options] backend-services get [-p ]... [-o ] + compute1 [options] backend-services get-health -r ... [-p ]... [-o ] + compute1 [options] backend-services insert -r ... [-p ]... [-o ] + compute1 [options] backend-services list [-p ]... [-o ] + compute1 [options] backend-services patch -r ... [-p ]... [-o ] + compute1 [options] backend-services update -r ... [-p ]... [-o ] + compute1 [options] disk-types aggregated-list [-p ]... [-o ] + compute1 [options] disk-types get [-p ]... [-o ] + compute1 [options] disk-types list [-p ]... [-o ] + compute1 [options] disks aggregated-list [-p ]... [-o ] + compute1 [options] disks create-snapshot -r ... [-p ]... [-o ] + compute1 [options] disks delete [-p ]... [-o ] + compute1 [options] disks get [-p ]... [-o ] + compute1 [options] disks insert -r ... [-p ]... [-o ] + compute1 [options] disks list [-p ]... [-o ] + compute1 [options] firewalls delete [-p ]... [-o ] + compute1 [options] firewalls get [-p ]... [-o ] + compute1 [options] firewalls insert -r ... [-p ]... [-o ] + compute1 [options] firewalls list [-p ]... [-o ] + compute1 [options] firewalls patch -r ... [-p ]... [-o ] + compute1 [options] firewalls update -r ... [-p ]... [-o ] + compute1 [options] forwarding-rules aggregated-list [-p ]... [-o ] + compute1 [options] forwarding-rules delete [-p ]... [-o ] + compute1 [options] forwarding-rules get [-p ]... [-o ] + compute1 [options] forwarding-rules insert -r ... [-p ]... [-o ] + compute1 [options] forwarding-rules list [-p ]... [-o ] + compute1 [options] forwarding-rules set-target -r ... [-p ]... [-o ] + compute1 [options] global-addresses delete
[-p ]... [-o ] + compute1 [options] global-addresses get
[-p ]... [-o ] + compute1 [options] global-addresses insert -r ... [-p ]... [-o ] + compute1 [options] global-addresses list [-p ]... [-o ] + compute1 [options] global-forwarding-rules delete [-p ]... [-o ] + compute1 [options] global-forwarding-rules get [-p ]... [-o ] + compute1 [options] global-forwarding-rules insert -r ... [-p ]... [-o ] + compute1 [options] global-forwarding-rules list [-p ]... [-o ] + compute1 [options] global-forwarding-rules set-target -r ... [-p ]... [-o ] + compute1 [options] global-operations aggregated-list [-p ]... [-o ] + compute1 [options] global-operations delete [-p ]... + compute1 [options] global-operations get [-p ]... [-o ] + compute1 [options] global-operations list [-p ]... [-o ] + compute1 [options] http-health-checks delete [-p ]... [-o ] + compute1 [options] http-health-checks get [-p ]... [-o ] + compute1 [options] http-health-checks insert -r ... [-p ]... [-o ] + compute1 [options] http-health-checks list [-p ]... [-o ] + compute1 [options] http-health-checks patch -r ... [-p ]... [-o ] + compute1 [options] http-health-checks update -r ... [-p ]... [-o ] + compute1 [options] images delete [-p ]... [-o ] + compute1 [options] images deprecate -r ... [-p ]... [-o ] + compute1 [options] images get [-p ]... [-o ] + compute1 [options] images insert -r ... [-p ]... [-o ] + compute1 [options] images list [-p ]... [-o ] + compute1 [options] instance-templates delete [-p ]... [-o ] + compute1 [options] instance-templates get [-p ]... [-o ] + compute1 [options] instance-templates insert -r ... [-p ]... [-o ] + compute1 [options] instance-templates list [-p ]... [-o ] + compute1 [options] instances add-access-config -r ... [-p ]... [-o ] + compute1 [options] instances aggregated-list [-p ]... [-o ] + compute1 [options] instances attach-disk -r ... [-p ]... [-o ] + compute1 [options] instances delete [-p ]... [-o ] + compute1 [options] instances delete-access-config [-p ]... [-o ] + compute1 [options] instances detach-disk [-p ]... [-o ] + compute1 [options] instances get [-p ]... [-o ] + compute1 [options] instances get-serial-port-output [-p ]... [-o ] + compute1 [options] instances insert -r ... [-p ]... [-o ] + compute1 [options] instances list [-p ]... [-o ] + compute1 [options] instances reset [-p ]... [-o ] + compute1 [options] instances set-disk-auto-delete [-p ]... [-o ] + compute1 [options] instances set-metadata -r ... [-p ]... [-o ] + compute1 [options] instances set-scheduling -r ... [-p ]... [-o ] + compute1 [options] instances set-tags -r ... [-p ]... [-o ] + compute1 [options] instances start [-p ]... [-o ] + compute1 [options] instances stop [-p ]... [-o ] + compute1 [options] licenses get [-p ]... [-o ] + compute1 [options] machine-types aggregated-list [-p ]... [-o ] + compute1 [options] machine-types get [-p ]... [-o ] + compute1 [options] machine-types list [-p ]... [-o ] + compute1 [options] networks delete [-p ]... [-o ] + compute1 [options] networks get [-p ]... [-o ] + compute1 [options] networks insert -r ... [-p ]... [-o ] + compute1 [options] networks list [-p ]... [-o ] + compute1 [options] projects get [-p ]... [-o ] + compute1 [options] projects move-disk -r ... [-p ]... [-o ] + compute1 [options] projects move-instance -r ... [-p ]... [-o ] + compute1 [options] projects set-common-instance-metadata -r ... [-p ]... [-o ] + compute1 [options] projects set-usage-export-bucket -r ... [-p ]... [-o ] + compute1 [options] region-operations delete [-p ]... + compute1 [options] region-operations get [-p ]... [-o ] + compute1 [options] region-operations list [-p ]... [-o ] + compute1 [options] regions get [-p ]... [-o ] + compute1 [options] regions list [-p ]... [-o ] + compute1 [options] routes delete [-p ]... [-o ] + compute1 [options] routes get [-p ]... [-o ] + compute1 [options] routes insert -r ... [-p ]... [-o ] + compute1 [options] routes list [-p ]... [-o ] + compute1 [options] snapshots delete [-p ]... [-o ] + compute1 [options] snapshots get [-p ]... [-o ] + compute1 [options] snapshots list [-p ]... [-o ] + compute1 [options] target-http-proxies delete [-p ]... [-o ] + compute1 [options] target-http-proxies get [-p ]... [-o ] + compute1 [options] target-http-proxies insert -r ... [-p ]... [-o ] + compute1 [options] target-http-proxies list [-p ]... [-o ] + compute1 [options] target-http-proxies set-url-map -r ... [-p ]... [-o ] + compute1 [options] target-instances aggregated-list [-p ]... [-o ] + compute1 [options] target-instances delete [-p ]... [-o ] + compute1 [options] target-instances get [-p ]... [-o ] + compute1 [options] target-instances insert -r ... [-p ]... [-o ] + compute1 [options] target-instances list [-p ]... [-o ] + compute1 [options] target-pools add-health-check -r ... [-p ]... [-o ] + compute1 [options] target-pools add-instance -r ... [-p ]... [-o ] + compute1 [options] target-pools aggregated-list [-p ]... [-o ] + compute1 [options] target-pools delete [-p ]... [-o ] + compute1 [options] target-pools get [-p ]... [-o ] + compute1 [options] target-pools get-health -r ... [-p ]... [-o ] + compute1 [options] target-pools insert -r ... [-p ]... [-o ] + compute1 [options] target-pools list [-p ]... [-o ] + compute1 [options] target-pools remove-health-check -r ... [-p ]... [-o ] + compute1 [options] target-pools remove-instance -r ... [-p ]... [-o ] + compute1 [options] target-pools set-backup -r ... [-p ]... [-o ] + compute1 [options] target-vpn-gateways aggregated-list [-p ]... [-o ] + compute1 [options] target-vpn-gateways delete [-p ]... [-o ] + compute1 [options] target-vpn-gateways get [-p ]... [-o ] + compute1 [options] target-vpn-gateways insert -r ... [-p ]... [-o ] + compute1 [options] target-vpn-gateways list [-p ]... [-o ] + compute1 [options] url-maps delete [-p ]... [-o ] + compute1 [options] url-maps get [-p ]... [-o ] + compute1 [options] url-maps insert -r ... [-p ]... [-o ] + compute1 [options] url-maps list [-p ]... [-o ] + compute1 [options] url-maps patch -r ... [-p ]... [-o ] + compute1 [options] url-maps update -r ... [-p ]... [-o ] + compute1 [options] url-maps validate -r ... [-p ]... [-o ] + compute1 [options] vpn-tunnels aggregated-list [-p ]... [-o ] + compute1 [options] vpn-tunnels delete [-p ]... [-o ] + compute1 [options] vpn-tunnels get [-p ]... [-o ] + compute1 [options] vpn-tunnels insert -r ... [-p ]... [-o ] + compute1 [options] vpn-tunnels list [-p ]... [-o ] + compute1 [options] zone-operations delete [-p ]... + compute1 [options] zone-operations get [-p ]... [-o ] + compute1 [options] zone-operations list [-p ]... [-o ] + compute1 [options] zones get [-p ]... [-o ] + compute1 [options] zones list [-p ]... [-o ] + compute1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Compute>, +} + + +impl Engine { + fn _addresses_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.addresses().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _addresses_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.addresses().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_address); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _addresses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.addresses().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_address); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _addresses_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Address = Default::default(); + let mut call = self.hub.addresses().insert(&request, &self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "users" => { + if request.users.is_none() { + request.users = Some(Default::default()); + } + request.users.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _addresses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.addresses().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.backend_services().delete(&self.opt.arg_project, &self.opt.arg_backend_service); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.backend_services().get(&self.opt.arg_project, &self.opt.arg_backend_service); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_get_health(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ResourceGroupReference = Default::default(); + let mut call = self.hub.backend_services().get_health(&request, &self.opt.arg_project, &self.opt.arg_backend_service); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "group" => { + request.group = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::BackendService = Default::default(); + let mut call = self.hub.backend_services().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "protocol" => { + request.protocol = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "port-name" => { + request.port_name = Some(value.unwrap_or("").to_string()); + }, + "health-checks" => { + if request.health_checks.is_none() { + request.health_checks = Some(Default::default()); + } + request.health_checks.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.backend_services().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::BackendService = Default::default(); + let mut call = self.hub.backend_services().patch(&request, &self.opt.arg_project, &self.opt.arg_backend_service); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "protocol" => { + request.protocol = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "port-name" => { + request.port_name = Some(value.unwrap_or("").to_string()); + }, + "health-checks" => { + if request.health_checks.is_none() { + request.health_checks = Some(Default::default()); + } + request.health_checks.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backend_services_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::BackendService = Default::default(); + let mut call = self.hub.backend_services().update(&request, &self.opt.arg_project, &self.opt.arg_backend_service); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "protocol" => { + request.protocol = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "port-name" => { + request.port_name = Some(value.unwrap_or("").to_string()); + }, + "health-checks" => { + if request.health_checks.is_none() { + request.health_checks = Some(Default::default()); + } + request.health_checks.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disk_types_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disk_types().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disk_types_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disk_types().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_disk_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disk_types_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disk_types().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disks().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_create_snapshot(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Snapshot = Default::default(); + let mut call = self.hub.disks().create_snapshot(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_disk); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "storage-bytes" => { + request.storage_bytes = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "source-disk" => { + request.source_disk = Some(value.unwrap_or("").to_string()); + }, + "storage-bytes-status" => { + request.storage_bytes_status = Some(value.unwrap_or("").to_string()); + }, + "source-disk-id" => { + request.source_disk_id = Some(value.unwrap_or("").to_string()); + }, + "disk-size-gb" => { + request.disk_size_gb = Some(value.unwrap_or("").to_string()); + }, + "licenses" => { + if request.licenses.is_none() { + request.licenses = Some(Default::default()); + } + request.licenses.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disks().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_disk); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disks().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_disk); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Disk = Default::default(); + let mut call = self.hub.disks().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source-image" => { + call = call.source_image(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "source-snapshot" => { + request.source_snapshot = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "size-gb" => { + request.size_gb = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "options" => { + request.options = Some(value.unwrap_or("").to_string()); + }, + "source-image-id" => { + request.source_image_id = Some(value.unwrap_or("").to_string()); + }, + "source-snapshot-id" => { + request.source_snapshot_id = Some(value.unwrap_or("").to_string()); + }, + "source-image" => { + request.source_image = Some(value.unwrap_or("").to_string()); + }, + "licenses" => { + if request.licenses.is_none() { + request.licenses = Some(Default::default()); + } + request.licenses.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "zone" => { + request.zone = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _disks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.disks().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.firewalls().delete(&self.opt.arg_project, &self.opt.arg_firewall); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.firewalls().get(&self.opt.arg_project, &self.opt.arg_firewall); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Firewall = Default::default(); + let mut call = self.hub.firewalls().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "source-tags" => { + if request.source_tags.is_none() { + request.source_tags = Some(Default::default()); + } + request.source_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "source-ranges" => { + if request.source_ranges.is_none() { + request.source_ranges = Some(Default::default()); + } + request.source_ranges.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + "target-tags" => { + if request.target_tags.is_none() { + request.target_tags = Some(Default::default()); + } + request.target_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.firewalls().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Firewall = Default::default(); + let mut call = self.hub.firewalls().patch(&request, &self.opt.arg_project, &self.opt.arg_firewall); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "source-tags" => { + if request.source_tags.is_none() { + request.source_tags = Some(Default::default()); + } + request.source_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "source-ranges" => { + if request.source_ranges.is_none() { + request.source_ranges = Some(Default::default()); + } + request.source_ranges.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + "target-tags" => { + if request.target_tags.is_none() { + request.target_tags = Some(Default::default()); + } + request.target_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _firewalls_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Firewall = Default::default(); + let mut call = self.hub.firewalls().update(&request, &self.opt.arg_project, &self.opt.arg_firewall); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "source-tags" => { + if request.source_tags.is_none() { + request.source_tags = Some(Default::default()); + } + request.source_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "source-ranges" => { + if request.source_ranges.is_none() { + request.source_ranges = Some(Default::default()); + } + request.source_ranges.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + "target-tags" => { + if request.target_tags.is_none() { + request.target_tags = Some(Default::default()); + } + request.target_tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.forwarding_rules().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.forwarding_rules().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.forwarding_rules().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ForwardingRule = Default::default(); + let mut call = self.hub.forwarding_rules().insert(&request, &self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "ip-address" => { + request.ip_address = Some(value.unwrap_or("").to_string()); + }, + "port-range" => { + request.port_range = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "target" => { + request.target = Some(value.unwrap_or("").to_string()); + }, + "ip-protocol" => { + request.ip_protocol = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.forwarding_rules().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _forwarding_rules_set_target(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetReference = Default::default(); + let mut call = self.hub.forwarding_rules().set_target(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target" => { + request.target = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_addresses_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_addresses().delete(&self.opt.arg_project, &self.opt.arg_address); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_addresses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_addresses().get(&self.opt.arg_project, &self.opt.arg_address); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_addresses_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Address = Default::default(); + let mut call = self.hub.global_addresses().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "users" => { + if request.users.is_none() { + request.users = Some(Default::default()); + } + request.users.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_addresses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_addresses().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_forwarding_rules_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_forwarding_rules().delete(&self.opt.arg_project, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_forwarding_rules_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_forwarding_rules().get(&self.opt.arg_project, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_forwarding_rules_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ForwardingRule = Default::default(); + let mut call = self.hub.global_forwarding_rules().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "ip-address" => { + request.ip_address = Some(value.unwrap_or("").to_string()); + }, + "port-range" => { + request.port_range = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "target" => { + request.target = Some(value.unwrap_or("").to_string()); + }, + "ip-protocol" => { + request.ip_protocol = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_forwarding_rules_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_forwarding_rules().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_forwarding_rules_set_target(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetReference = Default::default(); + let mut call = self.hub.global_forwarding_rules().set_target(&request, &self.opt.arg_project, &self.opt.arg_forwarding_rule); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target" => { + request.target = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_operations_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_operations().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_operations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_operations().delete(&self.opt.arg_project, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _global_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_operations().get(&self.opt.arg_project, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _global_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.global_operations().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.http_health_checks().delete(&self.opt.arg_project, &self.opt.arg_http_health_check); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.http_health_checks().get(&self.opt.arg_project, &self.opt.arg_http_health_check); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::HttpHealthCheck = Default::default(); + let mut call = self.hub.http_health_checks().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "check-interval-sec" => { + request.check_interval_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "check-interval-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "unhealthy-threshold" => { + request.unhealthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "unhealthy-threshold", "integer")); + }, + "healthy-threshold" => { + request.healthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "healthy-threshold", "integer")); + }, + "host" => { + request.host = Some(value.unwrap_or("").to_string()); + }, + "request-path" => { + request.request_path = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.http_health_checks().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::HttpHealthCheck = Default::default(); + let mut call = self.hub.http_health_checks().patch(&request, &self.opt.arg_project, &self.opt.arg_http_health_check); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "check-interval-sec" => { + request.check_interval_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "check-interval-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "unhealthy-threshold" => { + request.unhealthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "unhealthy-threshold", "integer")); + }, + "healthy-threshold" => { + request.healthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "healthy-threshold", "integer")); + }, + "host" => { + request.host = Some(value.unwrap_or("").to_string()); + }, + "request-path" => { + request.request_path = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _http_health_checks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::HttpHealthCheck = Default::default(); + let mut call = self.hub.http_health_checks().update(&request, &self.opt.arg_project, &self.opt.arg_http_health_check); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "timeout-sec" => { + request.timeout_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "timeout-sec", "integer")); + }, + "check-interval-sec" => { + request.check_interval_sec = Some(arg_from_str(value.unwrap_or("-0"), err, "check-interval-sec", "integer")); + }, + "port" => { + request.port = Some(arg_from_str(value.unwrap_or("-0"), err, "port", "integer")); + }, + "unhealthy-threshold" => { + request.unhealthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "unhealthy-threshold", "integer")); + }, + "healthy-threshold" => { + request.healthy_threshold = Some(arg_from_str(value.unwrap_or("-0"), err, "healthy-threshold", "integer")); + }, + "host" => { + request.host = Some(value.unwrap_or("").to_string()); + }, + "request-path" => { + request.request_path = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _images_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.images().delete(&self.opt.arg_project, &self.opt.arg_image); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _images_deprecate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::DeprecationStatus = Default::default(); + let mut call = self.hub.images().deprecate(&request, &self.opt.arg_project, &self.opt.arg_image); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "deleted" => { + request.deleted = Some(value.unwrap_or("").to_string()); + }, + "deprecated" => { + request.deprecated = Some(value.unwrap_or("").to_string()); + }, + "state" => { + request.state = Some(value.unwrap_or("").to_string()); + }, + "obsolete" => { + request.obsolete = Some(value.unwrap_or("").to_string()); + }, + "replacement" => { + request.replacement = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _images_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.images().get(&self.opt.arg_project, &self.opt.arg_image); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _images_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Image = Default::default(); + let mut call = self.hub.images().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_deprecated_init(request: &mut api::Image) { + if request.deprecated.is_none() { + request.deprecated = Some(Default::default()); + } + } + + fn request_raw_disk_init(request: &mut api::Image) { + if request.raw_disk.is_none() { + request.raw_disk = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "raw-disk.container-type" => { + request_raw_disk_init(&mut request); + request.raw_disk.as_mut().unwrap().container_type = value.unwrap_or("").to_string(); + }, + "raw-disk.source" => { + request_raw_disk_init(&mut request); + request.raw_disk.as_mut().unwrap().source = value.unwrap_or("").to_string(); + }, + "raw-disk.sha1-checksum" => { + request_raw_disk_init(&mut request); + request.raw_disk.as_mut().unwrap().sha1_checksum = value.unwrap_or("").to_string(); + }, + "deprecated.deleted" => { + request_deprecated_init(&mut request); + request.deprecated.as_mut().unwrap().deleted = Some(value.unwrap_or("").to_string()); + }, + "deprecated.deprecated" => { + request_deprecated_init(&mut request); + request.deprecated.as_mut().unwrap().deprecated = Some(value.unwrap_or("").to_string()); + }, + "deprecated.state" => { + request_deprecated_init(&mut request); + request.deprecated.as_mut().unwrap().state = Some(value.unwrap_or("").to_string()); + }, + "deprecated.obsolete" => { + request_deprecated_init(&mut request); + request.deprecated.as_mut().unwrap().obsolete = Some(value.unwrap_or("").to_string()); + }, + "deprecated.replacement" => { + request_deprecated_init(&mut request); + request.deprecated.as_mut().unwrap().replacement = Some(value.unwrap_or("").to_string()); + }, + "archive-size-bytes" => { + request_deprecated_init(&mut request); + request.archive_size_bytes = Some(value.unwrap_or("").to_string()); + }, + "source-disk-id" => { + request_deprecated_init(&mut request); + request.source_disk_id = Some(value.unwrap_or("").to_string()); + }, + "disk-size-gb" => { + request_deprecated_init(&mut request); + request.disk_size_gb = Some(value.unwrap_or("").to_string()); + }, + "source-disk" => { + request_deprecated_init(&mut request); + request.source_disk = Some(value.unwrap_or("").to_string()); + }, + "licenses" => { + request_deprecated_init(&mut request); + if request.licenses.is_none() { + request.licenses = Some(Default::default()); + } + request.licenses.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "source-type" => { + request_deprecated_init(&mut request); + request.source_type = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request_deprecated_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_deprecated_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_deprecated_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_deprecated_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _images_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.images().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_templates_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instance_templates().delete(&self.opt.arg_project, &self.opt.arg_instance_template); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_templates_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instance_templates().get(&self.opt.arg_project, &self.opt.arg_instance_template); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_templates_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InstanceTemplate = Default::default(); + let mut call = self.hub.instance_templates().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_properties_init(request: &mut api::InstanceTemplate) { + if request.properties.is_none() { + request.properties = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "properties.machine-type" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().machine_type = value.unwrap_or("").to_string(); + }, + "properties.description" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "properties.tags.items" => { + request_properties_init(&mut request); + if request.properties.as_mut().unwrap().tags.items.is_none() { + request.properties.as_mut().unwrap().tags.items = Some(Default::default()); + } + request.properties.as_mut().unwrap().tags.items.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "properties.tags.fingerprint" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().tags.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "properties.scheduling.automatic-restart" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().scheduling.automatic_restart = Some(arg_from_str(value.unwrap_or("false"), err, "properties.scheduling.automatic-restart", "boolean")); + }, + "properties.scheduling.on-host-maintenance" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().scheduling.on_host_maintenance = Some(value.unwrap_or("").to_string()); + }, + "properties.can-ip-forward" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().can_ip_forward = arg_from_str(value.unwrap_or("false"), err, "properties.can-ip-forward", "boolean"); + }, + "properties.metadata.kind" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().metadata.kind = Some(value.unwrap_or("").to_string()); + }, + "properties.metadata.fingerprint" => { + request_properties_init(&mut request); + request.properties.as_mut().unwrap().metadata.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_properties_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_properties_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_templates_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instance_templates().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_add_access_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccessConfig = Default::default(); + let mut call = self.hub.instances().add_access_config(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance, &self.opt.arg_network_interface); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "nat-ip" => { + request.nat_ip = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_attach_disk(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AttachedDisk = Default::default(); + let mut call = self.hub.instances().attach_disk(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_initialize_params_init(request: &mut api::AttachedDisk) { + if request.initialize_params.is_none() { + request.initialize_params = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-name" => { + request.device_name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "initialize-params.disk-size-gb" => { + request_initialize_params_init(&mut request); + request.initialize_params.as_mut().unwrap().disk_size_gb = value.unwrap_or("").to_string(); + }, + "initialize-params.disk-name" => { + request_initialize_params_init(&mut request); + request.initialize_params.as_mut().unwrap().disk_name = value.unwrap_or("").to_string(); + }, + "initialize-params.source-image" => { + request_initialize_params_init(&mut request); + request.initialize_params.as_mut().unwrap().source_image = value.unwrap_or("").to_string(); + }, + "initialize-params.disk-type" => { + request_initialize_params_init(&mut request); + request.initialize_params.as_mut().unwrap().disk_type = value.unwrap_or("").to_string(); + }, + "auto-delete" => { + request_initialize_params_init(&mut request); + request.auto_delete = Some(arg_from_str(value.unwrap_or("false"), err, "auto-delete", "boolean")); + }, + "index" => { + request_initialize_params_init(&mut request); + request.index = Some(arg_from_str(value.unwrap_or("-0"), err, "index", "integer")); + }, + "boot" => { + request_initialize_params_init(&mut request); + request.boot = Some(arg_from_str(value.unwrap_or("false"), err, "boot", "boolean")); + }, + "licenses" => { + request_initialize_params_init(&mut request); + if request.licenses.is_none() { + request.licenses = Some(Default::default()); + } + request.licenses.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "mode" => { + request_initialize_params_init(&mut request); + request.mode = Some(value.unwrap_or("").to_string()); + }, + "interface" => { + request_initialize_params_init(&mut request); + request.interface = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_initialize_params_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "source" => { + request_initialize_params_init(&mut request); + request.source = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_delete_access_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().delete_access_config(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance, &self.opt.arg_access_config, &self.opt.arg_network_interface); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_detach_disk(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().detach_disk(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance, &self.opt.arg_device_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_get_serial_port_output(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().get_serial_port_output(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Instance = Default::default(); + let mut call = self.hub.instances().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_metadata_init(request: &mut api::Instance) { + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + } + + fn request_scheduling_init(request: &mut api::Instance) { + if request.scheduling.is_none() { + request.scheduling = Some(Default::default()); + } + } + + fn request_tags_init(request: &mut api::Instance) { + if request.tags.is_none() { + request.tags = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "cpu-platform" => { + request.cpu_platform = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "can-ip-forward" => { + request.can_ip_forward = Some(arg_from_str(value.unwrap_or("false"), err, "can-ip-forward", "boolean")); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "zone" => { + request.zone = Some(value.unwrap_or("").to_string()); + }, + "tags.items" => { + request_tags_init(&mut request); + if request.tags.as_mut().unwrap().items.is_none() { + request.tags.as_mut().unwrap().items = Some(Default::default()); + } + request.tags.as_mut().unwrap().items.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tags.fingerprint" => { + request_tags_init(&mut request); + request.tags.as_mut().unwrap().fingerprint = Some(value.unwrap_or("").to_string()); + }, + "status-message" => { + request_tags_init(&mut request); + request.status_message = Some(value.unwrap_or("").to_string()); + }, + "scheduling.automatic-restart" => { + request_scheduling_init(&mut request); + request.scheduling.as_mut().unwrap().automatic_restart = Some(arg_from_str(value.unwrap_or("false"), err, "scheduling.automatic-restart", "boolean")); + }, + "scheduling.on-host-maintenance" => { + request_scheduling_init(&mut request); + request.scheduling.as_mut().unwrap().on_host_maintenance = Some(value.unwrap_or("").to_string()); + }, + "machine-type" => { + request_scheduling_init(&mut request); + request.machine_type = Some(value.unwrap_or("").to_string()); + }, + "metadata.kind" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "metadata.fingerprint" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().fingerprint = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request_metadata_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_metadata_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_metadata_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_metadata_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().reset(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_set_disk_auto_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let auto_delete: bool = arg_from_str(&self.opt.arg_auto_delete, err, "", "boolean"); + let mut call = self.hub.instances().set_disk_auto_delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance, auto_delete, &self.opt.arg_device_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_set_metadata(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Metadata = Default::default(); + let mut call = self.hub.instances().set_metadata(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_set_scheduling(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Scheduling = Default::default(); + let mut call = self.hub.instances().set_scheduling(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "automatic-restart" => { + request.automatic_restart = Some(arg_from_str(value.unwrap_or("false"), err, "automatic-restart", "boolean")); + }, + "on-host-maintenance" => { + request.on_host_maintenance = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_set_tags(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Tags = Default::default(); + let mut call = self.hub.instances().set_tags(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "items" => { + if request.items.is_none() { + request.items = Some(Default::default()); + } + request.items.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_start(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().start(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.instances().stop(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _licenses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.licenses().get(&self.opt.arg_project, &self.opt.arg_license); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _machine_types_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.machine_types().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _machine_types_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.machine_types().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_machine_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _machine_types_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.machine_types().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _networks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.networks().delete(&self.opt.arg_project, &self.opt.arg_network); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _networks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.networks().get(&self.opt.arg_project, &self.opt.arg_network); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _networks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Network = Default::default(); + let mut call = self.hub.networks().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "i-pv4-range" => { + request.i_pv4_range = Some(value.unwrap_or("").to_string()); + }, + "gateway-i-pv4" => { + request.gateway_i_pv4 = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _networks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.networks().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().get(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_move_disk(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::DiskMoveRequest = Default::default(); + let mut call = self.hub.projects().move_disk(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target-disk" => { + request.target_disk = Some(value.unwrap_or("").to_string()); + }, + "destination-zone" => { + request.destination_zone = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_move_instance(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InstanceMoveRequest = Default::default(); + let mut call = self.hub.projects().move_instance(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target-instance" => { + request.target_instance = Some(value.unwrap_or("").to_string()); + }, + "destination-zone" => { + request.destination_zone = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_set_common_instance_metadata(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Metadata = Default::default(); + let mut call = self.hub.projects().set_common_instance_metadata(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_set_usage_export_bucket(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UsageExportLocation = Default::default(); + let mut call = self.hub.projects().set_usage_export_bucket(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "bucket-name" => { + request.bucket_name = Some(value.unwrap_or("").to_string()); + }, + "report-name-prefix" => { + request.report_name_prefix = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _region_operations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.region_operations().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _region_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.region_operations().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _region_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.region_operations().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _regions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.regions().get(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _regions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.regions().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _routes_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.routes().delete(&self.opt.arg_project, &self.opt.arg_route); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _routes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.routes().get(&self.opt.arg_project, &self.opt.arg_route); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _routes_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Route = Default::default(); + let mut call = self.hub.routes().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "next-hop-gateway" => { + request.next_hop_gateway = Some(value.unwrap_or("").to_string()); + }, + "priority" => { + request.priority = Some(arg_from_str(value.unwrap_or("-0"), err, "priority", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "tags" => { + if request.tags.is_none() { + request.tags = Some(Default::default()); + } + request.tags.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "next-hop-instance" => { + request.next_hop_instance = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "next-hop-network" => { + request.next_hop_network = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "next-hop-vpn-tunnel" => { + request.next_hop_vpn_tunnel = Some(value.unwrap_or("").to_string()); + }, + "dest-range" => { + request.dest_range = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "next-hop-ip" => { + request.next_hop_ip = Some(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _routes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.routes().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.snapshots().delete(&self.opt.arg_project, &self.opt.arg_snapshot); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.snapshots().get(&self.opt.arg_project, &self.opt.arg_snapshot); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.snapshots().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_http_proxies_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_http_proxies().delete(&self.opt.arg_project, &self.opt.arg_target_http_proxy); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_http_proxies_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_http_proxies().get(&self.opt.arg_project, &self.opt.arg_target_http_proxy); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_http_proxies_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetHttpProxy = Default::default(); + let mut call = self.hub.target_http_proxies().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "url-map" => { + request.url_map = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_http_proxies_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_http_proxies().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_http_proxies_set_url_map(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlMapReference = Default::default(); + let mut call = self.hub.target_http_proxies().set_url_map(&request, &self.opt.arg_project, &self.opt.arg_target_http_proxy); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "url-map" => { + request.url_map = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_instances_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_instances().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_instances_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_instances().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_target_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_instances_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_instances().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_target_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_instances_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetInstance = Default::default(); + let mut call = self.hub.target_instances().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "nat-policy" => { + request.nat_policy = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "zone" => { + request.zone = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_instances_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_instances().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_add_health_check(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetPoolsAddHealthCheckRequest = Default::default(); + let mut call = self.hub.target_pools().add_health_check(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_add_instance(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetPoolsAddInstanceRequest = Default::default(); + let mut call = self.hub.target_pools().add_instance(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_pools().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_pools().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_pools().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_get_health(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InstanceReference = Default::default(); + let mut call = self.hub.target_pools().get_health(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetPool = Default::default(); + let mut call = self.hub.target_pools().insert(&request, &self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "failover-ratio" => { + request.failover_ratio = Some(arg_from_str(value.unwrap_or("0.0"), err, "failover-ratio", "number")); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "session-affinity" => { + request.session_affinity = Some(value.unwrap_or("").to_string()); + }, + "instances" => { + if request.instances.is_none() { + request.instances = Some(Default::default()); + } + request.instances.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "backup-pool" => { + request.backup_pool = Some(value.unwrap_or("").to_string()); + }, + "health-checks" => { + if request.health_checks.is_none() { + request.health_checks = Some(Default::default()); + } + request.health_checks.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_pools().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_remove_health_check(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetPoolsRemoveHealthCheckRequest = Default::default(); + let mut call = self.hub.target_pools().remove_health_check(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_remove_instance(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetPoolsRemoveInstanceRequest = Default::default(); + let mut call = self.hub.target_pools().remove_instance(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_pools_set_backup(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetReference = Default::default(); + let mut call = self.hub.target_pools().set_backup(&request, &self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_pool); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "failover-ratio" => { + call = call.failover_ratio(arg_from_str(value.unwrap_or("0.0"), err, "failover-ratio", "number")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target" => { + request.target = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_vpn_gateways_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_vpn_gateways().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_vpn_gateways_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_vpn_gateways().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_vpn_gateway); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_vpn_gateways_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_vpn_gateways().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_target_vpn_gateway); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_vpn_gateways_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::TargetVpnGateway = Default::default(); + let mut call = self.hub.target_vpn_gateways().insert(&request, &self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "forwarding-rules" => { + if request.forwarding_rules.is_none() { + request.forwarding_rules = Some(Default::default()); + } + request.forwarding_rules.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tunnels" => { + if request.tunnels.is_none() { + request.tunnels = Some(Default::default()); + } + request.tunnels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _target_vpn_gateways_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.target_vpn_gateways().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.url_maps().delete(&self.opt.arg_project, &self.opt.arg_url_map); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.url_maps().get(&self.opt.arg_project, &self.opt.arg_url_map); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlMap = Default::default(); + let mut call = self.hub.url_maps().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "default-service" => { + request.default_service = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.url_maps().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlMap = Default::default(); + let mut call = self.hub.url_maps().patch(&request, &self.opt.arg_project, &self.opt.arg_url_map); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "default-service" => { + request.default_service = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlMap = Default::default(); + let mut call = self.hub.url_maps().update(&request, &self.opt.arg_project, &self.opt.arg_url_map); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "default-service" => { + request.default_service = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_maps_validate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::UrlMapsValidateRequest = Default::default(); + let mut call = self.hub.url_maps().validate(&request, &self.opt.arg_project, &self.opt.arg_url_map); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_resource_init(request: &mut api::UrlMapsValidateRequest) { + if request.resource.is_none() { + request.resource = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "resource.kind" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "resource.description" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().description = Some(value.unwrap_or("").to_string()); + }, + "resource.default-service" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().default_service = Some(value.unwrap_or("").to_string()); + }, + "resource.fingerprint" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().fingerprint = Some(value.unwrap_or("").to_string()); + }, + "resource.creation-timestamp" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "resource.id" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "resource.self-link" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "resource.name" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _vpn_tunnels_aggregated_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.vpn_tunnels().aggregated_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _vpn_tunnels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.vpn_tunnels().delete(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_vpn_tunnel); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _vpn_tunnels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.vpn_tunnels().get(&self.opt.arg_project, &self.opt.arg_region, &self.opt.arg_vpn_tunnel); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _vpn_tunnels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::VpnTunnel = Default::default(); + let mut call = self.hub.vpn_tunnels().insert(&request, &self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "detailed-status" => { + request.detailed_status = Some(value.unwrap_or("").to_string()); + }, + "ike-version" => { + request.ike_version = Some(arg_from_str(value.unwrap_or("-0"), err, "ike-version", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "peer-ip" => { + request.peer_ip = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request.region = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "shared-secret-hash" => { + request.shared_secret_hash = Some(value.unwrap_or("").to_string()); + }, + "target-vpn-gateway" => { + request.target_vpn_gateway = Some(value.unwrap_or("").to_string()); + }, + "shared-secret" => { + request.shared_secret = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "ike-networks" => { + if request.ike_networks.is_none() { + request.ike_networks = Some(Default::default()); + } + request.ike_networks.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _vpn_tunnels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.vpn_tunnels().list(&self.opt.arg_project, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _zone_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zone_operations().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zones_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zones().get(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zones_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.zones().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_addresses { + if self.opt.cmd_aggregated_list { + call_result = self._addresses_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._addresses_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._addresses_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._addresses_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._addresses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_backend_services { + if self.opt.cmd_delete { + call_result = self._backend_services_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._backend_services_get(dry_run, &mut err); + } else if self.opt.cmd_get_health { + call_result = self._backend_services_get_health(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._backend_services_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._backend_services_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._backend_services_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._backend_services_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_disk_types { + if self.opt.cmd_aggregated_list { + call_result = self._disk_types_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._disk_types_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._disk_types_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_disks { + if self.opt.cmd_aggregated_list { + call_result = self._disks_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_create_snapshot { + call_result = self._disks_create_snapshot(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._disks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._disks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._disks_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._disks_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_firewalls { + if self.opt.cmd_delete { + call_result = self._firewalls_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._firewalls_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._firewalls_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._firewalls_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._firewalls_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._firewalls_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_forwarding_rules { + if self.opt.cmd_aggregated_list { + call_result = self._forwarding_rules_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._forwarding_rules_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._forwarding_rules_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._forwarding_rules_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._forwarding_rules_list(dry_run, &mut err); + } else if self.opt.cmd_set_target { + call_result = self._forwarding_rules_set_target(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_global_addresses { + if self.opt.cmd_delete { + call_result = self._global_addresses_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._global_addresses_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._global_addresses_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._global_addresses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_global_forwarding_rules { + if self.opt.cmd_delete { + call_result = self._global_forwarding_rules_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._global_forwarding_rules_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._global_forwarding_rules_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._global_forwarding_rules_list(dry_run, &mut err); + } else if self.opt.cmd_set_target { + call_result = self._global_forwarding_rules_set_target(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_global_operations { + if self.opt.cmd_aggregated_list { + call_result = self._global_operations_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._global_operations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._global_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._global_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_http_health_checks { + if self.opt.cmd_delete { + call_result = self._http_health_checks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._http_health_checks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._http_health_checks_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._http_health_checks_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._http_health_checks_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._http_health_checks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_images { + if self.opt.cmd_delete { + call_result = self._images_delete(dry_run, &mut err); + } else if self.opt.cmd_deprecate { + call_result = self._images_deprecate(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._images_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._images_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._images_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_instance_templates { + if self.opt.cmd_delete { + call_result = self._instance_templates_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._instance_templates_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._instance_templates_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._instance_templates_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_instances { + if self.opt.cmd_add_access_config { + call_result = self._instances_add_access_config(dry_run, &mut err); + } else if self.opt.cmd_aggregated_list { + call_result = self._instances_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_attach_disk { + call_result = self._instances_attach_disk(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._instances_delete(dry_run, &mut err); + } else if self.opt.cmd_delete_access_config { + call_result = self._instances_delete_access_config(dry_run, &mut err); + } else if self.opt.cmd_detach_disk { + call_result = self._instances_detach_disk(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._instances_get(dry_run, &mut err); + } else if self.opt.cmd_get_serial_port_output { + call_result = self._instances_get_serial_port_output(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._instances_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._instances_list(dry_run, &mut err); + } else if self.opt.cmd_reset { + call_result = self._instances_reset(dry_run, &mut err); + } else if self.opt.cmd_set_disk_auto_delete { + call_result = self._instances_set_disk_auto_delete(dry_run, &mut err); + } else if self.opt.cmd_set_metadata { + call_result = self._instances_set_metadata(dry_run, &mut err); + } else if self.opt.cmd_set_scheduling { + call_result = self._instances_set_scheduling(dry_run, &mut err); + } else if self.opt.cmd_set_tags { + call_result = self._instances_set_tags(dry_run, &mut err); + } else if self.opt.cmd_start { + call_result = self._instances_start(dry_run, &mut err); + } else if self.opt.cmd_stop { + call_result = self._instances_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_licenses { + if self.opt.cmd_get { + call_result = self._licenses_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_machine_types { + if self.opt.cmd_aggregated_list { + call_result = self._machine_types_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._machine_types_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._machine_types_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_networks { + if self.opt.cmd_delete { + call_result = self._networks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._networks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._networks_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._networks_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_projects { + if self.opt.cmd_get { + call_result = self._projects_get(dry_run, &mut err); + } else if self.opt.cmd_move_disk { + call_result = self._projects_move_disk(dry_run, &mut err); + } else if self.opt.cmd_move_instance { + call_result = self._projects_move_instance(dry_run, &mut err); + } else if self.opt.cmd_set_common_instance_metadata { + call_result = self._projects_set_common_instance_metadata(dry_run, &mut err); + } else if self.opt.cmd_set_usage_export_bucket { + call_result = self._projects_set_usage_export_bucket(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_region_operations { + if self.opt.cmd_delete { + call_result = self._region_operations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._region_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._region_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_regions { + if self.opt.cmd_get { + call_result = self._regions_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._regions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_routes { + if self.opt.cmd_delete { + call_result = self._routes_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._routes_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._routes_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._routes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_snapshots { + if self.opt.cmd_delete { + call_result = self._snapshots_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._snapshots_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._snapshots_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_target_http_proxies { + if self.opt.cmd_delete { + call_result = self._target_http_proxies_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._target_http_proxies_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._target_http_proxies_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._target_http_proxies_list(dry_run, &mut err); + } else if self.opt.cmd_set_url_map { + call_result = self._target_http_proxies_set_url_map(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_target_instances { + if self.opt.cmd_aggregated_list { + call_result = self._target_instances_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._target_instances_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._target_instances_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._target_instances_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._target_instances_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_target_pools { + if self.opt.cmd_add_health_check { + call_result = self._target_pools_add_health_check(dry_run, &mut err); + } else if self.opt.cmd_add_instance { + call_result = self._target_pools_add_instance(dry_run, &mut err); + } else if self.opt.cmd_aggregated_list { + call_result = self._target_pools_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._target_pools_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._target_pools_get(dry_run, &mut err); + } else if self.opt.cmd_get_health { + call_result = self._target_pools_get_health(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._target_pools_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._target_pools_list(dry_run, &mut err); + } else if self.opt.cmd_remove_health_check { + call_result = self._target_pools_remove_health_check(dry_run, &mut err); + } else if self.opt.cmd_remove_instance { + call_result = self._target_pools_remove_instance(dry_run, &mut err); + } else if self.opt.cmd_set_backup { + call_result = self._target_pools_set_backup(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_target_vpn_gateways { + if self.opt.cmd_aggregated_list { + call_result = self._target_vpn_gateways_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._target_vpn_gateways_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._target_vpn_gateways_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._target_vpn_gateways_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._target_vpn_gateways_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_url_maps { + if self.opt.cmd_delete { + call_result = self._url_maps_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._url_maps_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._url_maps_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._url_maps_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._url_maps_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._url_maps_update(dry_run, &mut err); + } else if self.opt.cmd_validate { + call_result = self._url_maps_validate(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_vpn_tunnels { + if self.opt.cmd_aggregated_list { + call_result = self._vpn_tunnels_aggregated_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._vpn_tunnels_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._vpn_tunnels_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._vpn_tunnels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._vpn_tunnels_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zone_operations { + if self.opt.cmd_delete { + call_result = self._zone_operations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._zone_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zone_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zones { + if self.opt.cmd_get { + call_result = self._zones_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zones_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "compute1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "compute1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Compute::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/container1_beta1-cli/Cargo.toml b/gen/container1_beta1-cli/Cargo.toml new file mode 100644 index 00000000000..71944e38fe2 --- /dev/null +++ b/gen/container1_beta1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-container1_beta1-cli" +version = "0.0.1+20150318" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with container (protocol v1beta1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/container1_beta1-cli" +homepage = "https://cloud.google.com/container-engine/docs/v1beta1/" +documentation = "http://byron.github.io/google-apis-rs/google_container1_beta1_cli" +license = "MIT" +keywords = ["container", "google", "cli"] + +[[bin]] +name = "container1-beta1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-container1_beta1] +path = "../container1_beta1" diff --git a/gen/container1_beta1-cli/LICENSE.md b/gen/container1_beta1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/container1_beta1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/container1_beta1-cli/README.md b/gen/container1_beta1-cli/README.md new file mode 100644 index 00000000000..8b7d47d4a89 --- /dev/null +++ b/gen/container1_beta1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CONTAINER:V1BETA1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/container1_beta1-cli/mkdocs.yml b/gen/container1_beta1-cli/mkdocs.yml new file mode 100644 index 00000000000..6b3b22c8efd --- /dev/null +++ b/gen/container1_beta1-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: container v0.0.1+20150318 +site_url: http://byron.github.io/google-apis-rs/google-container1_beta1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/container1_beta1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['projects_clusters-list.md', 'Projects', 'Clusters List'] +- ['projects_operations-list.md', 'Projects', 'Operations List'] +- ['projects_zones-clusters-create.md', 'Projects', 'Zones Clusters Create'] +- ['projects_zones-clusters-delete.md', 'Projects', 'Zones Clusters Delete'] +- ['projects_zones-clusters-get.md', 'Projects', 'Zones Clusters Get'] +- ['projects_zones-clusters-list.md', 'Projects', 'Zones Clusters List'] +- ['projects_zones-operations-get.md', 'Projects', 'Zones Operations Get'] +- ['projects_zones-operations-list.md', 'Projects', 'Zones Operations List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/container1_beta1-cli/src/cmn.rs b/gen/container1_beta1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/container1_beta1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/container1_beta1-cli/src/main.rs b/gen/container1_beta1-cli/src/main.rs new file mode 100644 index 00000000000..8763a7cd8aa --- /dev/null +++ b/gen/container1_beta1-cli/src/main.rs @@ -0,0 +1,597 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_container1_beta1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + container1-beta1 [options] projects clusters-list [-p ]... [-o ] + container1-beta1 [options] projects operations-list [-p ]... [-o ] + container1-beta1 [options] projects zones-clusters-create -r ... [-p ]... [-o ] + container1-beta1 [options] projects zones-clusters-delete [-p ]... [-o ] + container1-beta1 [options] projects zones-clusters-get [-p ]... [-o ] + container1-beta1 [options] projects zones-clusters-list [-p ]... [-o ] + container1-beta1 [options] projects zones-operations-get [-p ]... [-o ] + container1-beta1 [options] projects zones-operations-list [-p ]... [-o ] + container1-beta1 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::Container>, +} + + +impl Engine { + fn _projects_clusters_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().clusters_list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().operations_list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_clusters_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::CreateClusterRequest = Default::default(); + let mut call = self.hub.projects().zones_clusters_create(&request, &self.opt.arg_project_id, &self.opt.arg_zone_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_cluster_init(request: &mut api::CreateClusterRequest) { + if request.cluster.is_none() { + request.cluster = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "cluster.status" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "cluster.container-ipv4-cidr" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().container_ipv4_cidr = value.unwrap_or("").to_string(); + }, + "cluster.description" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "cluster.zone" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().zone = value.unwrap_or("").to_string(); + }, + "cluster.num-nodes" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().num_nodes = arg_from_str(value.unwrap_or("-0"), err, "cluster.num-nodes", "integer"); + }, + "cluster.node-routing-prefix-size" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().node_routing_prefix_size = arg_from_str(value.unwrap_or("-0"), err, "cluster.node-routing-prefix-size", "integer"); + }, + "cluster.master-auth.password" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().master_auth.password = value.unwrap_or("").to_string(); + }, + "cluster.master-auth.user" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().master_auth.user = value.unwrap_or("").to_string(); + }, + "cluster.cluster-api-version" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().cluster_api_version = value.unwrap_or("").to_string(); + }, + "cluster.network" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().network = value.unwrap_or("").to_string(); + }, + "cluster.endpoint" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().endpoint = value.unwrap_or("").to_string(); + }, + "cluster.node-config.machine-type" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().node_config.machine_type = value.unwrap_or("").to_string(); + }, + "cluster.node-config.source-image" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().node_config.source_image = value.unwrap_or("").to_string(); + }, + "cluster.status-message" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().status_message = value.unwrap_or("").to_string(); + }, + "cluster.services-ipv4-cidr" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().services_ipv4_cidr = value.unwrap_or("").to_string(); + }, + "cluster.creation-timestamp" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().creation_timestamp = value.unwrap_or("").to_string(); + }, + "cluster.enable-cloud-logging" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().enable_cloud_logging = arg_from_str(value.unwrap_or("false"), err, "cluster.enable-cloud-logging", "boolean"); + }, + "cluster.self-link" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "cluster.name" => { + request_cluster_init(&mut request); + request.cluster.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_clusters_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().zones_clusters_delete(&self.opt.arg_project_id, &self.opt.arg_zone_id, &self.opt.arg_cluster_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_clusters_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().zones_clusters_get(&self.opt.arg_project_id, &self.opt.arg_zone_id, &self.opt.arg_cluster_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_clusters_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().zones_clusters_list(&self.opt.arg_project_id, &self.opt.arg_zone_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().zones_operations_get(&self.opt.arg_project_id, &self.opt.arg_zone_id, &self.opt.arg_operation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_zones_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.projects().zones_operations_list(&self.opt.arg_project_id, &self.opt.arg_zone_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_projects { + if self.opt.cmd_clusters_list { + call_result = self._projects_clusters_list(dry_run, &mut err); + } else if self.opt.cmd_operations_list { + call_result = self._projects_operations_list(dry_run, &mut err); + } else if self.opt.cmd_zones_clusters_create { + call_result = self._projects_zones_clusters_create(dry_run, &mut err); + } else if self.opt.cmd_zones_clusters_delete { + call_result = self._projects_zones_clusters_delete(dry_run, &mut err); + } else if self.opt.cmd_zones_clusters_get { + call_result = self._projects_zones_clusters_get(dry_run, &mut err); + } else if self.opt.cmd_zones_clusters_list { + call_result = self._projects_zones_clusters_list(dry_run, &mut err); + } else if self.opt.cmd_zones_operations_get { + call_result = self._projects_zones_operations_get(dry_run, &mut err); + } else if self.opt.cmd_zones_operations_list { + call_result = self._projects_zones_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "container1-beta1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "container1-beta1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Container::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/content2-cli/Cargo.toml b/gen/content2-cli/Cargo.toml new file mode 100644 index 00000000000..f0a707f73ae --- /dev/null +++ b/gen/content2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-content2-cli" +version = "0.0.1+20150317" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Shopping Content (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/content2-cli" +homepage = "https://developers.google.com/shopping-content/v2/" +documentation = "http://byron.github.io/google-apis-rs/google_content2_cli" +license = "MIT" +keywords = ["content", "google", "cli"] + +[[bin]] +name = "content2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-content2] +path = "../content2" diff --git a/gen/content2-cli/LICENSE.md b/gen/content2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/content2-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/content2-cli/README.md b/gen/content2-cli/README.md new file mode 100644 index 00000000000..5538bc18d24 --- /dev/null +++ b/gen/content2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CONTENT:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/content2-cli/mkdocs.yml b/gen/content2-cli/mkdocs.yml new file mode 100644 index 00000000000..46b020ce04d --- /dev/null +++ b/gen/content2-cli/mkdocs.yml @@ -0,0 +1,57 @@ +site_name: Shopping Content v0.0.1+20150317 +site_url: http://byron.github.io/google-apis-rs/google-content2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/content2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_authinfo.md', 'Accounts', 'Authinfo'] +- ['accounts_custombatch.md', 'Accounts', 'Custombatch'] +- ['accounts_delete.md', 'Accounts', 'Delete'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_insert.md', 'Accounts', 'Insert'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_patch.md', 'Accounts', 'Patch'] +- ['accounts_update.md', 'Accounts', 'Update'] +- ['accountshipping_custombatch.md', 'Accountshipping', 'Custombatch'] +- ['accountshipping_get.md', 'Accountshipping', 'Get'] +- ['accountshipping_list.md', 'Accountshipping', 'List'] +- ['accountshipping_patch.md', 'Accountshipping', 'Patch'] +- ['accountshipping_update.md', 'Accountshipping', 'Update'] +- ['accountstatuses_custombatch.md', 'Accountstatuses', 'Custombatch'] +- ['accountstatuses_get.md', 'Accountstatuses', 'Get'] +- ['accountstatuses_list.md', 'Accountstatuses', 'List'] +- ['accounttax_custombatch.md', 'Accounttax', 'Custombatch'] +- ['accounttax_get.md', 'Accounttax', 'Get'] +- ['accounttax_list.md', 'Accounttax', 'List'] +- ['accounttax_patch.md', 'Accounttax', 'Patch'] +- ['accounttax_update.md', 'Accounttax', 'Update'] +- ['datafeeds_custombatch.md', 'Datafeeds', 'Custombatch'] +- ['datafeeds_delete.md', 'Datafeeds', 'Delete'] +- ['datafeeds_get.md', 'Datafeeds', 'Get'] +- ['datafeeds_insert.md', 'Datafeeds', 'Insert'] +- ['datafeeds_list.md', 'Datafeeds', 'List'] +- ['datafeeds_patch.md', 'Datafeeds', 'Patch'] +- ['datafeeds_update.md', 'Datafeeds', 'Update'] +- ['datafeedstatuses_custombatch.md', 'Datafeedstatuses', 'Custombatch'] +- ['datafeedstatuses_get.md', 'Datafeedstatuses', 'Get'] +- ['datafeedstatuses_list.md', 'Datafeedstatuses', 'List'] +- ['inventory_custombatch.md', 'Inventory', 'Custombatch'] +- ['inventory_set.md', 'Inventory', 'Set'] +- ['products_custombatch.md', 'Products', 'Custombatch'] +- ['products_delete.md', 'Products', 'Delete'] +- ['products_get.md', 'Products', 'Get'] +- ['products_insert.md', 'Products', 'Insert'] +- ['products_list.md', 'Products', 'List'] +- ['productstatuses_custombatch.md', 'Productstatuses', 'Custombatch'] +- ['productstatuses_get.md', 'Productstatuses', 'Get'] +- ['productstatuses_list.md', 'Productstatuses', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/content2-cli/src/cmn.rs b/gen/content2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/content2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/content2-cli/src/main.rs b/gen/content2-cli/src/main.rs new file mode 100644 index 00000000000..040ad3a7041 --- /dev/null +++ b/gen/content2-cli/src/main.rs @@ -0,0 +1,3148 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_content2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + content2 [options] accounts authinfo [-p ]... [-o ] + content2 [options] accounts custombatch -r ... [-p ]... [-o ] + content2 [options] accounts delete [-p ]... + content2 [options] accounts get [-p ]... [-o ] + content2 [options] accounts insert -r ... [-p ]... [-o ] + content2 [options] accounts list [-p ]... [-o ] + content2 [options] accounts patch -r ... [-p ]... [-o ] + content2 [options] accounts update -r ... [-p ]... [-o ] + content2 [options] accountshipping custombatch -r ... [-p ]... [-o ] + content2 [options] accountshipping get [-p ]... [-o ] + content2 [options] accountshipping list [-p ]... [-o ] + content2 [options] accountshipping patch -r ... [-p ]... [-o ] + content2 [options] accountshipping update -r ... [-p ]... [-o ] + content2 [options] accountstatuses custombatch -r ... [-p ]... [-o ] + content2 [options] accountstatuses get [-p ]... [-o ] + content2 [options] accountstatuses list [-p ]... [-o ] + content2 [options] accounttax custombatch -r ... [-p ]... [-o ] + content2 [options] accounttax get [-p ]... [-o ] + content2 [options] accounttax list [-p ]... [-o ] + content2 [options] accounttax patch -r ... [-p ]... [-o ] + content2 [options] accounttax update -r ... [-p ]... [-o ] + content2 [options] datafeeds custombatch -r ... [-p ]... [-o ] + content2 [options] datafeeds delete [-p ]... + content2 [options] datafeeds get [-p ]... [-o ] + content2 [options] datafeeds insert -r ... [-p ]... [-o ] + content2 [options] datafeeds list [-p ]... [-o ] + content2 [options] datafeeds patch -r ... [-p ]... [-o ] + content2 [options] datafeeds update -r ... [-p ]... [-o ] + content2 [options] datafeedstatuses custombatch -r ... [-p ]... [-o ] + content2 [options] datafeedstatuses get [-p ]... [-o ] + content2 [options] datafeedstatuses list [-p ]... [-o ] + content2 [options] inventory custombatch -r ... [-p ]... [-o ] + content2 [options] inventory set -r ... [-p ]... [-o ] + content2 [options] products custombatch -r ... [-p ]... [-o ] + content2 [options] products delete [-p ]... + content2 [options] products get [-p ]... [-o ] + content2 [options] products insert -r ... [-p ]... [-o ] + content2 [options] products list [-p ]... [-o ] + content2 [options] productstatuses custombatch -r ... [-p ]... [-o ] + content2 [options] productstatuses get [-p ]... [-o ] + content2 [options] productstatuses list [-p ]... [-o ] + content2 --help + +All documentation details can be found TODO: + +Configuration: + --scope + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --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] +"); + +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::ShoppingContent>, +} + + +impl Engine { + fn _accounts_authinfo(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().authinfo(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountsCustomBatchRequest = Default::default(); + let mut call = self.hub.accounts().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().delete(&self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().get(&self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().insert(&request, &self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "reviews-url" => { + request.reviews_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "adult-content" => { + request.adult_content = Some(arg_from_str(value.unwrap_or("false"), err, "adult-content", "boolean")); + }, + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "seller-id" => { + request.seller_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounts().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().patch(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "reviews-url" => { + request.reviews_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "adult-content" => { + request.adult_content = Some(arg_from_str(value.unwrap_or("false"), err, "adult-content", "boolean")); + }, + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "seller-id" => { + request.seller_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().update(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "reviews-url" => { + request.reviews_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "adult-content" => { + request.adult_content = Some(arg_from_str(value.unwrap_or("false"), err, "adult-content", "boolean")); + }, + "website-url" => { + request.website_url = Some(value.unwrap_or("").to_string()); + }, + "seller-id" => { + request.seller_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountshipping_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountshippingCustomBatchRequest = Default::default(); + let mut call = self.hub.accountshipping().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountshipping_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accountshipping().get(&self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountshipping_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accountshipping().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountshipping_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountShipping = Default::default(); + let mut call = self.hub.accountshipping().patch(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountshipping_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountShipping = Default::default(); + let mut call = self.hub.accountshipping().update(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountstatuses_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountstatusesCustomBatchRequest = Default::default(); + let mut call = self.hub.accountstatuses().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountstatuses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accountstatuses().get(&self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accountstatuses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accountstatuses().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounttax_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccounttaxCustomBatchRequest = Default::default(); + let mut call = self.hub.accounttax().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounttax_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounttax().get(&self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounttax_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.accounttax().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounttax_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountTax = Default::default(); + let mut call = self.hub.accounttax().patch(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounttax_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::AccountTax = Default::default(); + let mut call = self.hub.accounttax().update(&request, &self.opt.arg_merchant_id, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::DatafeedsCustomBatchRequest = Default::default(); + let mut call = self.hub.datafeeds().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datafeeds().delete(&self.opt.arg_merchant_id, &self.opt.arg_datafeed_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _datafeeds_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datafeeds().get(&self.opt.arg_merchant_id, &self.opt.arg_datafeed_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Datafeed = Default::default(); + let mut call = self.hub.datafeeds().insert(&request, &self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_fetch_schedule_init(request: &mut api::Datafeed) { + if request.fetch_schedule.is_none() { + request.fetch_schedule = Some(Default::default()); + } + } + + fn request_format_init(request: &mut api::Datafeed) { + if request.format.is_none() { + request.format = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "format.file-encoding" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().file_encoding = value.unwrap_or("").to_string(); + }, + "format.quoting-mode" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().quoting_mode = value.unwrap_or("").to_string(); + }, + "format.column-delimiter" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().column_delimiter = value.unwrap_or("").to_string(); + }, + "fetch-schedule.username" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().username = value.unwrap_or("").to_string(); + }, + "fetch-schedule.hour" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().hour = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.hour", "integer"); + }, + "fetch-schedule.fetch-url" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().fetch_url = value.unwrap_or("").to_string(); + }, + "fetch-schedule.weekday" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().weekday = value.unwrap_or("").to_string(); + }, + "fetch-schedule.time-zone" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "fetch-schedule.password" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().password = value.unwrap_or("").to_string(); + }, + "fetch-schedule.day-of-month" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().day_of_month = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.day-of-month", "integer"); + }, + "target-country" => { + request_fetch_schedule_init(&mut request); + request.target_country = Some(arg_from_str(value.unwrap_or("-0"), err, "target-country", "int64")); + }, + "file-name" => { + request_fetch_schedule_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "intended-destinations" => { + request_fetch_schedule_init(&mut request); + if request.intended_destinations.is_none() { + request.intended_destinations = Some(Default::default()); + } + request.intended_destinations.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_fetch_schedule_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "attribute-language" => { + request_fetch_schedule_init(&mut request); + request.attribute_language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datafeeds().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Datafeed = Default::default(); + let mut call = self.hub.datafeeds().patch(&request, &self.opt.arg_merchant_id, &self.opt.arg_datafeed_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_fetch_schedule_init(request: &mut api::Datafeed) { + if request.fetch_schedule.is_none() { + request.fetch_schedule = Some(Default::default()); + } + } + + fn request_format_init(request: &mut api::Datafeed) { + if request.format.is_none() { + request.format = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "format.file-encoding" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().file_encoding = value.unwrap_or("").to_string(); + }, + "format.quoting-mode" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().quoting_mode = value.unwrap_or("").to_string(); + }, + "format.column-delimiter" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().column_delimiter = value.unwrap_or("").to_string(); + }, + "fetch-schedule.username" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().username = value.unwrap_or("").to_string(); + }, + "fetch-schedule.hour" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().hour = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.hour", "integer"); + }, + "fetch-schedule.fetch-url" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().fetch_url = value.unwrap_or("").to_string(); + }, + "fetch-schedule.weekday" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().weekday = value.unwrap_or("").to_string(); + }, + "fetch-schedule.time-zone" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "fetch-schedule.password" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().password = value.unwrap_or("").to_string(); + }, + "fetch-schedule.day-of-month" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().day_of_month = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.day-of-month", "integer"); + }, + "target-country" => { + request_fetch_schedule_init(&mut request); + request.target_country = Some(arg_from_str(value.unwrap_or("-0"), err, "target-country", "int64")); + }, + "file-name" => { + request_fetch_schedule_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "intended-destinations" => { + request_fetch_schedule_init(&mut request); + if request.intended_destinations.is_none() { + request.intended_destinations = Some(Default::default()); + } + request.intended_destinations.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_fetch_schedule_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "attribute-language" => { + request_fetch_schedule_init(&mut request); + request.attribute_language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeeds_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Datafeed = Default::default(); + let mut call = self.hub.datafeeds().update(&request, &self.opt.arg_merchant_id, &self.opt.arg_datafeed_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_fetch_schedule_init(request: &mut api::Datafeed) { + if request.fetch_schedule.is_none() { + request.fetch_schedule = Some(Default::default()); + } + } + + fn request_format_init(request: &mut api::Datafeed) { + if request.format.is_none() { + request.format = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "format.file-encoding" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().file_encoding = value.unwrap_or("").to_string(); + }, + "format.quoting-mode" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().quoting_mode = value.unwrap_or("").to_string(); + }, + "format.column-delimiter" => { + request_format_init(&mut request); + request.format.as_mut().unwrap().column_delimiter = value.unwrap_or("").to_string(); + }, + "fetch-schedule.username" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().username = value.unwrap_or("").to_string(); + }, + "fetch-schedule.hour" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().hour = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.hour", "integer"); + }, + "fetch-schedule.fetch-url" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().fetch_url = value.unwrap_or("").to_string(); + }, + "fetch-schedule.weekday" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().weekday = value.unwrap_or("").to_string(); + }, + "fetch-schedule.time-zone" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().time_zone = value.unwrap_or("").to_string(); + }, + "fetch-schedule.password" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().password = value.unwrap_or("").to_string(); + }, + "fetch-schedule.day-of-month" => { + request_fetch_schedule_init(&mut request); + request.fetch_schedule.as_mut().unwrap().day_of_month = arg_from_str(value.unwrap_or("-0"), err, "fetch-schedule.day-of-month", "integer"); + }, + "target-country" => { + request_fetch_schedule_init(&mut request); + request.target_country = Some(arg_from_str(value.unwrap_or("-0"), err, "target-country", "int64")); + }, + "file-name" => { + request_fetch_schedule_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "intended-destinations" => { + request_fetch_schedule_init(&mut request); + if request.intended_destinations.is_none() { + request.intended_destinations = Some(Default::default()); + } + request.intended_destinations.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_fetch_schedule_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "attribute-language" => { + request_fetch_schedule_init(&mut request); + request.attribute_language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeedstatuses_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::DatafeedstatusesCustomBatchRequest = Default::default(); + let mut call = self.hub.datafeedstatuses().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeedstatuses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datafeedstatuses().get(&self.opt.arg_merchant_id, &self.opt.arg_datafeed_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datafeedstatuses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.datafeedstatuses().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inventory_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InventoryCustomBatchRequest = Default::default(); + let mut call = self.hub.inventory().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _inventory_set(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::InventorySetRequest = Default::default(); + let mut call = self.hub.inventory().set(&request, &self.opt.arg_merchant_id, &self.opt.arg_store_code, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_price_init(request: &mut api::InventorySetRequest) { + if request.price.is_none() { + request.price = Some(Default::default()); + } + } + + fn request_sale_price_init(request: &mut api::InventorySetRequest) { + if request.sale_price.is_none() { + request.sale_price = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "sale-price-effective-date" => { + request.sale_price_effective_date = Some(value.unwrap_or("").to_string()); + }, + "price.currency" => { + request_price_init(&mut request); + request.price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "price.value" => { + request_price_init(&mut request); + request.price.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "sale-price.currency" => { + request_sale_price_init(&mut request); + request.sale_price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "sale-price.value" => { + request_sale_price_init(&mut request); + request.sale_price.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "availability" => { + request_sale_price_init(&mut request); + request.availability = Some(value.unwrap_or("").to_string()); + }, + "quantity" => { + request_sale_price_init(&mut request); + request.quantity = Some(arg_from_str(value.unwrap_or("-0"), err, "quantity", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProductsCustomBatchRequest = Default::default(); + let mut call = self.hub.products().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "dry-run" => { + call = call.dry_run(arg_from_str(value.unwrap_or("false"), err, "dry-run", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().delete(&self.opt.arg_merchant_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "dry-run" => { + call = call.dry_run(arg_from_str(value.unwrap_or("false"), err, "dry-run", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _products_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().get(&self.opt.arg_merchant_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::Product = Default::default(); + let mut call = self.hub.products().insert(&request, &self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "dry-run" => { + call = call.dry_run(arg_from_str(value.unwrap_or("false"), err, "dry-run", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_installment_init(request: &mut api::Product) { + if request.installment.is_none() { + request.installment = Some(Default::default()); + } + } + + fn request_loyalty_points_init(request: &mut api::Product) { + if request.loyalty_points.is_none() { + request.loyalty_points = Some(Default::default()); + } + } + + fn request_price_init(request: &mut api::Product) { + if request.price.is_none() { + request.price = Some(Default::default()); + } + } + + fn request_sale_price_init(request: &mut api::Product) { + if request.sale_price.is_none() { + request.sale_price = Some(Default::default()); + } + } + + fn request_shipping_height_init(request: &mut api::Product) { + if request.shipping_height.is_none() { + request.shipping_height = Some(Default::default()); + } + } + + fn request_shipping_length_init(request: &mut api::Product) { + if request.shipping_length.is_none() { + request.shipping_length = Some(Default::default()); + } + } + + fn request_shipping_weight_init(request: &mut api::Product) { + if request.shipping_weight.is_none() { + request.shipping_weight = Some(Default::default()); + } + } + + fn request_shipping_width_init(request: &mut api::Product) { + if request.shipping_width.is_none() { + request.shipping_width = Some(Default::default()); + } + } + + fn request_unit_pricing_base_measure_init(request: &mut api::Product) { + if request.unit_pricing_base_measure.is_none() { + request.unit_pricing_base_measure = Some(Default::default()); + } + } + + fn request_unit_pricing_measure_init(request: &mut api::Product) { + if request.unit_pricing_measure.is_none() { + request.unit_pricing_measure = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "display-ads-title" => { + request.display_ads_title = Some(value.unwrap_or("").to_string()); + }, + "color" => { + request.color = Some(value.unwrap_or("").to_string()); + }, + "additional-image-links" => { + if request.additional_image_links.is_none() { + request.additional_image_links = Some(Default::default()); + } + request.additional_image_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "adwords-labels" => { + if request.adwords_labels.is_none() { + request.adwords_labels = Some(Default::default()); + } + request.adwords_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "item-group-id" => { + request.item_group_id = Some(value.unwrap_or("").to_string()); + }, + "gtin" => { + request.gtin = Some(value.unwrap_or("").to_string()); + }, + "expiration-date" => { + request.expiration_date = Some(value.unwrap_or("").to_string()); + }, + "google-product-category" => { + request.google_product_category = Some(value.unwrap_or("").to_string()); + }, + "multipack" => { + request.multipack = Some(value.unwrap_or("").to_string()); + }, + "display-ads-id" => { + request.display_ads_id = Some(value.unwrap_or("").to_string()); + }, + "display-ads-value" => { + request.display_ads_value = Some(arg_from_str(value.unwrap_or("0.0"), err, "display-ads-value", "number")); + }, + "availability" => { + request.availability = Some(value.unwrap_or("").to_string()); + }, + "adwords-grouping" => { + request.adwords_grouping = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "target-country" => { + request.target_country = Some(arg_from_str(value.unwrap_or("-0"), err, "target-country", "int64")); + }, + "size-type" => { + request.size_type = Some(value.unwrap_or("").to_string()); + }, + "offer-id" => { + request.offer_id = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "pattern" => { + request.pattern = Some(value.unwrap_or("").to_string()); + }, + "unit-pricing-measure.value" => { + request_unit_pricing_measure_init(&mut request); + request.unit_pricing_measure.as_mut().unwrap().value = arg_from_str(value.unwrap_or("0.0"), err, "unit-pricing-measure.value", "number"); + }, + "unit-pricing-measure.unit" => { + request_unit_pricing_measure_init(&mut request); + request.unit_pricing_measure.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "validated-destinations" => { + request_unit_pricing_measure_init(&mut request); + if request.validated_destinations.is_none() { + request.validated_destinations = Some(Default::default()); + } + request.validated_destinations.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_unit_pricing_measure_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "online-only" => { + request_unit_pricing_measure_init(&mut request); + request.online_only = Some(arg_from_str(value.unwrap_or("false"), err, "online-only", "boolean")); + }, + "is-bundle" => { + request_unit_pricing_measure_init(&mut request); + request.is_bundle = Some(arg_from_str(value.unwrap_or("false"), err, "is-bundle", "boolean")); + }, + "mobile-link" => { + request_unit_pricing_measure_init(&mut request); + request.mobile_link = Some(value.unwrap_or("").to_string()); + }, + "price.currency" => { + request_price_init(&mut request); + request.price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "price.value" => { + request_price_init(&mut request); + request.price.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "channel" => { + request_price_init(&mut request); + request.channel = Some(value.unwrap_or("").to_string()); + }, + "loyalty-points.ratio" => { + request_loyalty_points_init(&mut request); + request.loyalty_points.as_mut().unwrap().ratio = arg_from_str(value.unwrap_or("0.0"), err, "loyalty-points.ratio", "number"); + }, + "loyalty-points.name" => { + request_loyalty_points_init(&mut request); + request.loyalty_points.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "loyalty-points.points-value" => { + request_loyalty_points_init(&mut request); + request.loyalty_points.as_mut().unwrap().points_value = value.unwrap_or("").to_string(); + }, + "shipping-height.value" => { + request_shipping_height_init(&mut request); + request.shipping_height.as_mut().unwrap().value = arg_from_str(value.unwrap_or("0.0"), err, "shipping-height.value", "number"); + }, + "shipping-height.unit" => { + request_shipping_height_init(&mut request); + request.shipping_height.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "content-language" => { + request_shipping_height_init(&mut request); + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "mpn" => { + request_shipping_height_init(&mut request); + request.mpn = Some(value.unwrap_or("").to_string()); + }, + "sale-price-effective-date" => { + request_shipping_height_init(&mut request); + request.sale_price_effective_date = Some(value.unwrap_or("").to_string()); + }, + "brand" => { + request_shipping_height_init(&mut request); + request.brand = Some(value.unwrap_or("").to_string()); + }, + "material" => { + request_shipping_height_init(&mut request); + request.material = Some(value.unwrap_or("").to_string()); + }, + "availability-date" => { + request_shipping_height_init(&mut request); + request.availability_date = Some(value.unwrap_or("").to_string()); + }, + "shipping-length.value" => { + request_shipping_length_init(&mut request); + request.shipping_length.as_mut().unwrap().value = arg_from_str(value.unwrap_or("0.0"), err, "shipping-length.value", "number"); + }, + "shipping-length.unit" => { + request_shipping_length_init(&mut request); + request.shipping_length.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "link" => { + request_shipping_length_init(&mut request); + request.link = Some(value.unwrap_or("").to_string()); + }, + "adult" => { + request_shipping_length_init(&mut request); + request.adult = Some(arg_from_str(value.unwrap_or("false"), err, "adult", "boolean")); + }, + "display-ads-link" => { + request_shipping_length_init(&mut request); + request.display_ads_link = Some(value.unwrap_or("").to_string()); + }, + "energy-efficiency-class" => { + request_shipping_length_init(&mut request); + request.energy_efficiency_class = Some(value.unwrap_or("").to_string()); + }, + "size-system" => { + request_shipping_length_init(&mut request); + request.size_system = Some(value.unwrap_or("").to_string()); + }, + "custom-label4" => { + request_shipping_length_init(&mut request); + request.custom_label4 = Some(value.unwrap_or("").to_string()); + }, + "custom-label3" => { + request_shipping_length_init(&mut request); + request.custom_label3 = Some(value.unwrap_or("").to_string()); + }, + "custom-label2" => { + request_shipping_length_init(&mut request); + request.custom_label2 = Some(value.unwrap_or("").to_string()); + }, + "condition" => { + request_shipping_length_init(&mut request); + request.condition = Some(value.unwrap_or("").to_string()); + }, + "custom-label0" => { + request_shipping_length_init(&mut request); + request.custom_label0 = Some(value.unwrap_or("").to_string()); + }, + "shipping-label" => { + request_shipping_length_init(&mut request); + request.shipping_label = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_shipping_length_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "unit-pricing-base-measure.value" => { + request_unit_pricing_base_measure_init(&mut request); + request.unit_pricing_base_measure.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "unit-pricing-base-measure.unit" => { + request_unit_pricing_base_measure_init(&mut request); + request.unit_pricing_base_measure.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "installment.amount.currency" => { + request_installment_init(&mut request); + request.installment.as_mut().unwrap().amount.currency = value.unwrap_or("").to_string(); + }, + "installment.amount.value" => { + request_installment_init(&mut request); + request.installment.as_mut().unwrap().amount.value = value.unwrap_or("").to_string(); + }, + "installment.months" => { + request_installment_init(&mut request); + request.installment.as_mut().unwrap().months = value.unwrap_or("").to_string(); + }, + "sizes" => { + request_installment_init(&mut request); + if request.sizes.is_none() { + request.sizes = Some(Default::default()); + } + request.sizes.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "gender" => { + request_installment_init(&mut request); + request.gender = Some(value.unwrap_or("").to_string()); + }, + "shipping-width.value" => { + request_shipping_width_init(&mut request); + request.shipping_width.as_mut().unwrap().value = arg_from_str(value.unwrap_or("0.0"), err, "shipping-width.value", "number"); + }, + "shipping-width.unit" => { + request_shipping_width_init(&mut request); + request.shipping_width.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "shipping-weight.value" => { + request_shipping_weight_init(&mut request); + request.shipping_weight.as_mut().unwrap().value = arg_from_str(value.unwrap_or("0.0"), err, "shipping-weight.value", "number"); + }, + "shipping-weight.unit" => { + request_shipping_weight_init(&mut request); + request.shipping_weight.as_mut().unwrap().unit = value.unwrap_or("").to_string(); + }, + "identifier-exists" => { + request_shipping_weight_init(&mut request); + request.identifier_exists = Some(arg_from_str(value.unwrap_or("false"), err, "identifier-exists", "boolean")); + }, + "image-link" => { + request_shipping_weight_init(&mut request); + request.image_link = Some(value.unwrap_or("").to_string()); + }, + "sale-price.currency" => { + request_sale_price_init(&mut request); + request.sale_price.as_mut().unwrap().currency = value.unwrap_or("").to_string(); + }, + "sale-price.value" => { + request_sale_price_init(&mut request); + request.sale_price.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "product-type" => { + request_sale_price_init(&mut request); + request.product_type = Some(value.unwrap_or("").to_string()); + }, + "display-ads-similar-ids" => { + request_sale_price_init(&mut request); + if request.display_ads_similar_ids.is_none() { + request.display_ads_similar_ids = Some(Default::default()); + } + request.display_ads_similar_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "custom-label1" => { + request_sale_price_init(&mut request); + request.custom_label1 = Some(value.unwrap_or("").to_string()); + }, + "age-group" => { + request_sale_price_init(&mut request); + request.age_group = Some(value.unwrap_or("").to_string()); + }, + "adwords-redirect" => { + request_sale_price_init(&mut request); + request.adwords_redirect = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _products_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.products().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _productstatuses_custombatch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut request: api::ProductstatusesCustomBatchRequest = Default::default(); + let mut call = self.hub.productstatuses().custombatch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _productstatuses_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.productstatuses().get(&self.opt.arg_merchant_id, &self.opt.arg_product_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _productstatuses_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option { + let mut call = self.hub.productstatuses().list(&self.opt.arg_merchant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option, Option) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option; + let mut err_opt: Option = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_authinfo { + call_result = self._accounts_authinfo(dry_run, &mut err); + } else if self.opt.cmd_custombatch { + call_result = self._accounts_custombatch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._accounts_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._accounts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._accounts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_accountshipping { + if self.opt.cmd_custombatch { + call_result = self._accountshipping_custombatch(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accountshipping_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accountshipping_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._accountshipping_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accountshipping_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_accountstatuses { + if self.opt.cmd_custombatch { + call_result = self._accountstatuses_custombatch(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accountstatuses_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accountstatuses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_accounttax { + if self.opt.cmd_custombatch { + call_result = self._accounttax_custombatch(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounttax_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounttax_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._accounttax_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounttax_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_datafeeds { + if self.opt.cmd_custombatch { + call_result = self._datafeeds_custombatch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._datafeeds_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._datafeeds_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._datafeeds_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._datafeeds_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._datafeeds_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._datafeeds_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_datafeedstatuses { + if self.opt.cmd_custombatch { + call_result = self._datafeedstatuses_custombatch(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._datafeedstatuses_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._datafeedstatuses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_inventory { + if self.opt.cmd_custombatch { + call_result = self._inventory_custombatch(dry_run, &mut err); + } else if self.opt.cmd_set { + call_result = self._inventory_set(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_products { + if self.opt.cmd_custombatch { + call_result = self._products_custombatch(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._products_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._products_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._products_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._products_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_productstatuses { + if self.opt.cmd_custombatch { + call_result = self._productstatuses_custombatch(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._productstatuses_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._productstatuses_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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, "content2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "content2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::ShoppingContent::new(hyper::Client::new(), 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()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/coordinate1-cli/Cargo.toml b/gen/coordinate1-cli/Cargo.toml new file mode 100644 index 00000000000..d9f994f9512 --- /dev/null +++ b/gen/coordinate1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-coordinate1-cli" +version = "0.0.1+20141215" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with coordinate (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/coordinate1-cli" +homepage = "https://developers.google.com/coordinate/" +documentation = "http://byron.github.io/google-apis-rs/google_coordinate1_cli" +license = "MIT" +keywords = ["coordinate", "google", "cli"] + +[[bin]] +name = "coordinate1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-coordinate1] +path = "../coordinate1" diff --git a/gen/coordinate1-cli/LICENSE.md b/gen/coordinate1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/coordinate1-cli/LICENSE.md @@ -0,0 +1,30 @@ + +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. diff --git a/gen/coordinate1-cli/README.md b/gen/coordinate1-cli/README.md new file mode 100644 index 00000000000..79383e596ce --- /dev/null +++ b/gen/coordinate1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO COORDINATE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/coordinate1-cli/mkdocs.yml b/gen/coordinate1-cli/mkdocs.yml new file mode 100644 index 00000000000..56fb9f231bf --- /dev/null +++ b/gen/coordinate1-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: coordinate v0.0.1+20141215 +site_url: http://byron.github.io/google-apis-rs/google-coordinate1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/coordinate1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['custom-field-def_list.md', 'Custom Field Def', 'List'] +- ['jobs_get.md', 'Jobs', 'Get'] +- ['jobs_insert.md', 'Jobs', 'Insert'] +- ['jobs_list.md', 'Jobs', 'List'] +- ['jobs_patch.md', 'Jobs', 'Patch'] +- ['jobs_update.md', 'Jobs', 'Update'] +- ['location_list.md', 'Location', 'List'] +- ['schedule_get.md', 'Schedule', 'Get'] +- ['schedule_patch.md', 'Schedule', 'Patch'] +- ['schedule_update.md', 'Schedule', 'Update'] +- ['team_list.md', 'Team', 'List'] +- ['worker_list.md', 'Worker', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/coordinate1-cli/src/cmn.rs b/gen/coordinate1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/coordinate1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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); + +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, 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + 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 { + 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 { + if !flag || arg == "-" { + Box::new(stdout()) + } else { + Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap()) + } +} + + +pub fn arg_from_str(arg: &str, err: &mut InvalidOptionsError, + arg_name: &'static str, + arg_type: &'static str) -> T + where T: FromStr + Default, + ::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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern =", kv), + + } + } +} + +#[derive(Debug)] +pub struct InvalidOptionsError { + pub issues: Vec, + 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 { + 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) -> Result { + 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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::(&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!(); +} \ No newline at end of file diff --git a/gen/coordinate1-cli/src/main.rs b/gen/coordinate1-cli/src/main.rs new file mode 100644 index 00000000000..6dfe1e3457c --- /dev/null +++ b/gen/coordinate1-cli/src/main.rs @@ -0,0 +1,1110 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_coordinate1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + coordinate1 [options] custom-field-def list [-p ]... [-o ] + coordinate1 [options] jobs get [-p ]... [-o ] + coordinate1 [options] jobs insert
-r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] jobs list <team-id> [-p <v>]... [-o <out>] + coordinate1 [options] jobs patch <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] jobs update <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] location list <team-id> <worker-email> <start-timestamp-ms> [-p <v>]... [-o <out>] + coordinate1 [options] schedule get <team-id> <job-id> [-p <v>]... [-o <out>] + coordinate1 [options] schedule patch <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] schedule update <team-id> <job-id> -r <kv>... [-p <v>]... [-o <out>] + coordinate1 [options] team list [-p <v>]... [-o <out>] + coordinate1 [options] worker list <team-id> [-p <v>]... [-o <out>] + coordinate1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Coordinate<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _custom_field_def_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.custom_field_def().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().get(&self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Job = Default::default(); + let lat: f64 = arg_from_str(&self.opt.arg_lat, err, "<lat>", "number"); + let lng: f64 = arg_from_str(&self.opt.arg_lng, err, "<lng>", "number"); + let mut call = self.hub.jobs().insert(&request, &self.opt.arg_team_id, &self.opt.arg_address, lat, lng, &self.opt.arg_title); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "note" => { + call = call.note(value.unwrap_or("")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = value.unwrap_or("").to_string(); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "state.note" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().note.push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = value.unwrap_or("").to_string(); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = value.unwrap_or("").to_string(); + }, + "state.location.lat" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lat = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number"); + }, + "state.location.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.kind = value.unwrap_or("").to_string(); + }, + "state.location.address-line" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.address_line.push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lng = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number"); + }, + "state.progress" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().progress = value.unwrap_or("").to_string(); + }, + "state.custom-fields.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().custom_fields.kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-modified-timestamp-ms" => { + call = call.min_modified_timestamp_ms(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Job = Default::default(); + let mut call = self.hub.jobs().patch(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "title" => { + call = call.title(value.unwrap_or("")); + }, + "progress" => { + call = call.progress(value.unwrap_or("")); + }, + "note" => { + call = call.note(value.unwrap_or("")); + }, + "lng" => { + call = call.lng(arg_from_str(value.unwrap_or("0.0"), err, "lng", "number")); + }, + "lat" => { + call = call.lat(arg_from_str(value.unwrap_or("0.0"), err, "lat", "number")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "address" => { + call = call.address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = value.unwrap_or("").to_string(); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "state.note" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().note.push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = value.unwrap_or("").to_string(); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = value.unwrap_or("").to_string(); + }, + "state.location.lat" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lat = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number"); + }, + "state.location.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.kind = value.unwrap_or("").to_string(); + }, + "state.location.address-line" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.address_line.push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lng = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number"); + }, + "state.progress" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().progress = value.unwrap_or("").to_string(); + }, + "state.custom-fields.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().custom_fields.kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Job = Default::default(); + let mut call = self.hub.jobs().update(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "title" => { + call = call.title(value.unwrap_or("")); + }, + "progress" => { + call = call.progress(value.unwrap_or("")); + }, + "note" => { + call = call.note(value.unwrap_or("")); + }, + "lng" => { + call = call.lng(arg_from_str(value.unwrap_or("0.0"), err, "lng", "number")); + }, + "lat" => { + call = call.lat(arg_from_str(value.unwrap_or("0.0"), err, "lat", "number")); + }, + "customer-phone-number" => { + call = call.customer_phone_number(value.unwrap_or("")); + }, + "customer-name" => { + call = call.customer_name(value.unwrap_or("")); + }, + "custom-field" => { + call = call.add_custom_field(value.unwrap_or("")); + }, + "assignee" => { + call = call.assignee(value.unwrap_or("")); + }, + "address" => { + call = call.address(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_init(request: &mut api::Job) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "state.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "state.customer-name" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_name = value.unwrap_or("").to_string(); + }, + "state.title" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "state.note" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().note.push(value.unwrap_or("").to_string()); + }, + "state.assignee" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().assignee = value.unwrap_or("").to_string(); + }, + "state.customer-phone-number" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().customer_phone_number = value.unwrap_or("").to_string(); + }, + "state.location.lat" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lat = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lat", "number"); + }, + "state.location.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.kind = value.unwrap_or("").to_string(); + }, + "state.location.address-line" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.address_line.push(value.unwrap_or("").to_string()); + }, + "state.location.lng" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().location.lng = arg_from_str(value.unwrap_or("0.0"), err, "state.location.lng", "number"); + }, + "state.progress" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().progress = value.unwrap_or("").to_string(); + }, + "state.custom-fields.kind" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().custom_fields.kind = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _location_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.location().list(&self.opt.arg_team_id, &self.opt.arg_worker_email, &self.opt.arg_start_timestamp_ms); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.schedule().get(&self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Schedule = Default::default(); + let mut call = self.hub.schedule().patch(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "duration" => { + call = call.duration(value.unwrap_or("")); + }, + "all-day" => { + call = call.all_day(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "duration" => { + request.duration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "all-day" => { + request.all_day = Some(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "end-time" => { + request.end_time = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _schedule_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Schedule = Default::default(); + let mut call = self.hub.schedule().update(&request, &self.opt.arg_team_id, &self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "duration" => { + call = call.duration(value.unwrap_or("")); + }, + "all-day" => { + call = call.all_day(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "duration" => { + request.duration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "all-day" => { + request.all_day = Some(arg_from_str(value.unwrap_or("false"), err, "all-day", "boolean")); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "end-time" => { + request.end_time = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _team_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.team().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "worker" => { + call = call.worker(arg_from_str(value.unwrap_or("false"), err, "worker", "boolean")); + }, + "dispatcher" => { + call = call.dispatcher(arg_from_str(value.unwrap_or("false"), err, "dispatcher", "boolean")); + }, + "admin" => { + call = call.admin(arg_from_str(value.unwrap_or("false"), err, "admin", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _worker_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.worker().list(&self.opt.arg_team_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_custom_field_def { + if self.opt.cmd_list { + call_result = self._custom_field_def_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_jobs { + if self.opt.cmd_get { + call_result = self._jobs_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._jobs_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._jobs_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._jobs_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._jobs_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_location { + if self.opt.cmd_list { + call_result = self._location_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_schedule { + if self.opt.cmd_get { + call_result = self._schedule_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._schedule_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._schedule_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_team { + if self.opt.cmd_list { + call_result = self._team_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_worker { + if self.opt.cmd_list { + call_result = self._worker_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "coordinate1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "coordinate1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Coordinate::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/coordinate1/src/cmn.rs b/gen/coordinate1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/coordinate1/src/cmn.rs +++ b/gen/coordinate1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/customsearch1-cli/Cargo.toml b/gen/customsearch1-cli/Cargo.toml new file mode 100644 index 00000000000..f67d75a9cd5 --- /dev/null +++ b/gen/customsearch1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-customsearch1-cli" +version = "0.0.1+20131205" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with customsearch (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/customsearch1-cli" +homepage = "https://developers.google.com/custom-search/v1/using_rest" +documentation = "http://byron.github.io/google-apis-rs/google_customsearch1_cli" +license = "MIT" +keywords = ["customsearch", "google", "cli"] + +[[bin]] +name = "customsearch1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-customsearch1] +path = "../customsearch1" diff --git a/gen/customsearch1-cli/LICENSE.md b/gen/customsearch1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/customsearch1-cli/LICENSE.md @@ -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. diff --git a/gen/customsearch1-cli/README.md b/gen/customsearch1-cli/README.md new file mode 100644 index 00000000000..260a95e5442 --- /dev/null +++ b/gen/customsearch1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO CUSTOMSEARCH:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/customsearch1-cli/mkdocs.yml b/gen/customsearch1-cli/mkdocs.yml new file mode 100644 index 00000000000..4f2a14ddf70 --- /dev/null +++ b/gen/customsearch1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: customsearch v0.0.1+20131205 +site_url: http://byron.github.io/google-apis-rs/google-customsearch1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/customsearch1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['cse_list.md', 'Cse', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/customsearch1-cli/src/cmn.rs b/gen/customsearch1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/customsearch1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/customsearch1-cli/src/main.rs b/gen/customsearch1-cli/src/main.rs new file mode 100644 index 00000000000..86abceac2d9 --- /dev/null +++ b/gen/customsearch1-cli/src/main.rs @@ -0,0 +1,262 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_customsearch1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + customsearch1 [options] cse list <q> [-p <v>]... [-o <out>] + customsearch1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Customsearch<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _cse_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.cse().list(&self.opt.arg_q); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start" => { + call = call.start(arg_from_str(value.unwrap_or("-0"), err, "start", "integer")); + }, + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "site-search-filter" => { + call = call.site_search_filter(value.unwrap_or("")); + }, + "site-search" => { + call = call.site_search(value.unwrap_or("")); + }, + "search-type" => { + call = call.search_type(value.unwrap_or("")); + }, + "safe" => { + call = call.safe(value.unwrap_or("")); + }, + "rights" => { + call = call.rights(value.unwrap_or("")); + }, + "related-site" => { + call = call.related_site(value.unwrap_or("")); + }, + "or-terms" => { + call = call.or_terms(value.unwrap_or("")); + }, + "num" => { + call = call.num(arg_from_str(value.unwrap_or("-0"), err, "num", "integer")); + }, + "lr" => { + call = call.lr(value.unwrap_or("")); + }, + "low-range" => { + call = call.low_range(value.unwrap_or("")); + }, + "link-site" => { + call = call.link_site(value.unwrap_or("")); + }, + "img-type" => { + call = call.img_type(value.unwrap_or("")); + }, + "img-size" => { + call = call.img_size(value.unwrap_or("")); + }, + "img-dominant-color" => { + call = call.img_dominant_color(value.unwrap_or("")); + }, + "img-color-type" => { + call = call.img_color_type(value.unwrap_or("")); + }, + "hq" => { + call = call.hq(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "high-range" => { + call = call.high_range(value.unwrap_or("")); + }, + "googlehost" => { + call = call.googlehost(value.unwrap_or("")); + }, + "gl" => { + call = call.gl(value.unwrap_or("")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "file-type" => { + call = call.file_type(value.unwrap_or("")); + }, + "exclude-terms" => { + call = call.exclude_terms(value.unwrap_or("")); + }, + "exact-terms" => { + call = call.exact_terms(value.unwrap_or("")); + }, + "date-restrict" => { + call = call.date_restrict(value.unwrap_or("")); + }, + "cx" => { + call = call.cx(value.unwrap_or("")); + }, + "cref" => { + call = call.cref(value.unwrap_or("")); + }, + "cr" => { + call = call.cr(value.unwrap_or("")); + }, + "c2coff" => { + call = call.c2coff(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_cse { + if self.opt.cmd_list { + call_result = self._cse_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "customsearch1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "customsearch1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Customsearch::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/customsearch1/src/cmn.rs b/gen/customsearch1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/customsearch1/src/cmn.rs +++ b/gen/customsearch1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/dataflow1_b4-cli/Cargo.toml b/gen/dataflow1_b4-cli/Cargo.toml new file mode 100644 index 00000000000..f1fdde68bed --- /dev/null +++ b/gen/dataflow1_b4-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-dataflow1_b4-cli" +version = "0.0.1+20150401" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with dataflow (protocol v1b4)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/dataflow1_b4-cli" +documentation = "http://byron.github.io/google-apis-rs/google_dataflow1_b4_cli" +license = "MIT" +keywords = ["dataflow", "google", "cli"] + +[[bin]] +name = "dataflow1-b4" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-dataflow1_b4] +path = "../dataflow1_b4" diff --git a/gen/dataflow1_b4-cli/LICENSE.md b/gen/dataflow1_b4-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/dataflow1_b4-cli/LICENSE.md @@ -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. diff --git a/gen/dataflow1_b4-cli/README.md b/gen/dataflow1_b4-cli/README.md new file mode 100644 index 00000000000..5156a139a76 --- /dev/null +++ b/gen/dataflow1_b4-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DATAFLOW:V1B4 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/dataflow1_b4-cli/mkdocs.yml b/gen/dataflow1_b4-cli/mkdocs.yml new file mode 100644 index 00000000000..7c7d9095f2e --- /dev/null +++ b/gen/dataflow1_b4-cli/mkdocs.yml @@ -0,0 +1,16 @@ +site_name: dataflow v0.0.1+20150401 +site_url: http://byron.github.io/google-apis-rs/google-dataflow1_b4-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/dataflow1_b4-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/dataflow1_b4-cli/src/cmn.rs b/gen/dataflow1_b4-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/dataflow1_b4-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/dataflow1_b4-cli/src/main.rs b/gen/dataflow1_b4-cli/src/main.rs new file mode 100644 index 00000000000..13da9f8991e --- /dev/null +++ b/gen/dataflow1_b4-cli/src/main.rs @@ -0,0 +1,118 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_dataflow1_b4 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + dataflow1-b4 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Dataflow<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = 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<Engine, InvalidOptionsError> { + 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, "dataflow1-b4-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "dataflow1-b4", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Dataflow::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/datastore1_beta2-cli/Cargo.toml b/gen/datastore1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..bc2beb3c347 --- /dev/null +++ b/gen/datastore1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-datastore1_beta2-cli" +version = "0.0.1+20140916" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with datastore (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/datastore1_beta2-cli" +homepage = "https://developers.google.com/datastore/" +documentation = "http://byron.github.io/google-apis-rs/google_datastore1_beta2_cli" +license = "MIT" +keywords = ["datastore", "google", "cli"] + +[[bin]] +name = "datastore1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-datastore1_beta2] +path = "../datastore1_beta2" diff --git a/gen/datastore1_beta2-cli/LICENSE.md b/gen/datastore1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/datastore1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/datastore1_beta2-cli/README.md b/gen/datastore1_beta2-cli/README.md new file mode 100644 index 00000000000..4b58337290d --- /dev/null +++ b/gen/datastore1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DATASTORE:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/datastore1_beta2-cli/mkdocs.yml b/gen/datastore1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..7057d99aa7a --- /dev/null +++ b/gen/datastore1_beta2-cli/mkdocs.yml @@ -0,0 +1,22 @@ +site_name: datastore v0.0.1+20140916 +site_url: http://byron.github.io/google-apis-rs/google-datastore1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/datastore1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['datasets_allocate-ids.md', 'Datasets', 'Allocate Ids'] +- ['datasets_begin-transaction.md', 'Datasets', 'Begin Transaction'] +- ['datasets_commit.md', 'Datasets', 'Commit'] +- ['datasets_lookup.md', 'Datasets', 'Lookup'] +- ['datasets_rollback.md', 'Datasets', 'Rollback'] +- ['datasets_run-query.md', 'Datasets', 'Run Query'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/datastore1_beta2-cli/src/cmn.rs b/gen/datastore1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/datastore1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/datastore1_beta2-cli/src/main.rs b/gen/datastore1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..ec371bdd686 --- /dev/null +++ b/gen/datastore1_beta2-cli/src/main.rs @@ -0,0 +1,653 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_datastore1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + datastore1-beta2 [options] datasets allocate-ids <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 [options] datasets begin-transaction <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 [options] datasets commit <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 [options] datasets lookup <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 [options] datasets rollback <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 [options] datasets run-query <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + datastore1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Datastore<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _datasets_allocate_ids(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AllocateIdsRequest = Default::default(); + let mut call = self.hub.datasets().allocate_ids(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_begin_transaction(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::BeginTransactionRequest = Default::default(); + let mut call = self.hub.datasets().begin_transaction(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "isolation-level" => { + request.isolation_level = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_commit(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CommitRequest = Default::default(); + let mut call = self.hub.datasets().commit(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_mutation_init(request: &mut api::CommitRequest) { + if request.mutation.is_none() { + request.mutation = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "ignore-read-only" => { + request.ignore_read_only = Some(arg_from_str(value.unwrap_or("false"), err, "ignore-read-only", "boolean")); + }, + "transaction" => { + request.transaction = Some(value.unwrap_or("").to_string()); + }, + "mode" => { + request.mode = Some(value.unwrap_or("").to_string()); + }, + "mutation.force" => { + request_mutation_init(&mut request); + request.mutation.as_mut().unwrap().force = arg_from_str(value.unwrap_or("false"), err, "mutation.force", "boolean"); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_lookup(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LookupRequest = Default::default(); + let mut call = self.hub.datasets().lookup(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_read_options_init(request: &mut api::LookupRequest) { + if request.read_options.is_none() { + request.read_options = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "read-options.transaction" => { + request_read_options_init(&mut request); + request.read_options.as_mut().unwrap().transaction = value.unwrap_or("").to_string(); + }, + "read-options.read-consistency" => { + request_read_options_init(&mut request); + request.read_options.as_mut().unwrap().read_consistency = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_rollback(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RollbackRequest = Default::default(); + let mut call = self.hub.datasets().rollback(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "transaction" => { + request.transaction = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_run_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RunQueryRequest = Default::default(); + let mut call = self.hub.datasets().run_query(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_gql_query_init(request: &mut api::RunQueryRequest) { + if request.gql_query.is_none() { + request.gql_query = Some(Default::default()); + } + } + + fn request_partition_id_init(request: &mut api::RunQueryRequest) { + if request.partition_id.is_none() { + request.partition_id = Some(Default::default()); + } + } + + fn request_query_init(request: &mut api::RunQueryRequest) { + if request.query.is_none() { + request.query = Some(Default::default()); + } + } + + fn request_read_options_init(request: &mut api::RunQueryRequest) { + if request.read_options.is_none() { + request.read_options = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "query.filter.composite-filter.operator" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.composite_filter.operator = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.operator" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.operator = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.property.name" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.property.name = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.entity-value.key.partition-id.namespace" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.entity_value.key.partition_id.namespace = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.entity-value.key.partition-id.dataset-id" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.entity_value.key.partition_id.dataset_id = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.double-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.double_value = arg_from_str(value.unwrap_or("0.0"), err, "query.filter.property-filter.value.double-value", "number"); + }, + "query.filter.property-filter.value.integer-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.integer_value = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.meaning" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.meaning = arg_from_str(value.unwrap_or("-0"), err, "query.filter.property-filter.value.meaning", "integer"); + }, + "query.filter.property-filter.value.date-time-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.date_time_value = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.key-value.partition-id.namespace" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.key_value.partition_id.namespace = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.key-value.partition-id.dataset-id" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.key_value.partition_id.dataset_id = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.string-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.string_value = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.indexed" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.indexed = arg_from_str(value.unwrap_or("false"), err, "query.filter.property-filter.value.indexed", "boolean"); + }, + "query.filter.property-filter.value.blob-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.blob_value = value.unwrap_or("").to_string(); + }, + "query.filter.property-filter.value.boolean-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.boolean_value = arg_from_str(value.unwrap_or("false"), err, "query.filter.property-filter.value.boolean-value", "boolean"); + }, + "query.filter.property-filter.value.blob-key-value" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().filter.property_filter.value.blob_key_value = value.unwrap_or("").to_string(); + }, + "query.start-cursor" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().start_cursor = value.unwrap_or("").to_string(); + }, + "query.end-cursor" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().end_cursor = value.unwrap_or("").to_string(); + }, + "query.limit" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().limit = arg_from_str(value.unwrap_or("-0"), err, "query.limit", "integer"); + }, + "query.offset" => { + request_query_init(&mut request); + request.query.as_mut().unwrap().offset = arg_from_str(value.unwrap_or("-0"), err, "query.offset", "integer"); + }, + "partition-id.namespace" => { + request_partition_id_init(&mut request); + request.partition_id.as_mut().unwrap().namespace = value.unwrap_or("").to_string(); + }, + "partition-id.dataset-id" => { + request_partition_id_init(&mut request); + request.partition_id.as_mut().unwrap().dataset_id = value.unwrap_or("").to_string(); + }, + "gql-query.query-string" => { + request_gql_query_init(&mut request); + request.gql_query.as_mut().unwrap().query_string = value.unwrap_or("").to_string(); + }, + "gql-query.allow-literal" => { + request_gql_query_init(&mut request); + request.gql_query.as_mut().unwrap().allow_literal = arg_from_str(value.unwrap_or("false"), err, "gql-query.allow-literal", "boolean"); + }, + "read-options.transaction" => { + request_read_options_init(&mut request); + request.read_options.as_mut().unwrap().transaction = value.unwrap_or("").to_string(); + }, + "read-options.read-consistency" => { + request_read_options_init(&mut request); + request.read_options.as_mut().unwrap().read_consistency = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_datasets { + if self.opt.cmd_allocate_ids { + call_result = self._datasets_allocate_ids(dry_run, &mut err); + } else if self.opt.cmd_begin_transaction { + call_result = self._datasets_begin_transaction(dry_run, &mut err); + } else if self.opt.cmd_commit { + call_result = self._datasets_commit(dry_run, &mut err); + } else if self.opt.cmd_lookup { + call_result = self._datasets_lookup(dry_run, &mut err); + } else if self.opt.cmd_rollback { + call_result = self._datasets_rollback(dry_run, &mut err); + } else if self.opt.cmd_run_query { + call_result = self._datasets_run_query(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "datastore1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "datastore1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Datastore::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/deploymentmanager2_beta1-cli/Cargo.toml b/gen/deploymentmanager2_beta1-cli/Cargo.toml new file mode 100644 index 00000000000..588d64aa48a --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-deploymentmanager2_beta1-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with deploymentmanager (protocol v2beta1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/deploymentmanager2_beta1-cli" +homepage = "https://developers.google.com/deployment-manager/" +documentation = "http://byron.github.io/google-apis-rs/google_deploymentmanager2_beta1_cli" +license = "MIT" +keywords = ["deploymentmanager", "google", "cli"] + +[[bin]] +name = "deploymentmanager2-beta1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-deploymentmanager2_beta1] +path = "../deploymentmanager2_beta1" diff --git a/gen/deploymentmanager2_beta1-cli/LICENSE.md b/gen/deploymentmanager2_beta1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/LICENSE.md @@ -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. diff --git a/gen/deploymentmanager2_beta1-cli/README.md b/gen/deploymentmanager2_beta1-cli/README.md new file mode 100644 index 00000000000..747aa3731d6 --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DEPLOYMENTMANAGER:V2BETA1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/deploymentmanager2_beta1-cli/mkdocs.yml b/gen/deploymentmanager2_beta1-cli/mkdocs.yml new file mode 100644 index 00000000000..24e434880ce --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/mkdocs.yml @@ -0,0 +1,27 @@ +site_name: deploymentmanager v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-deploymentmanager2_beta1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/deploymentmanager2_beta1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['deployments_delete.md', 'Deployments', 'Delete'] +- ['deployments_get.md', 'Deployments', 'Get'] +- ['deployments_insert.md', 'Deployments', 'Insert'] +- ['deployments_list.md', 'Deployments', 'List'] +- ['manifests_get.md', 'Manifests', 'Get'] +- ['manifests_list.md', 'Manifests', 'List'] +- ['operations_get.md', 'Operations', 'Get'] +- ['operations_list.md', 'Operations', 'List'] +- ['resources_get.md', 'Resources', 'Get'] +- ['resources_list.md', 'Resources', 'List'] +- ['types_list.md', 'Types', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/deploymentmanager2_beta1-cli/src/cmn.rs b/gen/deploymentmanager2_beta1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/deploymentmanager2_beta1-cli/src/main.rs b/gen/deploymentmanager2_beta1-cli/src/main.rs new file mode 100644 index 00000000000..5d459ac7066 --- /dev/null +++ b/gen/deploymentmanager2_beta1-cli/src/main.rs @@ -0,0 +1,717 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_deploymentmanager2_beta1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + deploymentmanager2-beta1 [options] deployments delete <project> <deployment> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] deployments get <project> <deployment> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] deployments insert <project> -r <kv>... [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] deployments list <project> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] manifests get <project> <deployment> <manifest> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] manifests list <project> <deployment> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] operations get <project> <operation> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] operations list <project> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] resources get <project> <deployment> <resource> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] resources list <project> <deployment> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 [options] types list <project> [-p <v>]... [-o <out>] + deploymentmanager2-beta1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Deploymentmanager<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _deployments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().delete(&self.opt.arg_project, &self.opt.arg_deployment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _deployments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().get(&self.opt.arg_project, &self.opt.arg_deployment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _deployments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Deployment = Default::default(); + let mut call = self.hub.deployments().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target-config" => { + request.target_config = Some(value.unwrap_or("").to_string()); + }, + "manifest" => { + request.manifest = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _deployments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _manifests_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.manifests().get(&self.opt.arg_project, &self.opt.arg_deployment, &self.opt.arg_manifest); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _manifests_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.manifests().list(&self.opt.arg_project, &self.opt.arg_deployment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operations().get(&self.opt.arg_project, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operations().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _resources_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.resources().get(&self.opt.arg_project, &self.opt.arg_deployment, &self.opt.arg_resource); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _resources_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.resources().list(&self.opt.arg_project, &self.opt.arg_deployment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _types_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.types().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_deployments { + if self.opt.cmd_delete { + call_result = self._deployments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._deployments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._deployments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._deployments_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_manifests { + if self.opt.cmd_get { + call_result = self._manifests_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._manifests_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_operations { + if self.opt.cmd_get { + call_result = self._operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_resources { + if self.opt.cmd_get { + call_result = self._resources_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._resources_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_types { + if self.opt.cmd_list { + call_result = self._types_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "deploymentmanager2-beta1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "deploymentmanager2-beta1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Deploymentmanager::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/dfareporting2-cli/Cargo.toml b/gen/dfareporting2-cli/Cargo.toml new file mode 100644 index 00000000000..3240cfeab14 --- /dev/null +++ b/gen/dfareporting2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-dfareporting2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with dfareporting (protocol v2.0)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/dfareporting2-cli" +homepage = "https://developers.google.com/doubleclick-advertisers/reporting/" +documentation = "http://byron.github.io/google-apis-rs/google_dfareporting2_cli" +license = "MIT" +keywords = ["dfareporting", "google", "cli"] + +[[bin]] +name = "dfareporting2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-dfareporting2] +path = "../dfareporting2" diff --git a/gen/dfareporting2-cli/LICENSE.md b/gen/dfareporting2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/dfareporting2-cli/LICENSE.md @@ -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. diff --git a/gen/dfareporting2-cli/README.md b/gen/dfareporting2-cli/README.md new file mode 100644 index 00000000000..a6943b5bb1b --- /dev/null +++ b/gen/dfareporting2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DFAREPORTING:V2.0 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/dfareporting2-cli/mkdocs.yml b/gen/dfareporting2-cli/mkdocs.yml new file mode 100644 index 00000000000..e8bc7d932c1 --- /dev/null +++ b/gen/dfareporting2-cli/mkdocs.yml @@ -0,0 +1,183 @@ +site_name: dfareporting v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-dfareporting2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/dfareporting2-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_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_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_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'] +- ['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_list.md', 'Mobile Carriers', 'List'] +- ['operating-system-versions_list.md', 'Operating System Versions', 'List'] +- ['operating-systems_list.md', 'Operating Systems', '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_list.md', 'Platform Types', 'List'] +- ['postal-codes_list.md', 'Postal Codes', 'List'] +- ['regions_list.md', 'Regions', 'List'] +- ['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'] +- ['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` + diff --git a/gen/dfareporting2-cli/src/cmn.rs b/gen/dfareporting2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/dfareporting2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/dfareporting2-cli/src/main.rs b/gen/dfareporting2-cli/src/main.rs new file mode 100644 index 00000000000..f8c9e621e31 --- /dev/null +++ b/gen/dfareporting2-cli/src/main.rs @@ -0,0 +1,19555 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_dfareporting2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + dfareporting2 [options] account-active-ad-summaries get <profile-id> <summary-account-id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-permission-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-permission-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-permissions get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-permissions list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-user-profiles get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-user-profiles list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] account-user-profiles patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] account-user-profiles update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] accounts get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] accounts list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] accounts patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] accounts update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] ads get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] ads insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] ads list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] ads patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] ads update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertiser-groups delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] advertiser-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] advertiser-groups insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertiser-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] advertiser-groups patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertiser-groups update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertisers get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] advertisers insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertisers list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] advertisers patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] advertisers update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] browsers list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] campaign-creative-associations insert <profile-id> <campaign-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] campaign-creative-associations list <profile-id> <campaign-id> [-p <v>]... [-o <out>] + dfareporting2 [options] campaigns get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] campaigns insert <profile-id> <default-landing-page-name> <default-landing-page-url> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] campaigns list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] campaigns patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] campaigns update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] change-logs get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] change-logs list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] cities list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] connection-types list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] content-categories delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] content-categories get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] content-categories insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] content-categories list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] content-categories patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] content-categories update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] countries get <profile-id> <dart-id> [-p <v>]... [-o <out>] + dfareporting2 [options] countries list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-assets insert <profile-id> <advertiser-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-field-values delete <profile-id> <creative-field-id> <id> [-p <v>]... + dfareporting2 [options] creative-field-values get <profile-id> <creative-field-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-field-values insert <profile-id> <creative-field-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-field-values list <profile-id> <creative-field-id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-field-values patch <profile-id> <creative-field-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-field-values update <profile-id> <creative-field-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-fields delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] creative-fields get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-fields insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-fields list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-fields patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-fields update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-groups insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] creative-groups patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creative-groups update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creatives get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] creatives insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creatives list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] creatives patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] creatives update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] dimension-values query <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] directory-site-contacts get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] directory-site-contacts list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] directory-sites get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] directory-sites list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] event-tags delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] event-tags get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] event-tags insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] event-tags list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] event-tags patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] event-tags update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] files get <report-id> <file-id> [-p <v>]... [-o <out>] + dfareporting2 [options] files list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] floodlight-activities generatetag <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activities update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activity-groups delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] floodlight-activity-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activity-groups insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activity-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activity-groups patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-activity-groups update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-configurations get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-configurations list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-configurations patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] floodlight-configurations update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] landing-pages delete <profile-id> <campaign-id> <id> [-p <v>]... + dfareporting2 [options] landing-pages get <profile-id> <campaign-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] landing-pages insert <profile-id> <campaign-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] landing-pages list <profile-id> <campaign-id> [-p <v>]... [-o <out>] + dfareporting2 [options] landing-pages patch <profile-id> <campaign-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] landing-pages update <profile-id> <campaign-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] metros list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] mobile-carriers list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] operating-system-versions list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] operating-systems list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] placement-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] placement-groups insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placement-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] placement-groups patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placement-groups update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placement-strategies delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] placement-strategies get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] placement-strategies insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placement-strategies list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] placement-strategies patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placement-strategies update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placements generatetags <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] placements get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] placements insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placements list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] placements patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] placements update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] platform-types list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] postal-codes list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] regions list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports compatible-fields-query <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] reports delete <profile-id> <report-id> [-p <v>]... + dfareporting2 [options] reports files-get <profile-id> <report-id> <file-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports files-list <profile-id> <report-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports get <profile-id> <report-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] reports list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports patch <profile-id> <report-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] reports run <profile-id> <report-id> [-p <v>]... [-o <out>] + dfareporting2 [options] reports update <profile-id> <report-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] sites get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] sites insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] sites list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] sites patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] sites update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] sizes get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] sizes insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] sizes list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] subaccounts get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] subaccounts insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] subaccounts list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] subaccounts patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] subaccounts update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] user-profiles get <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-profiles list [-p <v>]... [-o <out>] + dfareporting2 [options] user-role-permission-groups get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-role-permission-groups list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-role-permissions get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-role-permissions list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-roles delete <profile-id> <id> [-p <v>]... + dfareporting2 [options] user-roles get <profile-id> <id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-roles insert <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] user-roles list <profile-id> [-p <v>]... [-o <out>] + dfareporting2 [options] user-roles patch <profile-id> <id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 [options] user-roles update <profile-id> -r <kv>... [-p <v>]... [-o <out>] + dfareporting2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Dfareporting<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _account_active_ad_summaries_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_active_ad_summaries().get(&self.opt.arg_profile_id, &self.opt.arg_summary_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_permission_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_permission_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_permission_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_permission_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_permissions().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_permissions().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_user_profiles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_user_profiles().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_user_profiles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.account_user_profiles().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-role-id" => { + call = call.user_role_id(value.unwrap_or("")); + }, + "subaccount-id" => { + call = call.subaccount_id(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "active" => { + call = call.active(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_user_profiles_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AccountUserProfile = Default::default(); + let mut call = self.hub.account_user_profiles().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_filter_init(request: &mut api::AccountUserProfile) { + if request.advertiser_filter.is_none() { + request.advertiser_filter = Some(Default::default()); + } + } + + fn request_campaign_filter_init(request: &mut api::AccountUserProfile) { + if request.campaign_filter.is_none() { + request.campaign_filter = Some(Default::default()); + } + } + + fn request_site_filter_init(request: &mut api::AccountUserProfile) { + if request.site_filter.is_none() { + request.site_filter = Some(Default::default()); + } + } + + fn request_user_role_filter_init(request: &mut api::AccountUserProfile) { + if request.user_role_filter.is_none() { + request.user_role_filter = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "user-role-filter.object-ids" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "user-role-filter.status" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "user-role-filter.kind" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "name" => { + request_user_role_filter_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "locale" => { + request_user_role_filter_init(&mut request); + request.locale = Some(value.unwrap_or("").to_string()); + }, + "site-filter.object-ids" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "site-filter.status" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "site-filter.kind" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "comments" => { + request_site_filter_init(&mut request); + request.comments = Some(value.unwrap_or("").to_string()); + }, + "trafficker-type" => { + request_site_filter_init(&mut request); + request.trafficker_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-filter.object-ids" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "advertiser-filter.status" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "advertiser-filter.kind" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "campaign-filter.object-ids" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "campaign-filter.status" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "campaign-filter.kind" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "email" => { + request_campaign_filter_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "user-role-id" => { + request_campaign_filter_init(&mut request); + request.user_role_id = Some(value.unwrap_or("").to_string()); + }, + "user-access-type" => { + request_campaign_filter_init(&mut request); + request.user_access_type = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_campaign_filter_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "id" => { + request_campaign_filter_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_campaign_filter_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _account_user_profiles_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AccountUserProfile = Default::default(); + let mut call = self.hub.account_user_profiles().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_filter_init(request: &mut api::AccountUserProfile) { + if request.advertiser_filter.is_none() { + request.advertiser_filter = Some(Default::default()); + } + } + + fn request_campaign_filter_init(request: &mut api::AccountUserProfile) { + if request.campaign_filter.is_none() { + request.campaign_filter = Some(Default::default()); + } + } + + fn request_site_filter_init(request: &mut api::AccountUserProfile) { + if request.site_filter.is_none() { + request.site_filter = Some(Default::default()); + } + } + + fn request_user_role_filter_init(request: &mut api::AccountUserProfile) { + if request.user_role_filter.is_none() { + request.user_role_filter = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "user-role-filter.object-ids" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "user-role-filter.status" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "user-role-filter.kind" => { + request_user_role_filter_init(&mut request); + request.user_role_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "name" => { + request_user_role_filter_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "locale" => { + request_user_role_filter_init(&mut request); + request.locale = Some(value.unwrap_or("").to_string()); + }, + "site-filter.object-ids" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "site-filter.status" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "site-filter.kind" => { + request_site_filter_init(&mut request); + request.site_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "comments" => { + request_site_filter_init(&mut request); + request.comments = Some(value.unwrap_or("").to_string()); + }, + "trafficker-type" => { + request_site_filter_init(&mut request); + request.trafficker_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-filter.object-ids" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "advertiser-filter.status" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "advertiser-filter.kind" => { + request_advertiser_filter_init(&mut request); + request.advertiser_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "campaign-filter.object-ids" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().object_ids.push(value.unwrap_or("").to_string()); + }, + "campaign-filter.status" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "campaign-filter.kind" => { + request_campaign_filter_init(&mut request); + request.campaign_filter.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "email" => { + request_campaign_filter_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "user-role-id" => { + request_campaign_filter_init(&mut request); + request.user_role_id = Some(value.unwrap_or("").to_string()); + }, + "user-access-type" => { + request_campaign_filter_init(&mut request); + request.user_access_type = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_campaign_filter_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "id" => { + request_campaign_filter_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_campaign_filter_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "active" => { + call = call.active(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_reports_configuration_init(request: &mut api::Account) { + if request.reports_configuration.is_none() { + request.reports_configuration = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "teaser-size-limit" => { + request.teaser_size_limit = Some(value.unwrap_or("").to_string()); + }, + "active-view-opt-out" => { + request.active_view_opt_out = Some(arg_from_str(value.unwrap_or("false"), err, "active-view-opt-out", "boolean")); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "maximum-image-size" => { + request.maximum_image_size = Some(value.unwrap_or("").to_string()); + }, + "locale" => { + request.locale = Some(value.unwrap_or("").to_string()); + }, + "default-creative-size-id" => { + request.default_creative_size_id = Some(value.unwrap_or("").to_string()); + }, + "account-permission-ids" => { + if request.account_permission_ids.is_none() { + request.account_permission_ids = Some(Default::default()); + } + request.account_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "account-profile" => { + request.account_profile = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "nielsen-ocr-enabled" => { + request.nielsen_ocr_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "nielsen-ocr-enabled", "boolean")); + }, + "reports-configuration.report-generation-time-zone-id" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().report_generation_time_zone_id = value.unwrap_or("").to_string(); + }, + "reports-configuration.exposure-to-conversion-enabled" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().exposure_to_conversion_enabled = arg_from_str(value.unwrap_or("false"), err, "reports-configuration.exposure-to-conversion-enabled", "boolean"); + }, + "reports-configuration.lookback-configuration.click-duration" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().lookback_configuration.click_duration = arg_from_str(value.unwrap_or("-0"), err, "reports-configuration.lookback-configuration.click-duration", "integer"); + }, + "reports-configuration.lookback-configuration.post-impression-activities-duration" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().lookback_configuration.post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "reports-configuration.lookback-configuration.post-impression-activities-duration", "integer"); + }, + "currency-id" => { + request_reports_configuration_init(&mut request); + request.currency_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_reports_configuration_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "comscore-vce-enabled" => { + request_reports_configuration_init(&mut request); + request.comscore_vce_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "comscore-vce-enabled", "boolean")); + }, + "active-ads-limit-tier" => { + request_reports_configuration_init(&mut request); + request.active_ads_limit_tier = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_reports_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "country-id" => { + request_reports_configuration_init(&mut request); + request.country_id = Some(value.unwrap_or("").to_string()); + }, + "available-permission-ids" => { + request_reports_configuration_init(&mut request); + if request.available_permission_ids.is_none() { + request.available_permission_ids = Some(Default::default()); + } + request.available_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_reports_configuration_init(request: &mut api::Account) { + if request.reports_configuration.is_none() { + request.reports_configuration = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "teaser-size-limit" => { + request.teaser_size_limit = Some(value.unwrap_or("").to_string()); + }, + "active-view-opt-out" => { + request.active_view_opt_out = Some(arg_from_str(value.unwrap_or("false"), err, "active-view-opt-out", "boolean")); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "maximum-image-size" => { + request.maximum_image_size = Some(value.unwrap_or("").to_string()); + }, + "locale" => { + request.locale = Some(value.unwrap_or("").to_string()); + }, + "default-creative-size-id" => { + request.default_creative_size_id = Some(value.unwrap_or("").to_string()); + }, + "account-permission-ids" => { + if request.account_permission_ids.is_none() { + request.account_permission_ids = Some(Default::default()); + } + request.account_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "account-profile" => { + request.account_profile = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "nielsen-ocr-enabled" => { + request.nielsen_ocr_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "nielsen-ocr-enabled", "boolean")); + }, + "reports-configuration.report-generation-time-zone-id" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().report_generation_time_zone_id = value.unwrap_or("").to_string(); + }, + "reports-configuration.exposure-to-conversion-enabled" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().exposure_to_conversion_enabled = arg_from_str(value.unwrap_or("false"), err, "reports-configuration.exposure-to-conversion-enabled", "boolean"); + }, + "reports-configuration.lookback-configuration.click-duration" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().lookback_configuration.click_duration = arg_from_str(value.unwrap_or("-0"), err, "reports-configuration.lookback-configuration.click-duration", "integer"); + }, + "reports-configuration.lookback-configuration.post-impression-activities-duration" => { + request_reports_configuration_init(&mut request); + request.reports_configuration.as_mut().unwrap().lookback_configuration.post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "reports-configuration.lookback-configuration.post-impression-activities-duration", "integer"); + }, + "currency-id" => { + request_reports_configuration_init(&mut request); + request.currency_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_reports_configuration_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "comscore-vce-enabled" => { + request_reports_configuration_init(&mut request); + request.comscore_vce_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "comscore-vce-enabled", "boolean")); + }, + "active-ads-limit-tier" => { + request_reports_configuration_init(&mut request); + request.active_ads_limit_tier = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_reports_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "country-id" => { + request_reports_configuration_init(&mut request); + request.country_id = Some(value.unwrap_or("").to_string()); + }, + "available-permission-ids" => { + request_reports_configuration_init(&mut request); + if request.available_permission_ids.is_none() { + request.available_permission_ids = Some(Default::default()); + } + request.available_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ads_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.ads().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ads_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Ad = Default::default(); + let mut call = self.hub.ads().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Ad) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Ad) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_init(request: &mut api::Ad) { + if request.click_through_url.is_none() { + request.click_through_url = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Ad) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Ad) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_rotation_init(request: &mut api::Ad) { + if request.creative_rotation.is_none() { + request.creative_rotation = Some(Default::default()); + } + } + + fn request_day_part_targeting_init(request: &mut api::Ad) { + if request.day_part_targeting.is_none() { + request.day_part_targeting = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Ad) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_delivery_schedule_init(request: &mut api::Ad) { + if request.delivery_schedule.is_none() { + request.delivery_schedule = Some(Default::default()); + } + } + + fn request_geo_targeting_init(request: &mut api::Ad) { + if request.geo_targeting.is_none() { + request.geo_targeting = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Ad) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_key_value_targeting_expression_init(request: &mut api::Ad) { + if request.key_value_targeting_expression.is_none() { + request.key_value_targeting_expression = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Ad) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_remarketing_list_expression_init(request: &mut api::Ad) { + if request.remarketing_list_expression.is_none() { + request.remarketing_list_expression = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Ad) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "campaign-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "geo-targeting.exclude-countries" => { + request_geo_targeting_init(&mut request); + request.geo_targeting.as_mut().unwrap().exclude_countries = arg_from_str(value.unwrap_or("false"), err, "geo-targeting.exclude-countries", "boolean"); + }, + "delivery-schedule.priority" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().priority = value.unwrap_or("").to_string(); + }, + "delivery-schedule.hard-cutoff" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().hard_cutoff = arg_from_str(value.unwrap_or("false"), err, "delivery-schedule.hard-cutoff", "boolean"); + }, + "delivery-schedule.frequency-cap.duration" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.duration = value.unwrap_or("").to_string(); + }, + "delivery-schedule.frequency-cap.impressions" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.impressions = value.unwrap_or("").to_string(); + }, + "delivery-schedule.impression-ratio" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().impression_ratio = value.unwrap_or("").to_string(); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "remarketing-list-expression.expression" => { + request_remarketing_list_expression_init(&mut request); + request.remarketing_list_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "account-id" => { + request_remarketing_list_expression_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_remarketing_list_expression_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "creative-rotation.weight-calculation-strategy" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().weight_calculation_strategy = value.unwrap_or("").to_string(); + }, + "creative-rotation.creative-optimization-configuration-id" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().creative_optimization_configuration_id = value.unwrap_or("").to_string(); + }, + "creative-rotation.type" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "click-through-url.landing-page-id" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().landing_page_id = value.unwrap_or("").to_string(); + }, + "click-through-url.custom-click-through-url" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().custom_click_through_url = value.unwrap_or("").to_string(); + }, + "click-through-url.default-landing-page" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().default_landing_page = arg_from_str(value.unwrap_or("false"), err, "click-through-url.default-landing-page", "boolean"); + }, + "comments" => { + request_click_through_url_init(&mut request); + request.comments = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "type" => { + request_size_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "audience-segment-id" => { + request_size_init(&mut request); + request.audience_segment_id = Some(value.unwrap_or("").to_string()); + }, + "key-value-targeting-expression.expression" => { + request_key_value_targeting_expression_init(&mut request); + request.key_value_targeting_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "start-time" => { + request_create_info_init(&mut request); + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_create_info_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "compatibility" => { + request_create_info_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "day-part-targeting.user-local-time" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().user_local_time = arg_from_str(value.unwrap_or("false"), err, "day-part-targeting.user-local-time", "boolean"); + }, + "day-part-targeting.hours-of-day" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().hours_of_day.push(arg_from_str(value.unwrap_or("-0"), err, "day-part-targeting.hours-of-day", "integer")); + }, + "day-part-targeting.days-of-week" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().days_of_week.push(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "end-time" => { + request_last_modified_info_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "dynamic-click-tracker" => { + request_last_modified_info_init(&mut request); + request.dynamic_click_tracker = Some(arg_from_str(value.unwrap_or("false"), err, "dynamic-click-tracker", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ads_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.ads().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.add_type(value.unwrap_or("")); + }, + "ssl-required" => { + call = call.ssl_required(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "ssl-compliant" => { + call = call.ssl_compliant(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "size-ids" => { + call = call.add_size_ids(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "remarketing-list-ids" => { + call = call.add_remarketing_list_ids(value.unwrap_or("")); + }, + "placement-ids" => { + call = call.add_placement_ids(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "overridden-event-tag-id" => { + call = call.overridden_event_tag_id(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "landing-page-ids" => { + call = call.add_landing_page_ids(value.unwrap_or("")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "dynamic-click-tracker" => { + call = call.dynamic_click_tracker(arg_from_str(value.unwrap_or("false"), err, "dynamic-click-tracker", "boolean")); + }, + "creative-type" => { + call = call.creative_type(value.unwrap_or("")); + }, + "creative-optimization-configuration-ids" => { + call = call.add_creative_optimization_configuration_ids(value.unwrap_or("")); + }, + "creative-ids" => { + call = call.add_creative_ids(value.unwrap_or("")); + }, + "compatibility" => { + call = call.compatibility(value.unwrap_or("")); + }, + "campaign-ids" => { + call = call.add_campaign_ids(value.unwrap_or("")); + }, + "audience-segment-ids" => { + call = call.add_audience_segment_ids(value.unwrap_or("")); + }, + "archived" => { + call = call.archived(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "active" => { + call = call.active(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ads_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Ad = Default::default(); + let mut call = self.hub.ads().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Ad) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Ad) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_init(request: &mut api::Ad) { + if request.click_through_url.is_none() { + request.click_through_url = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Ad) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Ad) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_rotation_init(request: &mut api::Ad) { + if request.creative_rotation.is_none() { + request.creative_rotation = Some(Default::default()); + } + } + + fn request_day_part_targeting_init(request: &mut api::Ad) { + if request.day_part_targeting.is_none() { + request.day_part_targeting = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Ad) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_delivery_schedule_init(request: &mut api::Ad) { + if request.delivery_schedule.is_none() { + request.delivery_schedule = Some(Default::default()); + } + } + + fn request_geo_targeting_init(request: &mut api::Ad) { + if request.geo_targeting.is_none() { + request.geo_targeting = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Ad) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_key_value_targeting_expression_init(request: &mut api::Ad) { + if request.key_value_targeting_expression.is_none() { + request.key_value_targeting_expression = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Ad) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_remarketing_list_expression_init(request: &mut api::Ad) { + if request.remarketing_list_expression.is_none() { + request.remarketing_list_expression = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Ad) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "campaign-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "geo-targeting.exclude-countries" => { + request_geo_targeting_init(&mut request); + request.geo_targeting.as_mut().unwrap().exclude_countries = arg_from_str(value.unwrap_or("false"), err, "geo-targeting.exclude-countries", "boolean"); + }, + "delivery-schedule.priority" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().priority = value.unwrap_or("").to_string(); + }, + "delivery-schedule.hard-cutoff" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().hard_cutoff = arg_from_str(value.unwrap_or("false"), err, "delivery-schedule.hard-cutoff", "boolean"); + }, + "delivery-schedule.frequency-cap.duration" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.duration = value.unwrap_or("").to_string(); + }, + "delivery-schedule.frequency-cap.impressions" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.impressions = value.unwrap_or("").to_string(); + }, + "delivery-schedule.impression-ratio" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().impression_ratio = value.unwrap_or("").to_string(); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "remarketing-list-expression.expression" => { + request_remarketing_list_expression_init(&mut request); + request.remarketing_list_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "account-id" => { + request_remarketing_list_expression_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_remarketing_list_expression_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "creative-rotation.weight-calculation-strategy" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().weight_calculation_strategy = value.unwrap_or("").to_string(); + }, + "creative-rotation.creative-optimization-configuration-id" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().creative_optimization_configuration_id = value.unwrap_or("").to_string(); + }, + "creative-rotation.type" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "click-through-url.landing-page-id" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().landing_page_id = value.unwrap_or("").to_string(); + }, + "click-through-url.custom-click-through-url" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().custom_click_through_url = value.unwrap_or("").to_string(); + }, + "click-through-url.default-landing-page" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().default_landing_page = arg_from_str(value.unwrap_or("false"), err, "click-through-url.default-landing-page", "boolean"); + }, + "comments" => { + request_click_through_url_init(&mut request); + request.comments = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "type" => { + request_size_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "audience-segment-id" => { + request_size_init(&mut request); + request.audience_segment_id = Some(value.unwrap_or("").to_string()); + }, + "key-value-targeting-expression.expression" => { + request_key_value_targeting_expression_init(&mut request); + request.key_value_targeting_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "start-time" => { + request_create_info_init(&mut request); + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_create_info_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "compatibility" => { + request_create_info_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "day-part-targeting.user-local-time" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().user_local_time = arg_from_str(value.unwrap_or("false"), err, "day-part-targeting.user-local-time", "boolean"); + }, + "day-part-targeting.hours-of-day" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().hours_of_day.push(arg_from_str(value.unwrap_or("-0"), err, "day-part-targeting.hours-of-day", "integer")); + }, + "day-part-targeting.days-of-week" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().days_of_week.push(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "end-time" => { + request_last_modified_info_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "dynamic-click-tracker" => { + request_last_modified_info_init(&mut request); + request.dynamic_click_tracker = Some(arg_from_str(value.unwrap_or("false"), err, "dynamic-click-tracker", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ads_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Ad = Default::default(); + let mut call = self.hub.ads().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Ad) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Ad) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_init(request: &mut api::Ad) { + if request.click_through_url.is_none() { + request.click_through_url = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Ad) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Ad) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_rotation_init(request: &mut api::Ad) { + if request.creative_rotation.is_none() { + request.creative_rotation = Some(Default::default()); + } + } + + fn request_day_part_targeting_init(request: &mut api::Ad) { + if request.day_part_targeting.is_none() { + request.day_part_targeting = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Ad) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_delivery_schedule_init(request: &mut api::Ad) { + if request.delivery_schedule.is_none() { + request.delivery_schedule = Some(Default::default()); + } + } + + fn request_geo_targeting_init(request: &mut api::Ad) { + if request.geo_targeting.is_none() { + request.geo_targeting = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Ad) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_key_value_targeting_expression_init(request: &mut api::Ad) { + if request.key_value_targeting_expression.is_none() { + request.key_value_targeting_expression = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Ad) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_remarketing_list_expression_init(request: &mut api::Ad) { + if request.remarketing_list_expression.is_none() { + request.remarketing_list_expression = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Ad) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "campaign-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "geo-targeting.exclude-countries" => { + request_geo_targeting_init(&mut request); + request.geo_targeting.as_mut().unwrap().exclude_countries = arg_from_str(value.unwrap_or("false"), err, "geo-targeting.exclude-countries", "boolean"); + }, + "delivery-schedule.priority" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().priority = value.unwrap_or("").to_string(); + }, + "delivery-schedule.hard-cutoff" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().hard_cutoff = arg_from_str(value.unwrap_or("false"), err, "delivery-schedule.hard-cutoff", "boolean"); + }, + "delivery-schedule.frequency-cap.duration" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.duration = value.unwrap_or("").to_string(); + }, + "delivery-schedule.frequency-cap.impressions" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().frequency_cap.impressions = value.unwrap_or("").to_string(); + }, + "delivery-schedule.impression-ratio" => { + request_delivery_schedule_init(&mut request); + request.delivery_schedule.as_mut().unwrap().impression_ratio = value.unwrap_or("").to_string(); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "remarketing-list-expression.expression" => { + request_remarketing_list_expression_init(&mut request); + request.remarketing_list_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "account-id" => { + request_remarketing_list_expression_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_remarketing_list_expression_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "creative-rotation.weight-calculation-strategy" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().weight_calculation_strategy = value.unwrap_or("").to_string(); + }, + "creative-rotation.creative-optimization-configuration-id" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().creative_optimization_configuration_id = value.unwrap_or("").to_string(); + }, + "creative-rotation.type" => { + request_creative_rotation_init(&mut request); + request.creative_rotation.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "click-through-url.landing-page-id" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().landing_page_id = value.unwrap_or("").to_string(); + }, + "click-through-url.custom-click-through-url" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().custom_click_through_url = value.unwrap_or("").to_string(); + }, + "click-through-url.default-landing-page" => { + request_click_through_url_init(&mut request); + request.click_through_url.as_mut().unwrap().default_landing_page = arg_from_str(value.unwrap_or("false"), err, "click-through-url.default-landing-page", "boolean"); + }, + "comments" => { + request_click_through_url_init(&mut request); + request.comments = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "type" => { + request_size_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "audience-segment-id" => { + request_size_init(&mut request); + request.audience_segment_id = Some(value.unwrap_or("").to_string()); + }, + "key-value-targeting-expression.expression" => { + request_key_value_targeting_expression_init(&mut request); + request.key_value_targeting_expression.as_mut().unwrap().expression = value.unwrap_or("").to_string(); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "start-time" => { + request_create_info_init(&mut request); + request.start_time = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_create_info_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "compatibility" => { + request_create_info_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "day-part-targeting.user-local-time" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().user_local_time = arg_from_str(value.unwrap_or("false"), err, "day-part-targeting.user-local-time", "boolean"); + }, + "day-part-targeting.hours-of-day" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().hours_of_day.push(arg_from_str(value.unwrap_or("-0"), err, "day-part-targeting.hours-of-day", "integer")); + }, + "day-part-targeting.days-of-week" => { + request_day_part_targeting_init(&mut request); + request.day_part_targeting.as_mut().unwrap().days_of_week.push(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "end-time" => { + request_last_modified_info_init(&mut request); + request.end_time = Some(value.unwrap_or("").to_string()); + }, + "dynamic-click-tracker" => { + request_last_modified_info_init(&mut request); + request.dynamic_click_tracker = Some(arg_from_str(value.unwrap_or("false"), err, "dynamic-click-tracker", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertiser_groups_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertiser_groups().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _advertiser_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertiser_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertiser_groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AdvertiserGroup = Default::default(); + let mut call = self.hub.advertiser_groups().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertiser_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertiser_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertiser_groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AdvertiserGroup = Default::default(); + let mut call = self.hub.advertiser_groups().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertiser_groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AdvertiserGroup = Default::default(); + let mut call = self.hub.advertiser_groups().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertisers().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Advertiser = Default::default(); + let mut call = self.hub.advertisers().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::Advertiser) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Advertiser) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-id" => { + request.default_click_through_event_tag_id = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix" => { + request.click_through_url_suffix = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-email" => { + request_id_dimension_value_init(&mut request); + request.default_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertisers().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "subaccount-id" => { + call = call.subaccount_id(value.unwrap_or("")); + }, + "status" => { + call = call.status(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "only-parent" => { + call = call.only_parent(arg_from_str(value.unwrap_or("false"), err, "only-parent", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-advertisers-without-groups-only" => { + call = call.include_advertisers_without_groups_only(arg_from_str(value.unwrap_or("false"), err, "include-advertisers-without-groups-only", "boolean")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "floodlight-configuration-ids" => { + call = call.add_floodlight_configuration_ids(value.unwrap_or("")); + }, + "advertiser-group-ids" => { + call = call.add_advertiser_group_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Advertiser = Default::default(); + let mut call = self.hub.advertisers().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::Advertiser) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Advertiser) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-id" => { + request.default_click_through_event_tag_id = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix" => { + request.click_through_url_suffix = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-email" => { + request_id_dimension_value_init(&mut request); + request.default_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Advertiser = Default::default(); + let mut call = self.hub.advertisers().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::Advertiser) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Advertiser) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-id" => { + request.default_click_through_event_tag_id = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix" => { + request.click_through_url_suffix = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "default-email" => { + request_id_dimension_value_init(&mut request); + request.default_email = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _browsers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.browsers().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaign_creative_associations_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CampaignCreativeAssociation = Default::default(); + let mut call = self.hub.campaign_creative_associations().insert(&request, &self.opt.arg_profile_id, &self.opt.arg_campaign_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "creative-id" => { + request.creative_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaign_creative_associations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.campaign_creative_associations().list(&self.opt.arg_profile_id, &self.opt.arg_campaign_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaigns_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.campaigns().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaigns_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Campaign = Default::default(); + let mut call = self.hub.campaigns().insert(&request, &self.opt.arg_profile_id, &self.opt.arg_default_landing_page_name, &self.opt.arg_default_landing_page_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Campaign) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Campaign) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Campaign) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_optimization_configuration_init(request: &mut api::Campaign) { + if request.creative_optimization_configuration.is_none() { + request.creative_optimization_configuration = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Campaign) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Campaign) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Campaign) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Campaign) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request.end_date = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creative-optimization-configuration.optimization-model" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().optimization_model = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.id" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.name" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "id" => { + request_creative_optimization_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_creative_optimization_configuration_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "trafficker-emails" => { + request_creative_optimization_configuration_init(&mut request); + if request.trafficker_emails.is_none() { + request.trafficker_emails = Some(Default::default()); + } + request.trafficker_emails.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "archived" => { + request_creative_optimization_configuration_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "external-id" => { + request_creative_optimization_configuration_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_creative_optimization_configuration_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "billing-invoice-code" => { + request_id_dimension_value_init(&mut request); + request.billing_invoice_code = Some(value.unwrap_or("").to_string()); + }, + "comscore-vce-enabled" => { + request_id_dimension_value_init(&mut request); + request.comscore_vce_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "comscore-vce-enabled", "boolean")); + }, + "creative-group-ids" => { + request_id_dimension_value_init(&mut request); + if request.creative_group_ids.is_none() { + request.creative_group_ids = Some(Default::default()); + } + request.creative_group_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "nielsen-ocr-enabled" => { + request_lookback_configuration_init(&mut request); + request.nielsen_ocr_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "nielsen-ocr-enabled", "boolean")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaigns_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.campaigns().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "subaccount-id" => { + call = call.subaccount_id(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "overridden-event-tag-id" => { + call = call.overridden_event_tag_id(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "excluded-ids" => { + call = call.add_excluded_ids(value.unwrap_or("")); + }, + "at-least-one-optimization-activity" => { + call = call.at_least_one_optimization_activity(arg_from_str(value.unwrap_or("false"), err, "at-least-one-optimization-activity", "boolean")); + }, + "archived" => { + call = call.archived(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "advertiser-ids" => { + call = call.add_advertiser_ids(value.unwrap_or("")); + }, + "advertiser-group-ids" => { + call = call.add_advertiser_group_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaigns_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Campaign = Default::default(); + let mut call = self.hub.campaigns().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Campaign) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Campaign) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Campaign) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_optimization_configuration_init(request: &mut api::Campaign) { + if request.creative_optimization_configuration.is_none() { + request.creative_optimization_configuration = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Campaign) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Campaign) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Campaign) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Campaign) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request.end_date = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creative-optimization-configuration.optimization-model" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().optimization_model = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.id" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.name" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "id" => { + request_creative_optimization_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_creative_optimization_configuration_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "trafficker-emails" => { + request_creative_optimization_configuration_init(&mut request); + if request.trafficker_emails.is_none() { + request.trafficker_emails = Some(Default::default()); + } + request.trafficker_emails.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "archived" => { + request_creative_optimization_configuration_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "external-id" => { + request_creative_optimization_configuration_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_creative_optimization_configuration_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "billing-invoice-code" => { + request_id_dimension_value_init(&mut request); + request.billing_invoice_code = Some(value.unwrap_or("").to_string()); + }, + "comscore-vce-enabled" => { + request_id_dimension_value_init(&mut request); + request.comscore_vce_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "comscore-vce-enabled", "boolean")); + }, + "creative-group-ids" => { + request_id_dimension_value_init(&mut request); + if request.creative_group_ids.is_none() { + request.creative_group_ids = Some(Default::default()); + } + request.creative_group_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "nielsen-ocr-enabled" => { + request_lookback_configuration_init(&mut request); + request.nielsen_ocr_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "nielsen-ocr-enabled", "boolean")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _campaigns_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Campaign = Default::default(); + let mut call = self.hub.campaigns().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Campaign) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_click_through_url_suffix_properties_init(request: &mut api::Campaign) { + if request.click_through_url_suffix_properties.is_none() { + request.click_through_url_suffix_properties = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Campaign) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_creative_optimization_configuration_init(request: &mut api::Campaign) { + if request.creative_optimization_configuration.is_none() { + request.creative_optimization_configuration = Some(Default::default()); + } + } + + fn request_default_click_through_event_tag_properties_init(request: &mut api::Campaign) { + if request.default_click_through_event_tag_properties.is_none() { + request.default_click_through_event_tag_properties = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Campaign) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Campaign) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Campaign) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request.end_date = Some(value.unwrap_or("").to_string()); + }, + "click-through-url-suffix-properties.click-through-url-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().click_through_url_suffix = value.unwrap_or("").to_string(); + }, + "click-through-url-suffix-properties.override-inherited-suffix" => { + request_click_through_url_suffix_properties_init(&mut request); + request.click_through_url_suffix_properties.as_mut().unwrap().override_inherited_suffix = arg_from_str(value.unwrap_or("false"), err, "click-through-url-suffix-properties.override-inherited-suffix", "boolean"); + }, + "advertiser-id" => { + request_click_through_url_suffix_properties_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creative-optimization-configuration.optimization-model" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().optimization_model = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.id" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "creative-optimization-configuration.name" => { + request_creative_optimization_configuration_init(&mut request); + request.creative_optimization_configuration.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "id" => { + request_creative_optimization_configuration_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_creative_optimization_configuration_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "trafficker-emails" => { + request_creative_optimization_configuration_init(&mut request); + if request.trafficker_emails.is_none() { + request.trafficker_emails = Some(Default::default()); + } + request.trafficker_emails.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "archived" => { + request_creative_optimization_configuration_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "external-id" => { + request_creative_optimization_configuration_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-group-id" => { + request_creative_optimization_configuration_init(&mut request); + request.advertiser_group_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "billing-invoice-code" => { + request_id_dimension_value_init(&mut request); + request.billing_invoice_code = Some(value.unwrap_or("").to_string()); + }, + "comscore-vce-enabled" => { + request_id_dimension_value_init(&mut request); + request.comscore_vce_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "comscore-vce-enabled", "boolean")); + }, + "creative-group-ids" => { + request_id_dimension_value_init(&mut request); + if request.creative_group_ids.is_none() { + request.creative_group_ids = Some(Default::default()); + } + request.creative_group_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "default-click-through-event-tag-properties.override-inherited-event-tag" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().override_inherited_event_tag = arg_from_str(value.unwrap_or("false"), err, "default-click-through-event-tag-properties.override-inherited-event-tag", "boolean"); + }, + "default-click-through-event-tag-properties.default-click-through-event-tag-id" => { + request_default_click_through_event_tag_properties_init(&mut request); + request.default_click_through_event_tag_properties.as_mut().unwrap().default_click_through_event_tag_id = value.unwrap_or("").to_string(); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "kind" => { + request_create_info_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_create_info_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_create_info_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "nielsen-ocr-enabled" => { + request_lookback_configuration_init(&mut request); + request.nielsen_ocr_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "nielsen-ocr-enabled", "boolean")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _change_logs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.change_logs().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _change_logs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.change_logs().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-profile-ids" => { + call = call.add_user_profile_ids(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "object-type" => { + call = call.object_type(value.unwrap_or("")); + }, + "object-ids" => { + call = call.add_object_ids(value.unwrap_or("")); + }, + "min-change-time" => { + call = call.min_change_time(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-change-time" => { + call = call.max_change_time(value.unwrap_or("")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "action" => { + call = call.action(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _cities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.cities().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "region-dart-ids" => { + call = call.add_region_dart_ids(value.unwrap_or("")); + }, + "name-prefix" => { + call = call.name_prefix(value.unwrap_or("")); + }, + "dart-ids" => { + call = call.add_dart_ids(value.unwrap_or("")); + }, + "country-dart-ids" => { + call = call.add_country_dart_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _connection_types_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.connection_types().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _content_categories_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.content_categories().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _content_categories_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.content_categories().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _content_categories_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ContentCategory = Default::default(); + let mut call = self.hub.content_categories().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _content_categories_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.content_categories().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _content_categories_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ContentCategory = Default::default(); + let mut call = self.hub.content_categories().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _content_categories_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ContentCategory = Default::default(); + let mut call = self.hub.content_categories().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _countries_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.countries().get(&self.opt.arg_profile_id, &self.opt.arg_dart_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _countries_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.countries().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_assets_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeAssetMetadata = Default::default(); + let mut call = self.hub.creative_assets().insert(&request, &self.opt.arg_profile_id, &self.opt.arg_advertiser_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_asset_identifier_init(request: &mut api::CreativeAssetMetadata) { + if request.asset_identifier.is_none() { + request.asset_identifier = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "warned-validation-rules" => { + if request.warned_validation_rules.is_none() { + request.warned_validation_rules = Some(Default::default()); + } + request.warned_validation_rules.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "detected-features" => { + if request.detected_features.is_none() { + request.detected_features = Some(Default::default()); + } + request.detected_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "asset-identifier.type" => { + request_asset_identifier_init(&mut request); + request.asset_identifier.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "asset-identifier.name" => { + request_asset_identifier_init(&mut request); + request.asset_identifier.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_field_values_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_field_values().delete(&self.opt.arg_profile_id, &self.opt.arg_creative_field_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _creative_field_values_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_field_values().get(&self.opt.arg_profile_id, &self.opt.arg_creative_field_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_field_values_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeFieldValue = Default::default(); + let mut call = self.hub.creative_field_values().insert(&request, &self.opt.arg_profile_id, &self.opt.arg_creative_field_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_field_values_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_field_values().list(&self.opt.arg_profile_id, &self.opt.arg_creative_field_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_field_values_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeFieldValue = Default::default(); + let mut call = self.hub.creative_field_values().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_creative_field_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_field_values_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeFieldValue = Default::default(); + let mut call = self.hub.creative_field_values().update(&request, &self.opt.arg_profile_id, &self.opt.arg_creative_field_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_fields_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_fields().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _creative_fields_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_fields().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_fields_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeField = Default::default(); + let mut call = self.hub.creative_fields().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeField) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_fields_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_fields().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "advertiser-ids" => { + call = call.add_advertiser_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_fields_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeField = Default::default(); + let mut call = self.hub.creative_fields().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeField) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_fields_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeField = Default::default(); + let mut call = self.hub.creative_fields().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeField) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeGroup = Default::default(); + let mut call = self.hub.creative_groups().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "group-number" => { + request.group_number = Some(arg_from_str(value.unwrap_or("-0"), err, "group-number", "integer")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creative_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "group-number" => { + call = call.group_number(arg_from_str(value.unwrap_or("-0"), err, "group-number", "integer")); + }, + "advertiser-ids" => { + call = call.add_advertiser_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeGroup = Default::default(); + let mut call = self.hub.creative_groups().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "group-number" => { + request.group_number = Some(arg_from_str(value.unwrap_or("-0"), err, "group-number", "integer")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creative_groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreativeGroup = Default::default(); + let mut call = self.hub.creative_groups().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::CreativeGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "group-number" => { + request.group_number = Some(arg_from_str(value.unwrap_or("-0"), err, "group-number", "integer")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creatives().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Creative = Default::default(); + let mut call = self.hub.creatives().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_backup_image_target_window_init(request: &mut api::Creative) { + if request.backup_image_target_window.is_none() { + request.backup_image_target_window = Some(Default::default()); + } + } + + fn request_fs_command_init(request: &mut api::Creative) { + if request.fs_command.is_none() { + request.fs_command = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Creative) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Creative) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_rendering_id_dimension_value_init(request: &mut api::Creative) { + if request.rendering_id_dimension_value.is_none() { + request.rendering_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Creative) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "artwork-type" => { + request.artwork_type = Some(value.unwrap_or("").to_string()); + }, + "latest-trafficked-creative-id" => { + request.latest_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "required-flash-plugin-version" => { + request.required_flash_plugin_version = Some(value.unwrap_or("").to_string()); + }, + "fs-command.window-height" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_height = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-height", "integer"); + }, + "fs-command.top" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().top = arg_from_str(value.unwrap_or("-0"), err, "fs-command.top", "integer"); + }, + "fs-command.window-width" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_width = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-width", "integer"); + }, + "fs-command.position-option" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().position_option = value.unwrap_or("").to_string(); + }, + "fs-command.left" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().left = arg_from_str(value.unwrap_or("-0"), err, "fs-command.left", "integer"); + }, + "rendering-id-dimension-value.kind" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.value" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.dimension-name" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.etag" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.match-type" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.id" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_rendering_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "studio-trafficked-creative-id" => { + request_size_init(&mut request); + request.studio_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_size_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "override-css" => { + request_size_init(&mut request); + request.override_css = Some(value.unwrap_or("").to_string()); + }, + "required-flash-version" => { + request_size_init(&mut request); + request.required_flash_version = Some(arg_from_str(value.unwrap_or("-0"), err, "required-flash-version", "integer")); + }, + "rendering-id" => { + request_size_init(&mut request); + request.rendering_id = Some(value.unwrap_or("").to_string()); + }, + "video-description" => { + request_size_init(&mut request); + request.video_description = Some(value.unwrap_or("").to_string()); + }, + "third-party-backup-image-impressions-url" => { + request_size_init(&mut request); + request.third_party_backup_image_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_size_init(&mut request); + request.version = Some(arg_from_str(value.unwrap_or("-0"), err, "version", "integer")); + }, + "background-color" => { + request_size_init(&mut request); + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "custom-key-values" => { + request_size_init(&mut request); + if request.custom_key_values.is_none() { + request.custom_key_values = Some(Default::default()); + } + request.custom_key_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "html-code" => { + request_id_dimension_value_init(&mut request); + request.html_code = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "total-file-size" => { + request_id_dimension_value_init(&mut request); + request.total_file_size = Some(value.unwrap_or("").to_string()); + }, + "third-party-rich-media-impressions-url" => { + request_id_dimension_value_init(&mut request); + request.third_party_rich_media_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "studio-advertiser-id" => { + request_id_dimension_value_init(&mut request); + request.studio_advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "html-code-locked" => { + request_id_dimension_value_init(&mut request); + request.html_code_locked = Some(arg_from_str(value.unwrap_or("false"), err, "html-code-locked", "boolean")); + }, + "redirect-url" => { + request_id_dimension_value_init(&mut request); + request.redirect_url = Some(value.unwrap_or("").to_string()); + }, + "commercial-id" => { + request_id_dimension_value_init(&mut request); + request.commercial_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_id_dimension_value_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "backup-image-reporting-label" => { + request_id_dimension_value_init(&mut request); + request.backup_image_reporting_label = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_id_dimension_value_init(&mut request); + if request.compatibility.is_none() { + request.compatibility = Some(Default::default()); + } + request.compatibility.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "ad-parameters" => { + request_id_dimension_value_init(&mut request); + request.ad_parameters = Some(value.unwrap_or("").to_string()); + }, + "ad-tag-keys" => { + request_id_dimension_value_init(&mut request); + if request.ad_tag_keys.is_none() { + request.ad_tag_keys = Some(Default::default()); + } + request.ad_tag_keys.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "video-duration" => { + request_id_dimension_value_init(&mut request); + request.video_duration = Some(arg_from_str(value.unwrap_or("0.0"), err, "video-duration", "number")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "backup-image-click-through-url" => { + request_last_modified_info_init(&mut request); + request.backup_image_click_through_url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "studio-creative-id" => { + request_last_modified_info_init(&mut request); + request.studio_creative_id = Some(value.unwrap_or("").to_string()); + }, + "authoring-tool" => { + request_last_modified_info_init(&mut request); + request.authoring_tool = Some(value.unwrap_or("").to_string()); + }, + "allow-script-access" => { + request_last_modified_info_init(&mut request); + request.allow_script_access = Some(arg_from_str(value.unwrap_or("false"), err, "allow-script-access", "boolean")); + }, + "companion-creatives" => { + request_last_modified_info_init(&mut request); + if request.companion_creatives.is_none() { + request.companion_creatives = Some(Default::default()); + } + request.companion_creatives.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "auto-advance-images" => { + request_last_modified_info_init(&mut request); + request.auto_advance_images = Some(arg_from_str(value.unwrap_or("false"), err, "auto-advance-images", "boolean")); + }, + "backup-image-features" => { + request_last_modified_info_init(&mut request); + if request.backup_image_features.is_none() { + request.backup_image_features = Some(Default::default()); + } + request.backup_image_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "backup-image-target-window.custom-html" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().custom_html = value.unwrap_or("").to_string(); + }, + "backup-image-target-window.target-window-option" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().target_window_option = value.unwrap_or("").to_string(); + }, + "skippable" => { + request_backup_image_target_window_init(&mut request); + request.skippable = Some(arg_from_str(value.unwrap_or("false"), err, "skippable", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.creatives().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "types" => { + call = call.add_types(value.unwrap_or("")); + }, + "studio-creative-id" => { + call = call.studio_creative_id(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "size-ids" => { + call = call.add_size_ids(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "rendering-ids" => { + call = call.add_rendering_ids(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "creative-field-ids" => { + call = call.add_creative_field_ids(value.unwrap_or("")); + }, + "companion-creative-ids" => { + call = call.add_companion_creative_ids(value.unwrap_or("")); + }, + "campaign-id" => { + call = call.campaign_id(value.unwrap_or("")); + }, + "archived" => { + call = call.archived(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "active" => { + call = call.active(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Creative = Default::default(); + let mut call = self.hub.creatives().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_backup_image_target_window_init(request: &mut api::Creative) { + if request.backup_image_target_window.is_none() { + request.backup_image_target_window = Some(Default::default()); + } + } + + fn request_fs_command_init(request: &mut api::Creative) { + if request.fs_command.is_none() { + request.fs_command = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Creative) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Creative) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_rendering_id_dimension_value_init(request: &mut api::Creative) { + if request.rendering_id_dimension_value.is_none() { + request.rendering_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Creative) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "artwork-type" => { + request.artwork_type = Some(value.unwrap_or("").to_string()); + }, + "latest-trafficked-creative-id" => { + request.latest_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "required-flash-plugin-version" => { + request.required_flash_plugin_version = Some(value.unwrap_or("").to_string()); + }, + "fs-command.window-height" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_height = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-height", "integer"); + }, + "fs-command.top" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().top = arg_from_str(value.unwrap_or("-0"), err, "fs-command.top", "integer"); + }, + "fs-command.window-width" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_width = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-width", "integer"); + }, + "fs-command.position-option" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().position_option = value.unwrap_or("").to_string(); + }, + "fs-command.left" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().left = arg_from_str(value.unwrap_or("-0"), err, "fs-command.left", "integer"); + }, + "rendering-id-dimension-value.kind" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.value" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.dimension-name" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.etag" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.match-type" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.id" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_rendering_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "studio-trafficked-creative-id" => { + request_size_init(&mut request); + request.studio_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_size_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "override-css" => { + request_size_init(&mut request); + request.override_css = Some(value.unwrap_or("").to_string()); + }, + "required-flash-version" => { + request_size_init(&mut request); + request.required_flash_version = Some(arg_from_str(value.unwrap_or("-0"), err, "required-flash-version", "integer")); + }, + "rendering-id" => { + request_size_init(&mut request); + request.rendering_id = Some(value.unwrap_or("").to_string()); + }, + "video-description" => { + request_size_init(&mut request); + request.video_description = Some(value.unwrap_or("").to_string()); + }, + "third-party-backup-image-impressions-url" => { + request_size_init(&mut request); + request.third_party_backup_image_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_size_init(&mut request); + request.version = Some(arg_from_str(value.unwrap_or("-0"), err, "version", "integer")); + }, + "background-color" => { + request_size_init(&mut request); + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "custom-key-values" => { + request_size_init(&mut request); + if request.custom_key_values.is_none() { + request.custom_key_values = Some(Default::default()); + } + request.custom_key_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "html-code" => { + request_id_dimension_value_init(&mut request); + request.html_code = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "total-file-size" => { + request_id_dimension_value_init(&mut request); + request.total_file_size = Some(value.unwrap_or("").to_string()); + }, + "third-party-rich-media-impressions-url" => { + request_id_dimension_value_init(&mut request); + request.third_party_rich_media_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "studio-advertiser-id" => { + request_id_dimension_value_init(&mut request); + request.studio_advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "html-code-locked" => { + request_id_dimension_value_init(&mut request); + request.html_code_locked = Some(arg_from_str(value.unwrap_or("false"), err, "html-code-locked", "boolean")); + }, + "redirect-url" => { + request_id_dimension_value_init(&mut request); + request.redirect_url = Some(value.unwrap_or("").to_string()); + }, + "commercial-id" => { + request_id_dimension_value_init(&mut request); + request.commercial_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_id_dimension_value_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "backup-image-reporting-label" => { + request_id_dimension_value_init(&mut request); + request.backup_image_reporting_label = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_id_dimension_value_init(&mut request); + if request.compatibility.is_none() { + request.compatibility = Some(Default::default()); + } + request.compatibility.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "ad-parameters" => { + request_id_dimension_value_init(&mut request); + request.ad_parameters = Some(value.unwrap_or("").to_string()); + }, + "ad-tag-keys" => { + request_id_dimension_value_init(&mut request); + if request.ad_tag_keys.is_none() { + request.ad_tag_keys = Some(Default::default()); + } + request.ad_tag_keys.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "video-duration" => { + request_id_dimension_value_init(&mut request); + request.video_duration = Some(arg_from_str(value.unwrap_or("0.0"), err, "video-duration", "number")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "backup-image-click-through-url" => { + request_last_modified_info_init(&mut request); + request.backup_image_click_through_url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "studio-creative-id" => { + request_last_modified_info_init(&mut request); + request.studio_creative_id = Some(value.unwrap_or("").to_string()); + }, + "authoring-tool" => { + request_last_modified_info_init(&mut request); + request.authoring_tool = Some(value.unwrap_or("").to_string()); + }, + "allow-script-access" => { + request_last_modified_info_init(&mut request); + request.allow_script_access = Some(arg_from_str(value.unwrap_or("false"), err, "allow-script-access", "boolean")); + }, + "companion-creatives" => { + request_last_modified_info_init(&mut request); + if request.companion_creatives.is_none() { + request.companion_creatives = Some(Default::default()); + } + request.companion_creatives.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "auto-advance-images" => { + request_last_modified_info_init(&mut request); + request.auto_advance_images = Some(arg_from_str(value.unwrap_or("false"), err, "auto-advance-images", "boolean")); + }, + "backup-image-features" => { + request_last_modified_info_init(&mut request); + if request.backup_image_features.is_none() { + request.backup_image_features = Some(Default::default()); + } + request.backup_image_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "backup-image-target-window.custom-html" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().custom_html = value.unwrap_or("").to_string(); + }, + "backup-image-target-window.target-window-option" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().target_window_option = value.unwrap_or("").to_string(); + }, + "skippable" => { + request_backup_image_target_window_init(&mut request); + request.skippable = Some(arg_from_str(value.unwrap_or("false"), err, "skippable", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _creatives_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Creative = Default::default(); + let mut call = self.hub.creatives().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_backup_image_target_window_init(request: &mut api::Creative) { + if request.backup_image_target_window.is_none() { + request.backup_image_target_window = Some(Default::default()); + } + } + + fn request_fs_command_init(request: &mut api::Creative) { + if request.fs_command.is_none() { + request.fs_command = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Creative) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Creative) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_rendering_id_dimension_value_init(request: &mut api::Creative) { + if request.rendering_id_dimension_value.is_none() { + request.rendering_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Creative) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "artwork-type" => { + request.artwork_type = Some(value.unwrap_or("").to_string()); + }, + "latest-trafficked-creative-id" => { + request.latest_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "required-flash-plugin-version" => { + request.required_flash_plugin_version = Some(value.unwrap_or("").to_string()); + }, + "fs-command.window-height" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_height = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-height", "integer"); + }, + "fs-command.top" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().top = arg_from_str(value.unwrap_or("-0"), err, "fs-command.top", "integer"); + }, + "fs-command.window-width" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().window_width = arg_from_str(value.unwrap_or("-0"), err, "fs-command.window-width", "integer"); + }, + "fs-command.position-option" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().position_option = value.unwrap_or("").to_string(); + }, + "fs-command.left" => { + request_fs_command_init(&mut request); + request.fs_command.as_mut().unwrap().left = arg_from_str(value.unwrap_or("-0"), err, "fs-command.left", "integer"); + }, + "rendering-id-dimension-value.kind" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.value" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.dimension-name" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.etag" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.match-type" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "rendering-id-dimension-value.id" => { + request_rendering_id_dimension_value_init(&mut request); + request.rendering_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_rendering_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "studio-trafficked-creative-id" => { + request_size_init(&mut request); + request.studio_trafficked_creative_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_size_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "override-css" => { + request_size_init(&mut request); + request.override_css = Some(value.unwrap_or("").to_string()); + }, + "required-flash-version" => { + request_size_init(&mut request); + request.required_flash_version = Some(arg_from_str(value.unwrap_or("-0"), err, "required-flash-version", "integer")); + }, + "rendering-id" => { + request_size_init(&mut request); + request.rendering_id = Some(value.unwrap_or("").to_string()); + }, + "video-description" => { + request_size_init(&mut request); + request.video_description = Some(value.unwrap_or("").to_string()); + }, + "third-party-backup-image-impressions-url" => { + request_size_init(&mut request); + request.third_party_backup_image_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_size_init(&mut request); + request.version = Some(arg_from_str(value.unwrap_or("-0"), err, "version", "integer")); + }, + "background-color" => { + request_size_init(&mut request); + request.background_color = Some(value.unwrap_or("").to_string()); + }, + "custom-key-values" => { + request_size_init(&mut request); + if request.custom_key_values.is_none() { + request.custom_key_values = Some(Default::default()); + } + request.custom_key_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "html-code" => { + request_id_dimension_value_init(&mut request); + request.html_code = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "total-file-size" => { + request_id_dimension_value_init(&mut request); + request.total_file_size = Some(value.unwrap_or("").to_string()); + }, + "third-party-rich-media-impressions-url" => { + request_id_dimension_value_init(&mut request); + request.third_party_rich_media_impressions_url = Some(value.unwrap_or("").to_string()); + }, + "studio-advertiser-id" => { + request_id_dimension_value_init(&mut request); + request.studio_advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "html-code-locked" => { + request_id_dimension_value_init(&mut request); + request.html_code_locked = Some(arg_from_str(value.unwrap_or("false"), err, "html-code-locked", "boolean")); + }, + "redirect-url" => { + request_id_dimension_value_init(&mut request); + request.redirect_url = Some(value.unwrap_or("").to_string()); + }, + "commercial-id" => { + request_id_dimension_value_init(&mut request); + request.commercial_id = Some(value.unwrap_or("").to_string()); + }, + "active" => { + request_id_dimension_value_init(&mut request); + request.active = Some(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "backup-image-reporting-label" => { + request_id_dimension_value_init(&mut request); + request.backup_image_reporting_label = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_id_dimension_value_init(&mut request); + if request.compatibility.is_none() { + request.compatibility = Some(Default::default()); + } + request.compatibility.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "ad-parameters" => { + request_id_dimension_value_init(&mut request); + request.ad_parameters = Some(value.unwrap_or("").to_string()); + }, + "ad-tag-keys" => { + request_id_dimension_value_init(&mut request); + if request.ad_tag_keys.is_none() { + request.ad_tag_keys = Some(Default::default()); + } + request.ad_tag_keys.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "video-duration" => { + request_id_dimension_value_init(&mut request); + request.video_duration = Some(arg_from_str(value.unwrap_or("0.0"), err, "video-duration", "number")); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "backup-image-click-through-url" => { + request_last_modified_info_init(&mut request); + request.backup_image_click_through_url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_last_modified_info_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "studio-creative-id" => { + request_last_modified_info_init(&mut request); + request.studio_creative_id = Some(value.unwrap_or("").to_string()); + }, + "authoring-tool" => { + request_last_modified_info_init(&mut request); + request.authoring_tool = Some(value.unwrap_or("").to_string()); + }, + "allow-script-access" => { + request_last_modified_info_init(&mut request); + request.allow_script_access = Some(arg_from_str(value.unwrap_or("false"), err, "allow-script-access", "boolean")); + }, + "companion-creatives" => { + request_last_modified_info_init(&mut request); + if request.companion_creatives.is_none() { + request.companion_creatives = Some(Default::default()); + } + request.companion_creatives.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "auto-advance-images" => { + request_last_modified_info_init(&mut request); + request.auto_advance_images = Some(arg_from_str(value.unwrap_or("false"), err, "auto-advance-images", "boolean")); + }, + "backup-image-features" => { + request_last_modified_info_init(&mut request); + if request.backup_image_features.is_none() { + request.backup_image_features = Some(Default::default()); + } + request.backup_image_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "backup-image-target-window.custom-html" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().custom_html = value.unwrap_or("").to_string(); + }, + "backup-image-target-window.target-window-option" => { + request_backup_image_target_window_init(&mut request); + request.backup_image_target_window.as_mut().unwrap().target_window_option = value.unwrap_or("").to_string(); + }, + "skippable" => { + request_backup_image_target_window_init(&mut request); + request.skippable = Some(arg_from_str(value.unwrap_or("false"), err, "skippable", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _dimension_values_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DimensionValueRequest = Default::default(); + let mut call = self.hub.dimension_values().query(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "dimension-name" => { + request.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request.end_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _directory_site_contacts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.directory_site_contacts().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _directory_site_contacts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.directory_site_contacts().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "directory-site-ids" => { + call = call.add_directory_site_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _directory_sites_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.directory_sites().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _directory_sites_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.directory_sites().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "parent-id" => { + call = call.parent_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "dfp-network-code" => { + call = call.dfp_network_code(value.unwrap_or("")); + }, + "country-id" => { + call = call.country_id(value.unwrap_or("")); + }, + "active" => { + call = call.active(arg_from_str(value.unwrap_or("false"), err, "active", "boolean")); + }, + "accepts-publisher-paid-placements" => { + call = call.accepts_publisher_paid_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-publisher-paid-placements", "boolean")); + }, + "accepts-interstitial-placements" => { + call = call.accepts_interstitial_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-interstitial-placements", "boolean")); + }, + "accepts-in-stream-video-placements" => { + call = call.accepts_in_stream_video_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-in-stream-video-placements", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _event_tags_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.event_tags().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _event_tags_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.event_tags().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _event_tags_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::EventTag = Default::default(); + let mut call = self.hub.event_tags().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::EventTag) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::EventTag) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "site-ids" => { + if request.site_ids.is_none() { + request.site_ids = Some(Default::default()); + } + request.site_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "url-escape-levels" => { + request.url_escape_levels = Some(arg_from_str(value.unwrap_or("-0"), err, "url-escape-levels", "integer")); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "enabled-by-default" => { + request_campaign_id_dimension_value_init(&mut request); + request.enabled_by_default = Some(arg_from_str(value.unwrap_or("false"), err, "enabled-by-default", "boolean")); + }, + "advertiser-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "site-filter-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.site_filter_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _event_tags_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.event_tags().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "event-tag-types" => { + call = call.add_event_tag_types(value.unwrap_or("")); + }, + "enabled" => { + call = call.enabled(arg_from_str(value.unwrap_or("false"), err, "enabled", "boolean")); + }, + "definitions-only" => { + call = call.definitions_only(arg_from_str(value.unwrap_or("false"), err, "definitions-only", "boolean")); + }, + "campaign-id" => { + call = call.campaign_id(value.unwrap_or("")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "ad-id" => { + call = call.ad_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _event_tags_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::EventTag = Default::default(); + let mut call = self.hub.event_tags().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::EventTag) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::EventTag) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "site-ids" => { + if request.site_ids.is_none() { + request.site_ids = Some(Default::default()); + } + request.site_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "url-escape-levels" => { + request.url_escape_levels = Some(arg_from_str(value.unwrap_or("-0"), err, "url-escape-levels", "integer")); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "enabled-by-default" => { + request_campaign_id_dimension_value_init(&mut request); + request.enabled_by_default = Some(arg_from_str(value.unwrap_or("false"), err, "enabled-by-default", "boolean")); + }, + "advertiser-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "site-filter-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.site_filter_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _event_tags_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::EventTag = Default::default(); + let mut call = self.hub.event_tags().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::EventTag) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::EventTag) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "site-ids" => { + if request.site_ids.is_none() { + request.site_ids = Some(Default::default()); + } + request.site_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "url-escape-levels" => { + request.url_escape_levels = Some(arg_from_str(value.unwrap_or("-0"), err, "url-escape-levels", "integer")); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "enabled-by-default" => { + request_campaign_id_dimension_value_init(&mut request); + request.enabled_by_default = Some(arg_from_str(value.unwrap_or("false"), err, "enabled-by-default", "boolean")); + }, + "advertiser-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "site-filter-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.site_filter_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.files().get(&self.opt.arg_report_id, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _files_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "scope" => { + call = call.scope(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activities().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _floodlight_activities_generatetag(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activities().generatetag(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "floodlight-activity-id" => { + call = call.floodlight_activity_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activities().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivity = Default::default(); + let mut call = self.hub.floodlight_activities().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "tag-string" => { + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "secure" => { + request.secure = Some(arg_from_str(value.unwrap_or("false"), err, "secure", "boolean")); + }, + "floodlight-activity-group-name" => { + request.floodlight_activity_group_name = Some(value.unwrap_or("").to_string()); + }, + "image-tag-enabled" => { + request.image_tag_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "image-tag-enabled", "boolean")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_tag_string = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_advertiser_id_dimension_value_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "cache-busting-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.cache_busting_type = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "account-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "expected-url" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.expected_url = Some(value.unwrap_or("").to_string()); + }, + "tag-format" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.tag_format = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "user-defined-variable-types" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + if request.user_defined_variable_types.is_none() { + request.user_defined_variable_types = Some(Default::default()); + } + request.user_defined_variable_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "counting-method" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.counting_method = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-type" => { + request_id_dimension_value_init(&mut request); + request.floodlight_activity_group_type = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activities().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tag-string" => { + call = call.tag_string(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "floodlight-configuration-id" => { + call = call.floodlight_configuration_id(value.unwrap_or("")); + }, + "floodlight-activity-group-type" => { + call = call.floodlight_activity_group_type(value.unwrap_or("")); + }, + "floodlight-activity-group-tag-string" => { + call = call.floodlight_activity_group_tag_string(value.unwrap_or("")); + }, + "floodlight-activity-group-name" => { + call = call.floodlight_activity_group_name(value.unwrap_or("")); + }, + "floodlight-activity-group-ids" => { + call = call.add_floodlight_activity_group_ids(value.unwrap_or("")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivity = Default::default(); + let mut call = self.hub.floodlight_activities().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "tag-string" => { + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "secure" => { + request.secure = Some(arg_from_str(value.unwrap_or("false"), err, "secure", "boolean")); + }, + "floodlight-activity-group-name" => { + request.floodlight_activity_group_name = Some(value.unwrap_or("").to_string()); + }, + "image-tag-enabled" => { + request.image_tag_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "image-tag-enabled", "boolean")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_tag_string = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_advertiser_id_dimension_value_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "cache-busting-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.cache_busting_type = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "account-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "expected-url" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.expected_url = Some(value.unwrap_or("").to_string()); + }, + "tag-format" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.tag_format = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "user-defined-variable-types" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + if request.user_defined_variable_types.is_none() { + request.user_defined_variable_types = Some(Default::default()); + } + request.user_defined_variable_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "counting-method" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.counting_method = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-type" => { + request_id_dimension_value_init(&mut request); + request.floodlight_activity_group_type = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activities_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivity = Default::default(); + let mut call = self.hub.floodlight_activities().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivity) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "tag-string" => { + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "secure" => { + request.secure = Some(arg_from_str(value.unwrap_or("false"), err, "secure", "boolean")); + }, + "floodlight-activity-group-name" => { + request.floodlight_activity_group_name = Some(value.unwrap_or("").to_string()); + }, + "image-tag-enabled" => { + request.image_tag_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "image-tag-enabled", "boolean")); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.floodlight_activity_group_tag_string = Some(value.unwrap_or("").to_string()); + }, + "ssl-compliant" => { + request_advertiser_id_dimension_value_init(&mut request); + request.ssl_compliant = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-compliant", "boolean")); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "cache-busting-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.cache_busting_type = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "account-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "expected-url" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.expected_url = Some(value.unwrap_or("").to_string()); + }, + "tag-format" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.tag_format = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "user-defined-variable-types" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + if request.user_defined_variable_types.is_none() { + request.user_defined_variable_types = Some(Default::default()); + } + request.user_defined_variable_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "counting-method" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.counting_method = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-activity-group-type" => { + request_id_dimension_value_init(&mut request); + request.floodlight_activity_group_type = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activity_groups_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activity_groups().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _floodlight_activity_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activity_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activity_groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivityGroup = Default::default(); + let mut call = self.hub.floodlight_activity_groups().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activity_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_activity_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "floodlight-configuration-id" => { + call = call.floodlight_configuration_id(value.unwrap_or("")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activity_groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivityGroup = Default::default(); + let mut call = self.hub.floodlight_activity_groups().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_activity_groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightActivityGroup = Default::default(); + let mut call = self.hub.floodlight_activity_groups().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_floodlight_configuration_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.floodlight_configuration_id_dimension_value.is_none() { + request.floodlight_configuration_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightActivityGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id" => { + request.floodlight_configuration_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.kind" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.value" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.dimension-name" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.etag" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.match-type" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-configuration-id-dimension-value.id" => { + request_floodlight_configuration_id_dimension_value_init(&mut request); + request.floodlight_configuration_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "tag-string" => { + request_advertiser_id_dimension_value_init(&mut request); + request.tag_string = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_configurations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_configurations().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_configurations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.floodlight_configurations().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_configurations_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightConfiguration = Default::default(); + let mut call = self.hub.floodlight_configurations().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightConfiguration) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightConfiguration) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::FloodlightConfiguration) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + fn request_omniture_settings_init(request: &mut api::FloodlightConfiguration) { + if request.omniture_settings.is_none() { + request.omniture_settings = Some(Default::default()); + } + } + + fn request_tag_settings_init(request: &mut api::FloodlightConfiguration) { + if request.tag_settings.is_none() { + request.tag_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "natural-search-conversion-attribution-option" => { + request.natural_search_conversion_attribution_option = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "exposure-to-conversion-enabled" => { + request.exposure_to_conversion_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "exposure-to-conversion-enabled", "boolean")); + }, + "analytics-data-sharing-enabled" => { + request.analytics_data_sharing_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "analytics-data-sharing-enabled", "boolean")); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "first-day-of-week" => { + request_lookback_configuration_init(&mut request); + request.first_day_of_week = Some(value.unwrap_or("").to_string()); + }, + "standard-variable-types" => { + request_lookback_configuration_init(&mut request); + if request.standard_variable_types.is_none() { + request.standard_variable_types = Some(Default::default()); + } + request.standard_variable_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "omniture-settings.omniture-cost-data-enabled" => { + request_omniture_settings_init(&mut request); + request.omniture_settings.as_mut().unwrap().omniture_cost_data_enabled = arg_from_str(value.unwrap_or("false"), err, "omniture-settings.omniture-cost-data-enabled", "boolean"); + }, + "omniture-settings.omniture-integration-enabled" => { + request_omniture_settings_init(&mut request); + request.omniture_settings.as_mut().unwrap().omniture_integration_enabled = arg_from_str(value.unwrap_or("false"), err, "omniture-settings.omniture-integration-enabled", "boolean"); + }, + "subaccount-id" => { + request_omniture_settings_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_omniture_settings_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "tag-settings.dynamic-tag-enabled" => { + request_tag_settings_init(&mut request); + request.tag_settings.as_mut().unwrap().dynamic_tag_enabled = arg_from_str(value.unwrap_or("false"), err, "tag-settings.dynamic-tag-enabled", "boolean"); + }, + "tag-settings.image-tag-enabled" => { + request_tag_settings_init(&mut request); + request.tag_settings.as_mut().unwrap().image_tag_enabled = arg_from_str(value.unwrap_or("false"), err, "tag-settings.image-tag-enabled", "boolean"); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_advertiser_id_dimension_value_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _floodlight_configurations_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FloodlightConfiguration = Default::default(); + let mut call = self.hub.floodlight_configurations().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::FloodlightConfiguration) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::FloodlightConfiguration) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::FloodlightConfiguration) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + fn request_omniture_settings_init(request: &mut api::FloodlightConfiguration) { + if request.omniture_settings.is_none() { + request.omniture_settings = Some(Default::default()); + } + } + + fn request_tag_settings_init(request: &mut api::FloodlightConfiguration) { + if request.tag_settings.is_none() { + request.tag_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "natural-search-conversion-attribution-option" => { + request.natural_search_conversion_attribution_option = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "exposure-to-conversion-enabled" => { + request.exposure_to_conversion_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "exposure-to-conversion-enabled", "boolean")); + }, + "analytics-data-sharing-enabled" => { + request.analytics_data_sharing_enabled = Some(arg_from_str(value.unwrap_or("false"), err, "analytics-data-sharing-enabled", "boolean")); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "first-day-of-week" => { + request_lookback_configuration_init(&mut request); + request.first_day_of_week = Some(value.unwrap_or("").to_string()); + }, + "standard-variable-types" => { + request_lookback_configuration_init(&mut request); + if request.standard_variable_types.is_none() { + request.standard_variable_types = Some(Default::default()); + } + request.standard_variable_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "omniture-settings.omniture-cost-data-enabled" => { + request_omniture_settings_init(&mut request); + request.omniture_settings.as_mut().unwrap().omniture_cost_data_enabled = arg_from_str(value.unwrap_or("false"), err, "omniture-settings.omniture-cost-data-enabled", "boolean"); + }, + "omniture-settings.omniture-integration-enabled" => { + request_omniture_settings_init(&mut request); + request.omniture_settings.as_mut().unwrap().omniture_integration_enabled = arg_from_str(value.unwrap_or("false"), err, "omniture-settings.omniture-integration-enabled", "boolean"); + }, + "subaccount-id" => { + request_omniture_settings_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_omniture_settings_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "tag-settings.dynamic-tag-enabled" => { + request_tag_settings_init(&mut request); + request.tag_settings.as_mut().unwrap().dynamic_tag_enabled = arg_from_str(value.unwrap_or("false"), err, "tag-settings.dynamic-tag-enabled", "boolean"); + }, + "tag-settings.image-tag-enabled" => { + request_tag_settings_init(&mut request); + request.tag_settings.as_mut().unwrap().image_tag_enabled = arg_from_str(value.unwrap_or("false"), err, "tag-settings.image-tag-enabled", "boolean"); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "ssl-required" => { + request_advertiser_id_dimension_value_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _landing_pages_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.landing_pages().delete(&self.opt.arg_profile_id, &self.opt.arg_campaign_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _landing_pages_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.landing_pages().get(&self.opt.arg_profile_id, &self.opt.arg_campaign_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _landing_pages_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LandingPage = Default::default(); + let mut call = self.hub.landing_pages().insert(&request, &self.opt.arg_profile_id, &self.opt.arg_campaign_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default" => { + request.default = Some(arg_from_str(value.unwrap_or("false"), err, "default", "boolean")); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _landing_pages_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.landing_pages().list(&self.opt.arg_profile_id, &self.opt.arg_campaign_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _landing_pages_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LandingPage = Default::default(); + let mut call = self.hub.landing_pages().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_campaign_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default" => { + request.default = Some(arg_from_str(value.unwrap_or("false"), err, "default", "boolean")); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _landing_pages_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LandingPage = Default::default(); + let mut call = self.hub.landing_pages().update(&request, &self.opt.arg_profile_id, &self.opt.arg_campaign_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default" => { + request.default = Some(arg_from_str(value.unwrap_or("false"), err, "default", "boolean")); + }, + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metros_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.metros().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _mobile_carriers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.mobile_carriers().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operating_system_versions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operating_system_versions().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operating_systems_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operating_systems().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placement_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementGroup = Default::default(); + let mut call = self.hub.placement_groups().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::PlacementGroup) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::PlacementGroup) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::PlacementGroup) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_primary_placement_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.primary_placement_id_dimension_value.is_none() { + request.primary_placement_id_dimension_value = Some(Default::default()); + } + } + + fn request_programmatic_setting_init(request: &mut api::PlacementGroup) { + if request.programmatic_setting.is_none() { + request.programmatic_setting = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id" => { + request.primary_placement_id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.placement_group_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "programmatic-setting.trafficker-emails" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().trafficker_emails.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.programmatic" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().programmatic = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.programmatic", "boolean"); + }, + "programmatic-setting.insertion-order-id" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id = value.unwrap_or("").to_string(); + }, + "programmatic-setting.insertion-order-id-status" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id_status = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.insertion-order-id-status", "boolean"); + }, + "programmatic-setting.adx-deal-ids" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().adx_deal_ids.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.media-cost-nanos" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().media_cost_nanos = value.unwrap_or("").to_string(); + }, + "archived" => { + request_programmatic_setting_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "child-placement-ids" => { + request_programmatic_setting_init(&mut request); + if request.child_placement_ids.is_none() { + request.child_placement_ids = Some(Default::default()); + } + request.child_placement_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "content-category-id" => { + request_programmatic_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_programmatic_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.kind" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.value" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.dimension-name" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.etag" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.match-type" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.id" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_site_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_site_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_site_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placement_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "site-ids" => { + call = call.add_site_ids(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "pricing-types" => { + call = call.add_pricing_types(value.unwrap_or("")); + }, + "placement-strategy-ids" => { + call = call.add_placement_strategy_ids(value.unwrap_or("")); + }, + "placement-group-type" => { + call = call.placement_group_type(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "directory-site-ids" => { + call = call.add_directory_site_ids(value.unwrap_or("")); + }, + "content-category-ids" => { + call = call.add_content_category_ids(value.unwrap_or("")); + }, + "campaign-ids" => { + call = call.add_campaign_ids(value.unwrap_or("")); + }, + "archived" => { + call = call.archived(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "advertiser-ids" => { + call = call.add_advertiser_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementGroup = Default::default(); + let mut call = self.hub.placement_groups().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::PlacementGroup) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::PlacementGroup) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::PlacementGroup) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_primary_placement_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.primary_placement_id_dimension_value.is_none() { + request.primary_placement_id_dimension_value = Some(Default::default()); + } + } + + fn request_programmatic_setting_init(request: &mut api::PlacementGroup) { + if request.programmatic_setting.is_none() { + request.programmatic_setting = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id" => { + request.primary_placement_id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.placement_group_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "programmatic-setting.trafficker-emails" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().trafficker_emails.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.programmatic" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().programmatic = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.programmatic", "boolean"); + }, + "programmatic-setting.insertion-order-id" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id = value.unwrap_or("").to_string(); + }, + "programmatic-setting.insertion-order-id-status" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id_status = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.insertion-order-id-status", "boolean"); + }, + "programmatic-setting.adx-deal-ids" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().adx_deal_ids.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.media-cost-nanos" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().media_cost_nanos = value.unwrap_or("").to_string(); + }, + "archived" => { + request_programmatic_setting_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "child-placement-ids" => { + request_programmatic_setting_init(&mut request); + if request.child_placement_ids.is_none() { + request.child_placement_ids = Some(Default::default()); + } + request.child_placement_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "content-category-id" => { + request_programmatic_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_programmatic_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.kind" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.value" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.dimension-name" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.etag" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.match-type" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.id" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_site_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_site_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_site_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementGroup = Default::default(); + let mut call = self.hub.placement_groups().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::PlacementGroup) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::PlacementGroup) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::PlacementGroup) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_primary_placement_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.primary_placement_id_dimension_value.is_none() { + request.primary_placement_id_dimension_value = Some(Default::default()); + } + } + + fn request_programmatic_setting_init(request: &mut api::PlacementGroup) { + if request.programmatic_setting.is_none() { + request.programmatic_setting = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::PlacementGroup) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id" => { + request.primary_placement_id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.placement_group_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "programmatic-setting.trafficker-emails" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().trafficker_emails.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.programmatic" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().programmatic = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.programmatic", "boolean"); + }, + "programmatic-setting.insertion-order-id" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id = value.unwrap_or("").to_string(); + }, + "programmatic-setting.insertion-order-id-status" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().insertion_order_id_status = arg_from_str(value.unwrap_or("false"), err, "programmatic-setting.insertion-order-id-status", "boolean"); + }, + "programmatic-setting.adx-deal-ids" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().adx_deal_ids.push(value.unwrap_or("").to_string()); + }, + "programmatic-setting.media-cost-nanos" => { + request_programmatic_setting_init(&mut request); + request.programmatic_setting.as_mut().unwrap().media_cost_nanos = value.unwrap_or("").to_string(); + }, + "archived" => { + request_programmatic_setting_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "child-placement-ids" => { + request_programmatic_setting_init(&mut request); + if request.child_placement_ids.is_none() { + request.child_placement_ids = Some(Default::default()); + } + request.child_placement_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "content-category-id" => { + request_programmatic_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_programmatic_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.kind" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.value" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.dimension-name" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.etag" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.match-type" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "primary-placement-id-dimension-value.id" => { + request_primary_placement_id_dimension_value_init(&mut request); + request.primary_placement_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_site_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_site_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_site_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_strategies_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placement_strategies().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _placement_strategies_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placement_strategies().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_strategies_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementStrategy = Default::default(); + let mut call = self.hub.placement_strategies().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_strategies_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placement_strategies().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_strategies_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementStrategy = Default::default(); + let mut call = self.hub.placement_strategies().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placement_strategies_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlacementStrategy = Default::default(); + let mut call = self.hub.placement_strategies().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_generatetags(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placements().generatetags(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tag-formats" => { + call = call.add_tag_formats(value.unwrap_or("")); + }, + "placement-ids" => { + call = call.add_placement_ids(value.unwrap_or("")); + }, + "campaign-id" => { + call = call.campaign_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placements().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Placement = Default::default(); + let mut call = self.hub.placements().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Placement) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Placement) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Placement) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::Placement) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Placement) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Placement) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Placement) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + fn request_placement_group_id_dimension_value_init(request: &mut api::Placement) { + if request.placement_group_id_dimension_value.is_none() { + request.placement_group_id_dimension_value = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::Placement) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_publisher_update_info_init(request: &mut api::Placement) { + if request.publisher_update_info.is_none() { + request.publisher_update_info = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::Placement) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Placement) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + fn request_tag_setting_init(request: &mut api::Placement) { + if request.tag_setting.is_none() { + request.tag_setting = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "payment-source" => { + request.payment_source = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_advertiser_id_dimension_value_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "publisher-update-info.time" => { + request_publisher_update_info_init(&mut request); + request.publisher_update_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "tag-formats" => { + request_publisher_update_info_init(&mut request); + if request.tag_formats.is_none() { + request.tag_formats = Some(Default::default()); + } + request.tag_formats.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "payment-approved" => { + request_publisher_update_info_init(&mut request); + request.payment_approved = Some(arg_from_str(value.unwrap_or("false"), err, "payment-approved", "boolean")); + }, + "tag-setting.include-click-through-urls" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-through-urls", "boolean"); + }, + "tag-setting.include-click-tracking" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-tracking", "boolean"); + }, + "tag-setting.additional-key-values" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().additional_key_values = value.unwrap_or("").to_string(); + }, + "tag-setting.keyword-option" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().keyword_option = value.unwrap_or("").to_string(); + }, + "content-category-id" => { + request_tag_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_tag_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "status" => { + request_size_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary" => { + request_campaign_id_dimension_value_init(&mut request); + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "placement-group-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.placement_group_id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_site_id_dimension_value_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.value" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.dimension-name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.etag" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.match-type" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.placements().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "size-ids" => { + call = call.add_size_ids(value.unwrap_or("")); + }, + "site-ids" => { + call = call.add_site_ids(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "pricing-types" => { + call = call.add_pricing_types(value.unwrap_or("")); + }, + "placement-strategy-ids" => { + call = call.add_placement_strategy_ids(value.unwrap_or("")); + }, + "payment-source" => { + call = call.payment_source(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "group-ids" => { + call = call.add_group_ids(value.unwrap_or("")); + }, + "directory-site-ids" => { + call = call.add_directory_site_ids(value.unwrap_or("")); + }, + "content-category-ids" => { + call = call.add_content_category_ids(value.unwrap_or("")); + }, + "compatibilities" => { + call = call.add_compatibilities(value.unwrap_or("")); + }, + "campaign-ids" => { + call = call.add_campaign_ids(value.unwrap_or("")); + }, + "archived" => { + call = call.archived(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "advertiser-ids" => { + call = call.add_advertiser_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Placement = Default::default(); + let mut call = self.hub.placements().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Placement) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Placement) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Placement) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::Placement) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Placement) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Placement) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Placement) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + fn request_placement_group_id_dimension_value_init(request: &mut api::Placement) { + if request.placement_group_id_dimension_value.is_none() { + request.placement_group_id_dimension_value = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::Placement) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_publisher_update_info_init(request: &mut api::Placement) { + if request.publisher_update_info.is_none() { + request.publisher_update_info = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::Placement) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Placement) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + fn request_tag_setting_init(request: &mut api::Placement) { + if request.tag_setting.is_none() { + request.tag_setting = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "payment-source" => { + request.payment_source = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_advertiser_id_dimension_value_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "publisher-update-info.time" => { + request_publisher_update_info_init(&mut request); + request.publisher_update_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "tag-formats" => { + request_publisher_update_info_init(&mut request); + if request.tag_formats.is_none() { + request.tag_formats = Some(Default::default()); + } + request.tag_formats.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "payment-approved" => { + request_publisher_update_info_init(&mut request); + request.payment_approved = Some(arg_from_str(value.unwrap_or("false"), err, "payment-approved", "boolean")); + }, + "tag-setting.include-click-through-urls" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-through-urls", "boolean"); + }, + "tag-setting.include-click-tracking" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-tracking", "boolean"); + }, + "tag-setting.additional-key-values" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().additional_key_values = value.unwrap_or("").to_string(); + }, + "tag-setting.keyword-option" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().keyword_option = value.unwrap_or("").to_string(); + }, + "content-category-id" => { + request_tag_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_tag_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "status" => { + request_size_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary" => { + request_campaign_id_dimension_value_init(&mut request); + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "placement-group-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.placement_group_id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_site_id_dimension_value_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.value" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.dimension-name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.etag" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.match-type" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _placements_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Placement = Default::default(); + let mut call = self.hub.placements().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_advertiser_id_dimension_value_init(request: &mut api::Placement) { + if request.advertiser_id_dimension_value.is_none() { + request.advertiser_id_dimension_value = Some(Default::default()); + } + } + + fn request_campaign_id_dimension_value_init(request: &mut api::Placement) { + if request.campaign_id_dimension_value.is_none() { + request.campaign_id_dimension_value = Some(Default::default()); + } + } + + fn request_create_info_init(request: &mut api::Placement) { + if request.create_info.is_none() { + request.create_info = Some(Default::default()); + } + } + + fn request_directory_site_id_dimension_value_init(request: &mut api::Placement) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Placement) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_last_modified_info_init(request: &mut api::Placement) { + if request.last_modified_info.is_none() { + request.last_modified_info = Some(Default::default()); + } + } + + fn request_lookback_configuration_init(request: &mut api::Placement) { + if request.lookback_configuration.is_none() { + request.lookback_configuration = Some(Default::default()); + } + } + + fn request_placement_group_id_dimension_value_init(request: &mut api::Placement) { + if request.placement_group_id_dimension_value.is_none() { + request.placement_group_id_dimension_value = Some(Default::default()); + } + } + + fn request_pricing_schedule_init(request: &mut api::Placement) { + if request.pricing_schedule.is_none() { + request.pricing_schedule = Some(Default::default()); + } + } + + fn request_publisher_update_info_init(request: &mut api::Placement) { + if request.publisher_update_info.is_none() { + request.publisher_update_info = Some(Default::default()); + } + } + + fn request_site_id_dimension_value_init(request: &mut api::Placement) { + if request.site_id_dimension_value.is_none() { + request.site_id_dimension_value = Some(Default::default()); + } + } + + fn request_size_init(request: &mut api::Placement) { + if request.size.is_none() { + request.size = Some(Default::default()); + } + } + + fn request_tag_setting_init(request: &mut api::Placement) { + if request.tag_setting.is_none() { + request.tag_setting = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "comment" => { + request.comment = Some(value.unwrap_or("").to_string()); + }, + "campaign-id" => { + request.campaign_id = Some(value.unwrap_or("").to_string()); + }, + "payment-source" => { + request.payment_source = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.kind" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.value" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.dimension-name" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.etag" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.match-type" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id-dimension-value.id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.advertiser_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_advertiser_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "archived" => { + request_advertiser_id_dimension_value_init(&mut request); + request.archived = Some(arg_from_str(value.unwrap_or("false"), err, "archived", "boolean")); + }, + "publisher-update-info.time" => { + request_publisher_update_info_init(&mut request); + request.publisher_update_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "tag-formats" => { + request_publisher_update_info_init(&mut request); + if request.tag_formats.is_none() { + request.tag_formats = Some(Default::default()); + } + request.tag_formats.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "payment-approved" => { + request_publisher_update_info_init(&mut request); + request.payment_approved = Some(arg_from_str(value.unwrap_or("false"), err, "payment-approved", "boolean")); + }, + "tag-setting.include-click-through-urls" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-through-urls", "boolean"); + }, + "tag-setting.include-click-tracking" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "tag-setting.include-click-tracking", "boolean"); + }, + "tag-setting.additional-key-values" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().additional_key_values = value.unwrap_or("").to_string(); + }, + "tag-setting.keyword-option" => { + request_tag_setting_init(&mut request); + request.tag_setting.as_mut().unwrap().keyword_option = value.unwrap_or("").to_string(); + }, + "content-category-id" => { + request_tag_setting_init(&mut request); + request.content_category_id = Some(value.unwrap_or("").to_string()); + }, + "external-id" => { + request_tag_setting_init(&mut request); + request.external_id = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.width" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().width = Some(arg_from_str(value.unwrap_or("-0"), err, "size.width", "integer")); + }, + "size.kind" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "size.iab" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().iab = Some(arg_from_str(value.unwrap_or("false"), err, "size.iab", "boolean")); + }, + "size.id" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "size.height" => { + request_size_init(&mut request); + request.size.as_mut().unwrap().height = Some(arg_from_str(value.unwrap_or("-0"), err, "size.height", "integer")); + }, + "ssl-required" => { + request_size_init(&mut request); + request.ssl_required = Some(arg_from_str(value.unwrap_or("false"), err, "ssl-required", "boolean")); + }, + "status" => { + request_size_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.kind" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.value" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.dimension-name" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.etag" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.match-type" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "campaign-id-dimension-value.id" => { + request_campaign_id_dimension_value_init(&mut request); + request.campaign_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "primary" => { + request_campaign_id_dimension_value_init(&mut request); + request.primary = Some(arg_from_str(value.unwrap_or("false"), err, "primary", "boolean")); + }, + "placement-group-id" => { + request_campaign_id_dimension_value_init(&mut request); + request.placement_group_id = Some(value.unwrap_or("").to_string()); + }, + "create-info.time" => { + request_create_info_init(&mut request); + request.create_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "site-id" => { + request_create_info_init(&mut request); + request.site_id = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.kind" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.value" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.dimension-name" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.etag" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.match-type" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "site-id-dimension-value.id" => { + request_site_id_dimension_value_init(&mut request); + request.site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "compatibility" => { + request_site_id_dimension_value_init(&mut request); + request.compatibility = Some(value.unwrap_or("").to_string()); + }, + "placement-strategy-id" => { + request_site_id_dimension_value_init(&mut request); + request.placement_strategy_id = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.value" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.dimension-name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.etag" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.match-type" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "placement-group-id-dimension-value.id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.placement_group_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_placement_group_id_dimension_value_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request_placement_group_id_dimension_value_init(&mut request); + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_placement_group_id_dimension_value_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "lookback-configuration.click-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().click_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.click-duration", "integer"); + }, + "lookback-configuration.post-impression-activities-duration" => { + request_lookback_configuration_init(&mut request); + request.lookback_configuration.as_mut().unwrap().post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "lookback-configuration.post-impression-activities-duration", "integer"); + }, + "last-modified-info.time" => { + request_last_modified_info_init(&mut request); + request.last_modified_info.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "pricing-schedule.start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.end-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.flighted" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().flighted = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.flighted", "boolean"); + }, + "pricing-schedule.disregard-overdelivery" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().disregard_overdelivery = arg_from_str(value.unwrap_or("false"), err, "pricing-schedule.disregard-overdelivery", "boolean"); + }, + "pricing-schedule.pricing-type" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().pricing_type = value.unwrap_or("").to_string(); + }, + "pricing-schedule.cap-cost-option" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().cap_cost_option = value.unwrap_or("").to_string(); + }, + "pricing-schedule.testing-start-date" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().testing_start_date = value.unwrap_or("").to_string(); + }, + "pricing-schedule.floodlight-activity-id" => { + request_pricing_schedule_init(&mut request); + request.pricing_schedule.as_mut().unwrap().floodlight_activity_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _platform_types_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.platform_types().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _postal_codes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.postal_codes().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _regions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.regions().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_compatible_fields_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Report = Default::default(); + let mut call = self.hub.reports().compatible_fields_query(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_criteria_init(request: &mut api::Report) { + if request.criteria.is_none() { + request.criteria = Some(Default::default()); + } + } + + fn request_cross_dimension_reach_criteria_init(request: &mut api::Report) { + if request.cross_dimension_reach_criteria.is_none() { + request.cross_dimension_reach_criteria = Some(Default::default()); + } + } + + fn request_delivery_init(request: &mut api::Report) { + if request.delivery.is_none() { + request.delivery = Some(Default::default()); + } + } + + fn request_floodlight_criteria_init(request: &mut api::Report) { + if request.floodlight_criteria.is_none() { + request.floodlight_criteria = Some(Default::default()); + } + } + + fn request_path_to_conversion_criteria_init(request: &mut api::Report) { + if request.path_to_conversion_criteria.is_none() { + request.path_to_conversion_criteria = Some(Default::default()); + } + } + + fn request_reach_criteria_init(request: &mut api::Report) { + if request.reach_criteria.is_none() { + request.reach_criteria = Some(Default::default()); + } + } + + fn request_schedule_init(request: &mut api::Report) { + if request.schedule.is_none() { + request.schedule = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "criteria.activities.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "criteria.activities.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "criteria.date-range.start-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "criteria.date-range.end-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.relative-date-range" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "criteria.custom-rich-media-events.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "criteria.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_criteria_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "sub-account-id" => { + request_criteria_init(&mut request); + request.sub_account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_criteria_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "schedule.start-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "schedule.runs-on-day-of-month" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().runs_on_day_of_month = value.unwrap_or("").to_string(); + }, + "schedule.every" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().every = arg_from_str(value.unwrap_or("-0"), err, "schedule.every", "integer"); + }, + "schedule.expiration-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().expiration_date = value.unwrap_or("").to_string(); + }, + "schedule.active" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().active = arg_from_str(value.unwrap_or("false"), err, "schedule.active", "boolean"); + }, + "schedule.repeats" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats = value.unwrap_or("").to_string(); + }, + "schedule.repeats-on-week-days" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats_on_week_days.push(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.date-range.start-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.end-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.relative-date-range" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.floodlight-config-id.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.value" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.dimension-name" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.etag" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.match-type" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.id" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.report-properties.clicks-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.clicks_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.clicks-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.pivot-on-interaction-path" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.pivot_on_interaction_path = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.pivot-on-interaction-path", "boolean"); + }, + "path-to-conversion-criteria.report-properties.impressions-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.impressions_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.impressions-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-interaction-gap" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_interaction_gap = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-interaction-gap", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-click-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_click_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-click-interactions", "integer"); + }, + "path-to-conversion-criteria.report-properties.maximum-impression-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_impression_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-impression-interactions", "integer"); + }, + "path-to-conversion-criteria.metric-names" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "format" => { + request_path_to_conversion_criteria_init(&mut request); + request.format = Some(value.unwrap_or("").to_string()); + }, + "reach-criteria.activities.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.activities.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.date-range.start-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.end-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.relative-date-range" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "reach-criteria.reach-by-frequency-metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().reach_by_frequency_metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.custom-rich-media-events.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.enable-all-dimension-combinations" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().enable_all_dimension_combinations = arg_from_str(value.unwrap_or("false"), err, "reach-criteria.enable-all-dimension-combinations", "boolean"); + }, + "file-name" => { + request_reach_criteria_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "delivery.message" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().message = value.unwrap_or("").to_string(); + }, + "delivery.email-owner-delivery-type" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner_delivery_type = value.unwrap_or("").to_string(); + }, + "delivery.email-owner" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner = arg_from_str(value.unwrap_or("false"), err, "delivery.email-owner", "boolean"); + }, + "etag" => { + request_delivery_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner-profile-id" => { + request_delivery_init(&mut request); + request.owner_profile_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_delivery_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_delivery_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_delivery_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_delivery_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.date-range.start-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.end-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.relative-date-range" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.floodlight-config-id.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.value" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.dimension-name" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.etag" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.match-type" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.id" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.report-properties.include-unattributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-attributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.metric-names" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.pivoted" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().pivoted = arg_from_str(value.unwrap_or("false"), err, "cross-dimension-reach-criteria.pivoted", "boolean"); + }, + "cross-dimension-reach-criteria.date-range.start-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.kind" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.end-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.relative-date-range" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.dimension" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.overlap-metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().overlap_metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().delete(&self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _reports_files_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.reports().files_get(&self.opt.arg_profile_id, &self.opt.arg_report_id, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _reports_files_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().files_list(&self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().get(&self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Report = Default::default(); + let mut call = self.hub.reports().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_criteria_init(request: &mut api::Report) { + if request.criteria.is_none() { + request.criteria = Some(Default::default()); + } + } + + fn request_cross_dimension_reach_criteria_init(request: &mut api::Report) { + if request.cross_dimension_reach_criteria.is_none() { + request.cross_dimension_reach_criteria = Some(Default::default()); + } + } + + fn request_delivery_init(request: &mut api::Report) { + if request.delivery.is_none() { + request.delivery = Some(Default::default()); + } + } + + fn request_floodlight_criteria_init(request: &mut api::Report) { + if request.floodlight_criteria.is_none() { + request.floodlight_criteria = Some(Default::default()); + } + } + + fn request_path_to_conversion_criteria_init(request: &mut api::Report) { + if request.path_to_conversion_criteria.is_none() { + request.path_to_conversion_criteria = Some(Default::default()); + } + } + + fn request_reach_criteria_init(request: &mut api::Report) { + if request.reach_criteria.is_none() { + request.reach_criteria = Some(Default::default()); + } + } + + fn request_schedule_init(request: &mut api::Report) { + if request.schedule.is_none() { + request.schedule = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "criteria.activities.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "criteria.activities.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "criteria.date-range.start-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "criteria.date-range.end-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.relative-date-range" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "criteria.custom-rich-media-events.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "criteria.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_criteria_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "sub-account-id" => { + request_criteria_init(&mut request); + request.sub_account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_criteria_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "schedule.start-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "schedule.runs-on-day-of-month" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().runs_on_day_of_month = value.unwrap_or("").to_string(); + }, + "schedule.every" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().every = arg_from_str(value.unwrap_or("-0"), err, "schedule.every", "integer"); + }, + "schedule.expiration-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().expiration_date = value.unwrap_or("").to_string(); + }, + "schedule.active" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().active = arg_from_str(value.unwrap_or("false"), err, "schedule.active", "boolean"); + }, + "schedule.repeats" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats = value.unwrap_or("").to_string(); + }, + "schedule.repeats-on-week-days" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats_on_week_days.push(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.date-range.start-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.end-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.relative-date-range" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.floodlight-config-id.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.value" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.dimension-name" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.etag" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.match-type" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.id" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.report-properties.clicks-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.clicks_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.clicks-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.pivot-on-interaction-path" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.pivot_on_interaction_path = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.pivot-on-interaction-path", "boolean"); + }, + "path-to-conversion-criteria.report-properties.impressions-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.impressions_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.impressions-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-interaction-gap" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_interaction_gap = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-interaction-gap", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-click-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_click_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-click-interactions", "integer"); + }, + "path-to-conversion-criteria.report-properties.maximum-impression-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_impression_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-impression-interactions", "integer"); + }, + "path-to-conversion-criteria.metric-names" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "format" => { + request_path_to_conversion_criteria_init(&mut request); + request.format = Some(value.unwrap_or("").to_string()); + }, + "reach-criteria.activities.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.activities.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.date-range.start-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.end-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.relative-date-range" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "reach-criteria.reach-by-frequency-metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().reach_by_frequency_metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.custom-rich-media-events.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.enable-all-dimension-combinations" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().enable_all_dimension_combinations = arg_from_str(value.unwrap_or("false"), err, "reach-criteria.enable-all-dimension-combinations", "boolean"); + }, + "file-name" => { + request_reach_criteria_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "delivery.message" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().message = value.unwrap_or("").to_string(); + }, + "delivery.email-owner-delivery-type" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner_delivery_type = value.unwrap_or("").to_string(); + }, + "delivery.email-owner" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner = arg_from_str(value.unwrap_or("false"), err, "delivery.email-owner", "boolean"); + }, + "etag" => { + request_delivery_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner-profile-id" => { + request_delivery_init(&mut request); + request.owner_profile_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_delivery_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_delivery_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_delivery_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_delivery_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.date-range.start-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.end-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.relative-date-range" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.floodlight-config-id.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.value" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.dimension-name" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.etag" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.match-type" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.id" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.report-properties.include-unattributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-attributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.metric-names" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.pivoted" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().pivoted = arg_from_str(value.unwrap_or("false"), err, "cross-dimension-reach-criteria.pivoted", "boolean"); + }, + "cross-dimension-reach-criteria.date-range.start-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.kind" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.end-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.relative-date-range" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.dimension" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.overlap-metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().overlap_metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "scope" => { + call = call.scope(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Report = Default::default(); + let mut call = self.hub.reports().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_criteria_init(request: &mut api::Report) { + if request.criteria.is_none() { + request.criteria = Some(Default::default()); + } + } + + fn request_cross_dimension_reach_criteria_init(request: &mut api::Report) { + if request.cross_dimension_reach_criteria.is_none() { + request.cross_dimension_reach_criteria = Some(Default::default()); + } + } + + fn request_delivery_init(request: &mut api::Report) { + if request.delivery.is_none() { + request.delivery = Some(Default::default()); + } + } + + fn request_floodlight_criteria_init(request: &mut api::Report) { + if request.floodlight_criteria.is_none() { + request.floodlight_criteria = Some(Default::default()); + } + } + + fn request_path_to_conversion_criteria_init(request: &mut api::Report) { + if request.path_to_conversion_criteria.is_none() { + request.path_to_conversion_criteria = Some(Default::default()); + } + } + + fn request_reach_criteria_init(request: &mut api::Report) { + if request.reach_criteria.is_none() { + request.reach_criteria = Some(Default::default()); + } + } + + fn request_schedule_init(request: &mut api::Report) { + if request.schedule.is_none() { + request.schedule = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "criteria.activities.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "criteria.activities.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "criteria.date-range.start-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "criteria.date-range.end-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.relative-date-range" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "criteria.custom-rich-media-events.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "criteria.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_criteria_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "sub-account-id" => { + request_criteria_init(&mut request); + request.sub_account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_criteria_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "schedule.start-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "schedule.runs-on-day-of-month" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().runs_on_day_of_month = value.unwrap_or("").to_string(); + }, + "schedule.every" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().every = arg_from_str(value.unwrap_or("-0"), err, "schedule.every", "integer"); + }, + "schedule.expiration-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().expiration_date = value.unwrap_or("").to_string(); + }, + "schedule.active" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().active = arg_from_str(value.unwrap_or("false"), err, "schedule.active", "boolean"); + }, + "schedule.repeats" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats = value.unwrap_or("").to_string(); + }, + "schedule.repeats-on-week-days" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats_on_week_days.push(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.date-range.start-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.end-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.relative-date-range" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.floodlight-config-id.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.value" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.dimension-name" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.etag" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.match-type" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.id" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.report-properties.clicks-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.clicks_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.clicks-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.pivot-on-interaction-path" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.pivot_on_interaction_path = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.pivot-on-interaction-path", "boolean"); + }, + "path-to-conversion-criteria.report-properties.impressions-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.impressions_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.impressions-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-interaction-gap" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_interaction_gap = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-interaction-gap", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-click-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_click_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-click-interactions", "integer"); + }, + "path-to-conversion-criteria.report-properties.maximum-impression-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_impression_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-impression-interactions", "integer"); + }, + "path-to-conversion-criteria.metric-names" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "format" => { + request_path_to_conversion_criteria_init(&mut request); + request.format = Some(value.unwrap_or("").to_string()); + }, + "reach-criteria.activities.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.activities.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.date-range.start-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.end-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.relative-date-range" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "reach-criteria.reach-by-frequency-metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().reach_by_frequency_metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.custom-rich-media-events.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.enable-all-dimension-combinations" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().enable_all_dimension_combinations = arg_from_str(value.unwrap_or("false"), err, "reach-criteria.enable-all-dimension-combinations", "boolean"); + }, + "file-name" => { + request_reach_criteria_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "delivery.message" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().message = value.unwrap_or("").to_string(); + }, + "delivery.email-owner-delivery-type" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner_delivery_type = value.unwrap_or("").to_string(); + }, + "delivery.email-owner" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner = arg_from_str(value.unwrap_or("false"), err, "delivery.email-owner", "boolean"); + }, + "etag" => { + request_delivery_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner-profile-id" => { + request_delivery_init(&mut request); + request.owner_profile_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_delivery_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_delivery_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_delivery_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_delivery_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.date-range.start-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.end-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.relative-date-range" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.floodlight-config-id.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.value" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.dimension-name" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.etag" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.match-type" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.id" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.report-properties.include-unattributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-attributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.metric-names" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.pivoted" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().pivoted = arg_from_str(value.unwrap_or("false"), err, "cross-dimension-reach-criteria.pivoted", "boolean"); + }, + "cross-dimension-reach-criteria.date-range.start-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.kind" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.end-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.relative-date-range" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.dimension" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.overlap-metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().overlap_metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_run(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().run(&self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "synchronous" => { + call = call.synchronous(arg_from_str(value.unwrap_or("false"), err, "synchronous", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Report = Default::default(); + let mut call = self.hub.reports().update(&request, &self.opt.arg_profile_id, &self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_criteria_init(request: &mut api::Report) { + if request.criteria.is_none() { + request.criteria = Some(Default::default()); + } + } + + fn request_cross_dimension_reach_criteria_init(request: &mut api::Report) { + if request.cross_dimension_reach_criteria.is_none() { + request.cross_dimension_reach_criteria = Some(Default::default()); + } + } + + fn request_delivery_init(request: &mut api::Report) { + if request.delivery.is_none() { + request.delivery = Some(Default::default()); + } + } + + fn request_floodlight_criteria_init(request: &mut api::Report) { + if request.floodlight_criteria.is_none() { + request.floodlight_criteria = Some(Default::default()); + } + } + + fn request_path_to_conversion_criteria_init(request: &mut api::Report) { + if request.path_to_conversion_criteria.is_none() { + request.path_to_conversion_criteria = Some(Default::default()); + } + } + + fn request_reach_criteria_init(request: &mut api::Report) { + if request.reach_criteria.is_none() { + request.reach_criteria = Some(Default::default()); + } + } + + fn request_schedule_init(request: &mut api::Report) { + if request.schedule.is_none() { + request.schedule = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "criteria.activities.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "criteria.activities.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "criteria.date-range.start-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "criteria.date-range.end-date" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "criteria.date-range.relative-date-range" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "criteria.custom-rich-media-events.kind" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "criteria.metric-names" => { + request_criteria_init(&mut request); + request.criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_criteria_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "sub-account-id" => { + request_criteria_init(&mut request); + request.sub_account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_criteria_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "schedule.start-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "schedule.runs-on-day-of-month" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().runs_on_day_of_month = value.unwrap_or("").to_string(); + }, + "schedule.every" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().every = arg_from_str(value.unwrap_or("-0"), err, "schedule.every", "integer"); + }, + "schedule.expiration-date" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().expiration_date = value.unwrap_or("").to_string(); + }, + "schedule.active" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().active = arg_from_str(value.unwrap_or("false"), err, "schedule.active", "boolean"); + }, + "schedule.repeats" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats = value.unwrap_or("").to_string(); + }, + "schedule.repeats-on-week-days" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().repeats_on_week_days.push(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.date-range.start-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.end-date" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.date-range.relative-date-range" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "path-to-conversion-criteria.floodlight-config-id.kind" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.value" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.dimension-name" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.etag" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.match-type" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.floodlight-config-id.id" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "path-to-conversion-criteria.report-properties.clicks-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.clicks_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.clicks-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.pivot-on-interaction-path" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.pivot_on_interaction_path = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.pivot-on-interaction-path", "boolean"); + }, + "path-to-conversion-criteria.report-properties.impressions-lookback-window" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.impressions_lookback_window = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.impressions-lookback-window", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-interaction-gap" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_interaction_gap = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-interaction-gap", "integer"); + }, + "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "path-to-conversion-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "path-to-conversion-criteria.report-properties.maximum-click-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_click_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-click-interactions", "integer"); + }, + "path-to-conversion-criteria.report-properties.maximum-impression-interactions" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().report_properties.maximum_impression_interactions = arg_from_str(value.unwrap_or("-0"), err, "path-to-conversion-criteria.report-properties.maximum-impression-interactions", "integer"); + }, + "path-to-conversion-criteria.metric-names" => { + request_path_to_conversion_criteria_init(&mut request); + request.path_to_conversion_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "format" => { + request_path_to_conversion_criteria_init(&mut request); + request.format = Some(value.unwrap_or("").to_string()); + }, + "reach-criteria.activities.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.activities.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().activities.metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.date-range.start-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.end-date" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "reach-criteria.date-range.relative-date-range" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "reach-criteria.reach-by-frequency-metric-names" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().reach_by_frequency_metric_names.push(value.unwrap_or("").to_string()); + }, + "reach-criteria.custom-rich-media-events.kind" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().custom_rich_media_events.kind = value.unwrap_or("").to_string(); + }, + "reach-criteria.enable-all-dimension-combinations" => { + request_reach_criteria_init(&mut request); + request.reach_criteria.as_mut().unwrap().enable_all_dimension_combinations = arg_from_str(value.unwrap_or("false"), err, "reach-criteria.enable-all-dimension-combinations", "boolean"); + }, + "file-name" => { + request_reach_criteria_init(&mut request); + request.file_name = Some(value.unwrap_or("").to_string()); + }, + "delivery.message" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().message = value.unwrap_or("").to_string(); + }, + "delivery.email-owner-delivery-type" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner_delivery_type = value.unwrap_or("").to_string(); + }, + "delivery.email-owner" => { + request_delivery_init(&mut request); + request.delivery.as_mut().unwrap().email_owner = arg_from_str(value.unwrap_or("false"), err, "delivery.email-owner", "boolean"); + }, + "etag" => { + request_delivery_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner-profile-id" => { + request_delivery_init(&mut request); + request.owner_profile_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_delivery_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_delivery_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_delivery_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_delivery_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.date-range.start-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.end-date" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.date-range.relative-date-range" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "floodlight-criteria.floodlight-config-id.kind" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.kind = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.value" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.value = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.dimension-name" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.dimension_name = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.etag" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.etag = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.match-type" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.match_type = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.floodlight-config-id.id" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().floodlight_config_id.id = Some(value.unwrap_or("").to_string()); + }, + "floodlight-criteria.report-properties.include-unattributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-unattributed-cookie-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_unattributed_cookie_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-unattributed-cookie-conversions", "boolean"); + }, + "floodlight-criteria.report-properties.include-attributed-ip-conversions" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().report_properties.include_attributed_ip_conversions = arg_from_str(value.unwrap_or("false"), err, "floodlight-criteria.report-properties.include-attributed-ip-conversions", "boolean"); + }, + "floodlight-criteria.metric-names" => { + request_floodlight_criteria_init(&mut request); + request.floodlight_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.pivoted" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().pivoted = arg_from_str(value.unwrap_or("false"), err, "cross-dimension-reach-criteria.pivoted", "boolean"); + }, + "cross-dimension-reach-criteria.date-range.start-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.start_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.kind" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.kind = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.end-date" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.end_date = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.date-range.relative-date-range" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().date_range.relative_date_range = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.dimension" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "cross-dimension-reach-criteria.overlap-metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().overlap_metric_names.push(value.unwrap_or("").to_string()); + }, + "cross-dimension-reach-criteria.metric-names" => { + request_cross_dimension_reach_criteria_init(&mut request); + request.cross_dimension_reach_criteria.as_mut().unwrap().metric_names.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Site = Default::default(); + let mut call = self.hub.sites().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_directory_site_id_dimension_value_init(request: &mut api::Site) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Site) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_site_settings_init(request: &mut api::Site) { + if request.site_settings.is_none() { + request.site_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "site-settings.disable-brand-safe-ads" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_brand_safe_ads = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-brand-safe-ads", "boolean"); + }, + "site-settings.active-view-opt-out" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().active_view_opt_out = arg_from_str(value.unwrap_or("false"), err, "site-settings.active-view-opt-out", "boolean"); + }, + "site-settings.lookback-configuration.click-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.click_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.click-duration", "integer"); + }, + "site-settings.lookback-configuration.post-impression-activities-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.post-impression-activities-duration", "integer"); + }, + "site-settings.disable-new-cookie" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_new_cookie = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-new-cookie", "boolean"); + }, + "site-settings.tag-setting.include-click-through-urls" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-through-urls", "boolean"); + }, + "site-settings.tag-setting.include-click-tracking" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-tracking", "boolean"); + }, + "site-settings.tag-setting.additional-key-values" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.additional_key_values = value.unwrap_or("").to_string(); + }, + "site-settings.tag-setting.keyword-option" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.keyword_option = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-header" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_header = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-footer" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_footer = value.unwrap_or("").to_string(); + }, + "approved" => { + request_site_settings_init(&mut request); + request.approved = Some(arg_from_str(value.unwrap_or("false"), err, "approved", "boolean")); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "unmapped-site" => { + call = call.unmapped_site(arg_from_str(value.unwrap_or("false"), err, "unmapped-site", "boolean")); + }, + "subaccount-id" => { + call = call.subaccount_id(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "directory-site-ids" => { + call = call.add_directory_site_ids(value.unwrap_or("")); + }, + "campaign-ids" => { + call = call.add_campaign_ids(value.unwrap_or("")); + }, + "approved" => { + call = call.approved(arg_from_str(value.unwrap_or("false"), err, "approved", "boolean")); + }, + "ad-words-site" => { + call = call.ad_words_site(arg_from_str(value.unwrap_or("false"), err, "ad-words-site", "boolean")); + }, + "accepts-publisher-paid-placements" => { + call = call.accepts_publisher_paid_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-publisher-paid-placements", "boolean")); + }, + "accepts-interstitial-placements" => { + call = call.accepts_interstitial_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-interstitial-placements", "boolean")); + }, + "accepts-in-stream-video-placements" => { + call = call.accepts_in_stream_video_placements(arg_from_str(value.unwrap_or("false"), err, "accepts-in-stream-video-placements", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Site = Default::default(); + let mut call = self.hub.sites().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_directory_site_id_dimension_value_init(request: &mut api::Site) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Site) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_site_settings_init(request: &mut api::Site) { + if request.site_settings.is_none() { + request.site_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "site-settings.disable-brand-safe-ads" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_brand_safe_ads = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-brand-safe-ads", "boolean"); + }, + "site-settings.active-view-opt-out" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().active_view_opt_out = arg_from_str(value.unwrap_or("false"), err, "site-settings.active-view-opt-out", "boolean"); + }, + "site-settings.lookback-configuration.click-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.click_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.click-duration", "integer"); + }, + "site-settings.lookback-configuration.post-impression-activities-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.post-impression-activities-duration", "integer"); + }, + "site-settings.disable-new-cookie" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_new_cookie = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-new-cookie", "boolean"); + }, + "site-settings.tag-setting.include-click-through-urls" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-through-urls", "boolean"); + }, + "site-settings.tag-setting.include-click-tracking" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-tracking", "boolean"); + }, + "site-settings.tag-setting.additional-key-values" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.additional_key_values = value.unwrap_or("").to_string(); + }, + "site-settings.tag-setting.keyword-option" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.keyword_option = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-header" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_header = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-footer" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_footer = value.unwrap_or("").to_string(); + }, + "approved" => { + request_site_settings_init(&mut request); + request.approved = Some(arg_from_str(value.unwrap_or("false"), err, "approved", "boolean")); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Site = Default::default(); + let mut call = self.hub.sites().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_directory_site_id_dimension_value_init(request: &mut api::Site) { + if request.directory_site_id_dimension_value.is_none() { + request.directory_site_id_dimension_value = Some(Default::default()); + } + } + + fn request_id_dimension_value_init(request: &mut api::Site) { + if request.id_dimension_value.is_none() { + request.id_dimension_value = Some(Default::default()); + } + } + + fn request_site_settings_init(request: &mut api::Site) { + if request.site_settings.is_none() { + request.site_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.kind" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.value" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.dimension-name" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.etag" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.match-type" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id-dimension-value.id" => { + request_directory_site_id_dimension_value_init(&mut request); + request.directory_site_id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "site-settings.disable-brand-safe-ads" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_brand_safe_ads = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-brand-safe-ads", "boolean"); + }, + "site-settings.active-view-opt-out" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().active_view_opt_out = arg_from_str(value.unwrap_or("false"), err, "site-settings.active-view-opt-out", "boolean"); + }, + "site-settings.lookback-configuration.click-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.click_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.click-duration", "integer"); + }, + "site-settings.lookback-configuration.post-impression-activities-duration" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().lookback_configuration.post_impression_activities_duration = arg_from_str(value.unwrap_or("-0"), err, "site-settings.lookback-configuration.post-impression-activities-duration", "integer"); + }, + "site-settings.disable-new-cookie" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().disable_new_cookie = arg_from_str(value.unwrap_or("false"), err, "site-settings.disable-new-cookie", "boolean"); + }, + "site-settings.tag-setting.include-click-through-urls" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_through_urls = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-through-urls", "boolean"); + }, + "site-settings.tag-setting.include-click-tracking" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.include_click_tracking = arg_from_str(value.unwrap_or("false"), err, "site-settings.tag-setting.include-click-tracking", "boolean"); + }, + "site-settings.tag-setting.additional-key-values" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.additional_key_values = value.unwrap_or("").to_string(); + }, + "site-settings.tag-setting.keyword-option" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().tag_setting.keyword_option = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-header" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_header = value.unwrap_or("").to_string(); + }, + "site-settings.creative-settings.i-frame-footer" => { + request_site_settings_init(&mut request); + request.site_settings.as_mut().unwrap().creative_settings.i_frame_footer = value.unwrap_or("").to_string(); + }, + "approved" => { + request_site_settings_init(&mut request); + request.approved = Some(arg_from_str(value.unwrap_or("false"), err, "approved", "boolean")); + }, + "id-dimension-value.kind" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.value" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.dimension-name" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().dimension_name = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.etag" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.match-type" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().match_type = Some(value.unwrap_or("").to_string()); + }, + "id-dimension-value.id" => { + request_id_dimension_value_init(&mut request); + request.id_dimension_value.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "key-name" => { + request_id_dimension_value_init(&mut request); + request.key_name = Some(value.unwrap_or("").to_string()); + }, + "directory-site-id" => { + request_id_dimension_value_init(&mut request); + request.directory_site_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_id_dimension_value_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_id_dimension_value_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sizes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sizes().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sizes_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Size = Default::default(); + let mut call = self.hub.sizes().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "width" => { + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "iab" => { + request.iab = Some(arg_from_str(value.unwrap_or("false"), err, "iab", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sizes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sizes().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "width" => { + call = call.width(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "iab-standard" => { + call = call.iab_standard(arg_from_str(value.unwrap_or("false"), err, "iab-standard", "boolean")); + }, + "height" => { + call = call.height(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subaccounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subaccounts().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subaccounts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subaccount = Default::default(); + let mut call = self.hub.subaccounts().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "available-permission-ids" => { + if request.available_permission_ids.is_none() { + request.available_permission_ids = Some(Default::default()); + } + request.available_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subaccounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subaccounts().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subaccounts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subaccount = Default::default(); + let mut call = self.hub.subaccounts().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "available-permission-ids" => { + if request.available_permission_ids.is_none() { + request.available_permission_ids = Some(Default::default()); + } + request.available_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subaccounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subaccount = Default::default(); + let mut call = self.hub.subaccounts().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "available-permission-ids" => { + if request.available_permission_ids.is_none() { + request.available_permission_ids = Some(Default::default()); + } + request.available_permission_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_profiles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_profiles().get(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_profiles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_profiles().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_role_permission_groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_role_permission_groups().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_role_permission_groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_role_permission_groups().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_role_permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_role_permissions().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_role_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_role_permissions().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_roles_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_roles().delete(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _user_roles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_roles().get(&self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_roles_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UserRole = Default::default(); + let mut call = self.hub.user_roles().insert(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default-user-role" => { + request.default_user_role = Some(arg_from_str(value.unwrap_or("false"), err, "default-user-role", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "parent-user-role-id" => { + request.parent_user_role_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_roles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.user_roles().list(&self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "subaccount-id" => { + call = call.subaccount_id(value.unwrap_or("")); + }, + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-field" => { + call = call.sort_field(value.unwrap_or("")); + }, + "search-string" => { + call = call.search_string(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "ids" => { + call = call.add_ids(value.unwrap_or("")); + }, + "account-user-role-only" => { + call = call.account_user_role_only(arg_from_str(value.unwrap_or("false"), err, "account-user-role-only", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_roles_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UserRole = Default::default(); + let mut call = self.hub.user_roles().patch(&request, &self.opt.arg_profile_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default-user-role" => { + request.default_user_role = Some(arg_from_str(value.unwrap_or("false"), err, "default-user-role", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "parent-user-role-id" => { + request.parent_user_role_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _user_roles_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UserRole = Default::default(); + let mut call = self.hub.user_roles().update(&request, &self.opt.arg_profile_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "default-user-role" => { + request.default_user_role = Some(arg_from_str(value.unwrap_or("false"), err, "default-user-role", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "subaccount-id" => { + request.subaccount_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "parent-user-role-id" => { + request.parent_user_role_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_account_active_ad_summaries { + if self.opt.cmd_get { + call_result = self._account_active_ad_summaries_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_account_permission_groups { + if self.opt.cmd_get { + call_result = self._account_permission_groups_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._account_permission_groups_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_account_permissions { + if self.opt.cmd_get { + call_result = self._account_permissions_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._account_permissions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_account_user_profiles { + if self.opt.cmd_get { + call_result = self._account_user_profiles_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._account_user_profiles_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._account_user_profiles_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._account_user_profiles_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_accounts { + if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._accounts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_ads { + if self.opt.cmd_get { + call_result = self._ads_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._ads_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._ads_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._ads_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._ads_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_advertiser_groups { + if self.opt.cmd_delete { + call_result = self._advertiser_groups_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._advertiser_groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._advertiser_groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._advertiser_groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._advertiser_groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._advertiser_groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_advertisers { + if self.opt.cmd_get { + call_result = self._advertisers_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._advertisers_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._advertisers_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._advertisers_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._advertisers_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_browsers { + if self.opt.cmd_list { + call_result = self._browsers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_campaign_creative_associations { + if self.opt.cmd_insert { + call_result = self._campaign_creative_associations_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._campaign_creative_associations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_campaigns { + if self.opt.cmd_get { + call_result = self._campaigns_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._campaigns_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._campaigns_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._campaigns_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._campaigns_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_change_logs { + if self.opt.cmd_get { + call_result = self._change_logs_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._change_logs_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_cities { + if self.opt.cmd_list { + call_result = self._cities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_connection_types { + if self.opt.cmd_list { + call_result = self._connection_types_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_content_categories { + if self.opt.cmd_delete { + call_result = self._content_categories_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._content_categories_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._content_categories_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._content_categories_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._content_categories_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._content_categories_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_countries { + if self.opt.cmd_get { + call_result = self._countries_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._countries_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creative_assets { + if self.opt.cmd_insert { + call_result = self._creative_assets_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creative_field_values { + if self.opt.cmd_delete { + call_result = self._creative_field_values_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._creative_field_values_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._creative_field_values_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._creative_field_values_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._creative_field_values_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._creative_field_values_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creative_fields { + if self.opt.cmd_delete { + call_result = self._creative_fields_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._creative_fields_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._creative_fields_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._creative_fields_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._creative_fields_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._creative_fields_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creative_groups { + if self.opt.cmd_get { + call_result = self._creative_groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._creative_groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._creative_groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._creative_groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._creative_groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_creatives { + if self.opt.cmd_get { + call_result = self._creatives_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._creatives_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._creatives_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._creatives_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._creatives_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_dimension_values { + if self.opt.cmd_query { + call_result = self._dimension_values_query(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_directory_site_contacts { + if self.opt.cmd_get { + call_result = self._directory_site_contacts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._directory_site_contacts_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_directory_sites { + if self.opt.cmd_get { + call_result = self._directory_sites_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._directory_sites_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_event_tags { + if self.opt.cmd_delete { + call_result = self._event_tags_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._event_tags_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._event_tags_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._event_tags_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._event_tags_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._event_tags_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_files { + if self.opt.cmd_get { + call_result = self._files_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._files_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_floodlight_activities { + if self.opt.cmd_delete { + call_result = self._floodlight_activities_delete(dry_run, &mut err); + } else if self.opt.cmd_generatetag { + call_result = self._floodlight_activities_generatetag(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._floodlight_activities_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._floodlight_activities_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._floodlight_activities_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._floodlight_activities_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._floodlight_activities_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_floodlight_activity_groups { + if self.opt.cmd_delete { + call_result = self._floodlight_activity_groups_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._floodlight_activity_groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._floodlight_activity_groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._floodlight_activity_groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._floodlight_activity_groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._floodlight_activity_groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_floodlight_configurations { + if self.opt.cmd_get { + call_result = self._floodlight_configurations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._floodlight_configurations_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._floodlight_configurations_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._floodlight_configurations_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_landing_pages { + if self.opt.cmd_delete { + call_result = self._landing_pages_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._landing_pages_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._landing_pages_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._landing_pages_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._landing_pages_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._landing_pages_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_metros { + if self.opt.cmd_list { + call_result = self._metros_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_mobile_carriers { + if self.opt.cmd_list { + call_result = self._mobile_carriers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_operating_system_versions { + if self.opt.cmd_list { + call_result = self._operating_system_versions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_operating_systems { + if self.opt.cmd_list { + call_result = self._operating_systems_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_placement_groups { + if self.opt.cmd_get { + call_result = self._placement_groups_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._placement_groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._placement_groups_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._placement_groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._placement_groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_placement_strategies { + if self.opt.cmd_delete { + call_result = self._placement_strategies_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._placement_strategies_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._placement_strategies_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._placement_strategies_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._placement_strategies_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._placement_strategies_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_placements { + if self.opt.cmd_generatetags { + call_result = self._placements_generatetags(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._placements_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._placements_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._placements_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._placements_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._placements_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_platform_types { + if self.opt.cmd_list { + call_result = self._platform_types_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_postal_codes { + if self.opt.cmd_list { + call_result = self._postal_codes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_regions { + if self.opt.cmd_list { + call_result = self._regions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_compatible_fields_query { + call_result = self._reports_compatible_fields_query(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._reports_delete(dry_run, &mut err); + } else if self.opt.cmd_files_get { + call_result = self._reports_files_get(dry_run, &mut err); + } else if self.opt.cmd_files_list { + call_result = self._reports_files_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._reports_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._reports_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._reports_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._reports_patch(dry_run, &mut err); + } else if self.opt.cmd_run { + call_result = self._reports_run(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._reports_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_sites { + if self.opt.cmd_get { + call_result = self._sites_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._sites_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._sites_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._sites_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._sites_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_sizes { + if self.opt.cmd_get { + call_result = self._sizes_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._sizes_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._sizes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_subaccounts { + if self.opt.cmd_get { + call_result = self._subaccounts_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._subaccounts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._subaccounts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._subaccounts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._subaccounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_user_profiles { + if self.opt.cmd_get { + call_result = self._user_profiles_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._user_profiles_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_user_role_permission_groups { + if self.opt.cmd_get { + call_result = self._user_role_permission_groups_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._user_role_permission_groups_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_user_role_permissions { + if self.opt.cmd_get { + call_result = self._user_role_permissions_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._user_role_permissions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_user_roles { + if self.opt.cmd_delete { + call_result = self._user_roles_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._user_roles_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._user_roles_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._user_roles_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._user_roles_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._user_roles_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "dfareporting2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "dfareporting2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Dfareporting::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/discovery1-cli/Cargo.toml b/gen/discovery1-cli/Cargo.toml new file mode 100644 index 00000000000..3f7980b4f53 --- /dev/null +++ b/gen/discovery1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-discovery1-cli" +version = "0.0.1+00000000" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with discovery (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/discovery1-cli" +homepage = "https://developers.google.com/discovery/" +documentation = "http://byron.github.io/google-apis-rs/google_discovery1_cli" +license = "MIT" +keywords = ["discovery", "google", "cli"] + +[[bin]] +name = "discovery1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-discovery1] +path = "../discovery1" diff --git a/gen/discovery1-cli/LICENSE.md b/gen/discovery1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/discovery1-cli/LICENSE.md @@ -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. diff --git a/gen/discovery1-cli/README.md b/gen/discovery1-cli/README.md new file mode 100644 index 00000000000..38aa82e3a9b --- /dev/null +++ b/gen/discovery1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DISCOVERY:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/discovery1-cli/mkdocs.yml b/gen/discovery1-cli/mkdocs.yml new file mode 100644 index 00000000000..781e10e1ff4 --- /dev/null +++ b/gen/discovery1-cli/mkdocs.yml @@ -0,0 +1,18 @@ +site_name: discovery v0.0.1+00000000 +site_url: http://byron.github.io/google-apis-rs/google-discovery1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/discovery1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['apis_get-rest.md', 'Apis', 'Get Rest'] +- ['apis_list.md', 'Apis', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/discovery1-cli/src/cmn.rs b/gen/discovery1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/discovery1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/discovery1-cli/src/main.rs b/gen/discovery1-cli/src/main.rs new file mode 100644 index 00000000000..d2ef6d8a0fa --- /dev/null +++ b/gen/discovery1-cli/src/main.rs @@ -0,0 +1,222 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_discovery1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + discovery1 [options] apis get-rest <api> <version> [-p <v>]... [-o <out>] + discovery1 [options] apis list [-p <v>]... [-o <out>] + discovery1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Discovery<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _apis_get_rest(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apis().get_rest(&self.opt.arg_api, &self.opt.arg_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _apis_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apis().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "preferred" => { + call = call.preferred(arg_from_str(value.unwrap_or("false"), err, "preferred", "boolean")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_apis { + if self.opt.cmd_get_rest { + call_result = self._apis_get_rest(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._apis_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "discovery1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "discovery1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Discovery::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/dns1_beta1-cli/Cargo.toml b/gen/dns1_beta1-cli/Cargo.toml new file mode 100644 index 00000000000..a338c806f3e --- /dev/null +++ b/gen/dns1_beta1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-dns1_beta1-cli" +version = "0.0.1+20150114" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with dns (protocol v1beta1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/dns1_beta1-cli" +homepage = "https://developers.google.com/cloud-dns" +documentation = "http://byron.github.io/google-apis-rs/google_dns1_beta1_cli" +license = "MIT" +keywords = ["dns", "google", "cli"] + +[[bin]] +name = "dns1-beta1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-dns1_beta1] +path = "../dns1_beta1" diff --git a/gen/dns1_beta1-cli/LICENSE.md b/gen/dns1_beta1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/dns1_beta1-cli/LICENSE.md @@ -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. diff --git a/gen/dns1_beta1-cli/README.md b/gen/dns1_beta1-cli/README.md new file mode 100644 index 00000000000..c0386d0f3a1 --- /dev/null +++ b/gen/dns1_beta1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DNS:V1BETA1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/dns1_beta1-cli/mkdocs.yml b/gen/dns1_beta1-cli/mkdocs.yml new file mode 100644 index 00000000000..5ec92d0eb2f --- /dev/null +++ b/gen/dns1_beta1-cli/mkdocs.yml @@ -0,0 +1,25 @@ +site_name: dns v0.0.1+20150114 +site_url: http://byron.github.io/google-apis-rs/google-dns1_beta1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/dns1_beta1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['changes_create.md', 'Changes', 'Create'] +- ['changes_get.md', 'Changes', 'Get'] +- ['changes_list.md', 'Changes', 'List'] +- ['managed-zones_create.md', 'Managed Zones', 'Create'] +- ['managed-zones_delete.md', 'Managed Zones', 'Delete'] +- ['managed-zones_get.md', 'Managed Zones', 'Get'] +- ['managed-zones_list.md', 'Managed Zones', 'List'] +- ['projects_get.md', 'Projects', 'Get'] +- ['resource-record-sets_list.md', 'Resource Record Sets', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/dns1_beta1-cli/src/cmn.rs b/gen/dns1_beta1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/dns1_beta1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/dns1_beta1-cli/src/main.rs b/gen/dns1_beta1-cli/src/main.rs new file mode 100644 index 00000000000..cda769750a0 --- /dev/null +++ b/gen/dns1_beta1-cli/src/main.rs @@ -0,0 +1,654 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_dns1_beta1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + dns1-beta1 [options] changes create <project> <managed-zone> -r <kv>... [-p <v>]... [-o <out>] + dns1-beta1 [options] changes get <project> <managed-zone> <change-id> [-p <v>]... [-o <out>] + dns1-beta1 [options] changes list <project> <managed-zone> [-p <v>]... [-o <out>] + dns1-beta1 [options] managed-zones create <project> -r <kv>... [-p <v>]... [-o <out>] + dns1-beta1 [options] managed-zones delete <project> <managed-zone> [-p <v>]... + dns1-beta1 [options] managed-zones get <project> <managed-zone> [-p <v>]... [-o <out>] + dns1-beta1 [options] managed-zones list <project> [-p <v>]... [-o <out>] + dns1-beta1 [options] projects get <project> [-p <v>]... [-o <out>] + dns1-beta1 [options] resource-record-sets list <project> <managed-zone> [-p <v>]... [-o <out>] + dns1-beta1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Dns<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _changes_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Change = Default::default(); + let mut call = self.hub.changes().create(&request, &self.opt.arg_project, &self.opt.arg_managed_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "start-time" => { + request.start_time = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().get(&self.opt.arg_project, &self.opt.arg_managed_zone, &self.opt.arg_change_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().list(&self.opt.arg_project, &self.opt.arg_managed_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "sort-by" => { + call = call.sort_by(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _managed_zones_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ManagedZone = Default::default(); + let mut call = self.hub.managed_zones().create(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name-servers" => { + if request.name_servers.is_none() { + request.name_servers = Some(Default::default()); + } + request.name_servers.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "name-server-set" => { + request.name_server_set = Some(value.unwrap_or("").to_string()); + }, + "dns-name" => { + request.dns_name = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _managed_zones_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.managed_zones().delete(&self.opt.arg_project, &self.opt.arg_managed_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _managed_zones_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.managed_zones().get(&self.opt.arg_project, &self.opt.arg_managed_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _managed_zones_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.managed_zones().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().get(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _resource_record_sets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.resource_record_sets().list(&self.opt.arg_project, &self.opt.arg_managed_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_changes { + if self.opt.cmd_create { + call_result = self._changes_create(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._changes_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._changes_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_managed_zones { + if self.opt.cmd_create { + call_result = self._managed_zones_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._managed_zones_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._managed_zones_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._managed_zones_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_projects { + if self.opt.cmd_get { + call_result = self._projects_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_resource_record_sets { + if self.opt.cmd_list { + call_result = self._resource_record_sets_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "dns1-beta1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "dns1-beta1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Dns::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/doubleclickbidmanager1-cli/Cargo.toml b/gen/doubleclickbidmanager1-cli/Cargo.toml new file mode 100644 index 00000000000..51cf9ce2e06 --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-doubleclickbidmanager1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with DoubleClick Bid Manager (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/doubleclickbidmanager1-cli" +homepage = "https://developers.google.com/bid-manager/" +documentation = "http://byron.github.io/google-apis-rs/google_doubleclickbidmanager1_cli" +license = "MIT" +keywords = ["doubleclickbidmanage", "google", "cli"] + +[[bin]] +name = "doubleclickbidmanager1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-doubleclickbidmanager1] +path = "../doubleclickbidmanager1" diff --git a/gen/doubleclickbidmanager1-cli/LICENSE.md b/gen/doubleclickbidmanager1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/LICENSE.md @@ -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. diff --git a/gen/doubleclickbidmanager1-cli/README.md b/gen/doubleclickbidmanager1-cli/README.md new file mode 100644 index 00000000000..6f2e9c09868 --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DOUBLECLICKBIDMANAGER:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/doubleclickbidmanager1-cli/mkdocs.yml b/gen/doubleclickbidmanager1-cli/mkdocs.yml new file mode 100644 index 00000000000..3d333e5ce32 --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: DoubleClick Bid Manager v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-doubleclickbidmanager1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/doubleclickbidmanager1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['lineitems_downloadlineitems.md', 'Lineitems', 'Downloadlineitems'] +- ['lineitems_uploadlineitems.md', 'Lineitems', 'Uploadlineitems'] +- ['queries_createquery.md', 'Queries', 'Createquery'] +- ['queries_deletequery.md', 'Queries', 'Deletequery'] +- ['queries_getquery.md', 'Queries', 'Getquery'] +- ['queries_listqueries.md', 'Queries', 'Listqueries'] +- ['queries_runquery.md', 'Queries', 'Runquery'] +- ['reports_listreports.md', 'Reports', 'Listreports'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/doubleclickbidmanager1-cli/src/cmn.rs b/gen/doubleclickbidmanager1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/doubleclickbidmanager1-cli/src/main.rs b/gen/doubleclickbidmanager1-cli/src/main.rs new file mode 100644 index 00000000000..6ebdf31b85a --- /dev/null +++ b/gen/doubleclickbidmanager1-cli/src/main.rs @@ -0,0 +1,700 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_doubleclickbidmanager1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + doubleclickbidmanager1 [options] lineitems downloadlineitems -r <kv>... [-p <v>]... [-o <out>] + doubleclickbidmanager1 [options] lineitems uploadlineitems -r <kv>... [-p <v>]... [-o <out>] + doubleclickbidmanager1 [options] queries createquery -r <kv>... [-p <v>]... [-o <out>] + doubleclickbidmanager1 [options] queries deletequery <query-id> [-p <v>]... + doubleclickbidmanager1 [options] queries getquery <query-id> [-p <v>]... [-o <out>] + doubleclickbidmanager1 [options] queries listqueries [-p <v>]... [-o <out>] + doubleclickbidmanager1 [options] queries runquery <query-id> -r <kv>... [-p <v>]... + doubleclickbidmanager1 [options] reports listreports <query-id> [-p <v>]... [-o <out>] + doubleclickbidmanager1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::DoubleClickBidManager<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _lineitems_downloadlineitems(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DownloadLineItemsRequest = Default::default(); + let mut call = self.hub.lineitems().downloadlineitems(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "filter-type" => { + request.filter_type = Some(value.unwrap_or("").to_string()); + }, + "filter-ids" => { + if request.filter_ids.is_none() { + request.filter_ids = Some(Default::default()); + } + request.filter_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "format" => { + request.format = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _lineitems_uploadlineitems(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UploadLineItemsRequest = Default::default(); + let mut call = self.hub.lineitems().uploadlineitems(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "line-items" => { + request.line_items = Some(value.unwrap_or("").to_string()); + }, + "dry-run" => { + request.dry_run = Some(arg_from_str(value.unwrap_or("false"), err, "dry-run", "boolean")); + }, + "format" => { + request.format = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _queries_createquery(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Query = Default::default(); + let mut call = self.hub.queries().createquery(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_metadata_init(request: &mut api::Query) { + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + } + + fn request_params_init(request: &mut api::Query) { + if request.params.is_none() { + request.params = Some(Default::default()); + } + } + + fn request_schedule_init(request: &mut api::Query) { + if request.schedule.is_none() { + request.schedule = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "schedule.end-time-ms" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().end_time_ms = value.unwrap_or("").to_string(); + }, + "schedule.next-run-timezone-code" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().next_run_timezone_code = value.unwrap_or("").to_string(); + }, + "schedule.frequency" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().frequency = value.unwrap_or("").to_string(); + }, + "schedule.next-run-minute-of-day" => { + request_schedule_init(&mut request); + request.schedule.as_mut().unwrap().next_run_minute_of_day = arg_from_str(value.unwrap_or("-0"), err, "schedule.next-run-minute-of-day", "integer"); + }, + "timezone-code" => { + request_schedule_init(&mut request); + request.timezone_code = Some(value.unwrap_or("").to_string()); + }, + "report-data-end-time-ms" => { + request_schedule_init(&mut request); + request.report_data_end_time_ms = Some(value.unwrap_or("").to_string()); + }, + "query-id" => { + request_schedule_init(&mut request); + request.query_id = Some(value.unwrap_or("").to_string()); + }, + "params.metrics" => { + request_params_init(&mut request); + request.params.as_mut().unwrap().metrics.push(value.unwrap_or("").to_string()); + }, + "params.type" => { + request_params_init(&mut request); + request.params.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "params.group-bys" => { + request_params_init(&mut request); + request.params.as_mut().unwrap().group_bys.push(value.unwrap_or("").to_string()); + }, + "params.include-invite-data" => { + request_params_init(&mut request); + request.params.as_mut().unwrap().include_invite_data = arg_from_str(value.unwrap_or("false"), err, "params.include-invite-data", "boolean"); + }, + "report-data-start-time-ms" => { + request_params_init(&mut request); + request.report_data_start_time_ms = Some(value.unwrap_or("").to_string()); + }, + "metadata.google-cloud-storage-path-for-latest-report" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().google_cloud_storage_path_for_latest_report = value.unwrap_or("").to_string(); + }, + "metadata.data-range" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().data_range = value.unwrap_or("").to_string(); + }, + "metadata.format" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().format = value.unwrap_or("").to_string(); + }, + "metadata.locale" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().locale = value.unwrap_or("").to_string(); + }, + "metadata.google-drive-path-for-latest-report" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().google_drive_path_for_latest_report = value.unwrap_or("").to_string(); + }, + "metadata.send-notification" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().send_notification = arg_from_str(value.unwrap_or("false"), err, "metadata.send-notification", "boolean"); + }, + "metadata.share-email-address" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().share_email_address.push(value.unwrap_or("").to_string()); + }, + "metadata.report-count" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().report_count = arg_from_str(value.unwrap_or("-0"), err, "metadata.report-count", "integer"); + }, + "metadata.running" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().running = arg_from_str(value.unwrap_or("false"), err, "metadata.running", "boolean"); + }, + "metadata.latest-report-run-time-ms" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().latest_report_run_time_ms = value.unwrap_or("").to_string(); + }, + "metadata.title" => { + request_metadata_init(&mut request); + request.metadata.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _queries_deletequery(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.queries().deletequery(&self.opt.arg_query_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _queries_getquery(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.queries().getquery(&self.opt.arg_query_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _queries_listqueries(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.queries().listqueries(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _queries_runquery(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RunQueryRequest = Default::default(); + let mut call = self.hub.queries().runquery(&request, &self.opt.arg_query_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "report-data-end-time-ms" => { + request.report_data_end_time_ms = Some(value.unwrap_or("").to_string()); + }, + "timezone-code" => { + request.timezone_code = Some(value.unwrap_or("").to_string()); + }, + "report-data-start-time-ms" => { + request.report_data_start_time_ms = Some(value.unwrap_or("").to_string()); + }, + "data-range" => { + request.data_range = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _reports_listreports(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().listreports(&self.opt.arg_query_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_lineitems { + if self.opt.cmd_downloadlineitems { + call_result = self._lineitems_downloadlineitems(dry_run, &mut err); + } else if self.opt.cmd_uploadlineitems { + call_result = self._lineitems_uploadlineitems(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_queries { + if self.opt.cmd_createquery { + call_result = self._queries_createquery(dry_run, &mut err); + } else if self.opt.cmd_deletequery { + call_result = self._queries_deletequery(dry_run, &mut err); + } else if self.opt.cmd_getquery { + call_result = self._queries_getquery(dry_run, &mut err); + } else if self.opt.cmd_listqueries { + call_result = self._queries_listqueries(dry_run, &mut err); + } else if self.opt.cmd_runquery { + call_result = self._queries_runquery(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_listreports { + call_result = self._reports_listreports(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "doubleclickbidmanager1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "doubleclickbidmanager1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::DoubleClickBidManager::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/doubleclicksearch2-cli/Cargo.toml b/gen/doubleclicksearch2-cli/Cargo.toml new file mode 100644 index 00000000000..84cb42affcd --- /dev/null +++ b/gen/doubleclicksearch2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-doubleclicksearch2-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with doubleclicksearch (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/doubleclicksearch2-cli" +homepage = "https://developers.google.com/doubleclick-search/" +documentation = "http://byron.github.io/google-apis-rs/google_doubleclicksearch2_cli" +license = "MIT" +keywords = ["doubleclicksearch", "google", "cli"] + +[[bin]] +name = "doubleclicksearch2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-doubleclicksearch2] +path = "../doubleclicksearch2" diff --git a/gen/doubleclicksearch2-cli/LICENSE.md b/gen/doubleclicksearch2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/doubleclicksearch2-cli/LICENSE.md @@ -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. diff --git a/gen/doubleclicksearch2-cli/README.md b/gen/doubleclicksearch2-cli/README.md new file mode 100644 index 00000000000..95f5cfe03c8 --- /dev/null +++ b/gen/doubleclicksearch2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DOUBLECLICKSEARCH:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/doubleclicksearch2-cli/mkdocs.yml b/gen/doubleclicksearch2-cli/mkdocs.yml new file mode 100644 index 00000000000..640977eece9 --- /dev/null +++ b/gen/doubleclicksearch2-cli/mkdocs.yml @@ -0,0 +1,26 @@ +site_name: doubleclicksearch v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-doubleclicksearch2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/doubleclicksearch2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['conversion_get.md', 'Conversion', 'Get'] +- ['conversion_insert.md', 'Conversion', 'Insert'] +- ['conversion_patch.md', 'Conversion', 'Patch'] +- ['conversion_update.md', 'Conversion', 'Update'] +- ['conversion_update-availability.md', 'Conversion', 'Update Availability'] +- ['reports_generate.md', 'Reports', 'Generate'] +- ['reports_get.md', 'Reports', 'Get'] +- ['reports_get-file.md', 'Reports', 'Get File'] +- ['reports_request.md', 'Reports', 'Request'] +- ['saved-columns_list.md', 'Saved Columns', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/doubleclicksearch2-cli/src/cmn.rs b/gen/doubleclicksearch2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/doubleclicksearch2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/doubleclicksearch2-cli/src/main.rs b/gen/doubleclicksearch2-cli/src/main.rs new file mode 100644 index 00000000000..da67def8f0c --- /dev/null +++ b/gen/doubleclicksearch2-cli/src/main.rs @@ -0,0 +1,903 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_doubleclicksearch2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + doubleclicksearch2 [options] conversion get <agency-id> <advertiser-id> <engine-account-id> <end-date> <row-count> <start-date> <start-row> [-p <v>]... [-o <out>] + doubleclicksearch2 [options] conversion insert -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] conversion patch <advertiser-id> <agency-id> <end-date> <engine-account-id> <row-count> <start-date> <start-row> -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] conversion update -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] conversion update-availability -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] reports generate -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] reports get <report-id> [-p <v>]... [-o <out>] + doubleclicksearch2 [options] reports get-file <report-id> <report-fragment> [-p <v>]... [-o <out>] + doubleclicksearch2 [options] reports request -r <kv>... [-p <v>]... [-o <out>] + doubleclicksearch2 [options] saved-columns list <agency-id> <advertiser-id> [-p <v>]... [-o <out>] + doubleclicksearch2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Doubleclicksearch<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _conversion_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let end_date: i32 = arg_from_str(&self.opt.arg_end_date, err, "<end-date>", "integer"); + let row_count: i32 = arg_from_str(&self.opt.arg_row_count, err, "<row-count>", "integer"); + let start_date: i32 = arg_from_str(&self.opt.arg_start_date, err, "<start-date>", "integer"); + let start_row: u32 = arg_from_str(&self.opt.arg_start_row, err, "<start-row>", "integer"); + let mut call = self.hub.conversion().get(&self.opt.arg_agency_id, &self.opt.arg_advertiser_id, &self.opt.arg_engine_account_id, end_date, row_count, start_date, start_row); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "criterion-id" => { + call = call.criterion_id(value.unwrap_or("")); + }, + "campaign-id" => { + call = call.campaign_id(value.unwrap_or("")); + }, + "ad-id" => { + call = call.ad_id(value.unwrap_or("")); + }, + "ad-group-id" => { + call = call.ad_group_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _conversion_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ConversionList = Default::default(); + let mut call = self.hub.conversion().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _conversion_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ConversionList = Default::default(); + let end_date: i32 = arg_from_str(&self.opt.arg_end_date, err, "<end-date>", "integer"); + let row_count: i32 = arg_from_str(&self.opt.arg_row_count, err, "<row-count>", "integer"); + let start_date: i32 = arg_from_str(&self.opt.arg_start_date, err, "<start-date>", "integer"); + let start_row: u32 = arg_from_str(&self.opt.arg_start_row, err, "<start-row>", "integer"); + let mut call = self.hub.conversion().patch(&request, &self.opt.arg_advertiser_id, &self.opt.arg_agency_id, end_date, &self.opt.arg_engine_account_id, row_count, start_date, start_row); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _conversion_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ConversionList = Default::default(); + let mut call = self.hub.conversion().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _conversion_update_availability(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UpdateAvailabilityRequest = Default::default(); + let mut call = self.hub.conversion().update_availability(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_generate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ReportRequest = Default::default(); + let mut call = self.hub.reports().generate(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_report_scope_init(request: &mut api::ReportRequest) { + if request.report_scope.is_none() { + request.report_scope = Some(Default::default()); + } + } + + fn request_time_range_init(request: &mut api::ReportRequest) { + if request.time_range.is_none() { + request.time_range = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "report-scope.ad-group-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().ad_group_id = value.unwrap_or("").to_string(); + }, + "report-scope.agency-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().agency_id = value.unwrap_or("").to_string(); + }, + "report-scope.engine-account-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().engine_account_id = value.unwrap_or("").to_string(); + }, + "report-scope.campaign-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().campaign_id = value.unwrap_or("").to_string(); + }, + "report-scope.advertiser-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().advertiser_id = value.unwrap_or("").to_string(); + }, + "report-scope.keyword-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().keyword_id = value.unwrap_or("").to_string(); + }, + "report-scope.ad-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().ad_id = value.unwrap_or("").to_string(); + }, + "max-rows-per-file" => { + request_report_scope_init(&mut request); + request.max_rows_per_file = Some(arg_from_str(value.unwrap_or("-0"), err, "max-rows-per-file", "integer")); + }, + "statistics-currency" => { + request_report_scope_init(&mut request); + request.statistics_currency = Some(value.unwrap_or("").to_string()); + }, + "time-range.changed-metrics-since-timestamp" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().changed_metrics_since_timestamp = value.unwrap_or("").to_string(); + }, + "time-range.end-date" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "time-range.changed-attributes-since-timestamp" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().changed_attributes_since_timestamp = value.unwrap_or("").to_string(); + }, + "time-range.start-date" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "start-row" => { + request_time_range_init(&mut request); + request.start_row = Some(arg_from_str(value.unwrap_or("-0"), err, "start-row", "integer")); + }, + "row-count" => { + request_time_range_init(&mut request); + request.row_count = Some(arg_from_str(value.unwrap_or("-0"), err, "row-count", "integer")); + }, + "report-type" => { + request_time_range_init(&mut request); + request.report_type = Some(value.unwrap_or("").to_string()); + }, + "download-format" => { + request_time_range_init(&mut request); + request.download_format = Some(value.unwrap_or("").to_string()); + }, + "include-deleted-entities" => { + request_time_range_init(&mut request); + request.include_deleted_entities = Some(arg_from_str(value.unwrap_or("false"), err, "include-deleted-entities", "boolean")); + }, + "verify-single-time-zone" => { + request_time_range_init(&mut request); + request.verify_single_time_zone = Some(arg_from_str(value.unwrap_or("false"), err, "verify-single-time-zone", "boolean")); + }, + "include-removed-entities" => { + request_time_range_init(&mut request); + request.include_removed_entities = Some(arg_from_str(value.unwrap_or("false"), err, "include-removed-entities", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().get(&self.opt.arg_report_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_get_file(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let report_fragment: i32 = arg_from_str(&self.opt.arg_report_fragment, err, "<report-fragment>", "integer"); + let mut download_mode = false; + let mut call = self.hub.reports().get_file(&self.opt.arg_report_id, report_fragment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _reports_request(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ReportRequest = Default::default(); + let mut call = self.hub.reports().request(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_report_scope_init(request: &mut api::ReportRequest) { + if request.report_scope.is_none() { + request.report_scope = Some(Default::default()); + } + } + + fn request_time_range_init(request: &mut api::ReportRequest) { + if request.time_range.is_none() { + request.time_range = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "report-scope.ad-group-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().ad_group_id = value.unwrap_or("").to_string(); + }, + "report-scope.agency-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().agency_id = value.unwrap_or("").to_string(); + }, + "report-scope.engine-account-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().engine_account_id = value.unwrap_or("").to_string(); + }, + "report-scope.campaign-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().campaign_id = value.unwrap_or("").to_string(); + }, + "report-scope.advertiser-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().advertiser_id = value.unwrap_or("").to_string(); + }, + "report-scope.keyword-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().keyword_id = value.unwrap_or("").to_string(); + }, + "report-scope.ad-id" => { + request_report_scope_init(&mut request); + request.report_scope.as_mut().unwrap().ad_id = value.unwrap_or("").to_string(); + }, + "max-rows-per-file" => { + request_report_scope_init(&mut request); + request.max_rows_per_file = Some(arg_from_str(value.unwrap_or("-0"), err, "max-rows-per-file", "integer")); + }, + "statistics-currency" => { + request_report_scope_init(&mut request); + request.statistics_currency = Some(value.unwrap_or("").to_string()); + }, + "time-range.changed-metrics-since-timestamp" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().changed_metrics_since_timestamp = value.unwrap_or("").to_string(); + }, + "time-range.end-date" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "time-range.changed-attributes-since-timestamp" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().changed_attributes_since_timestamp = value.unwrap_or("").to_string(); + }, + "time-range.start-date" => { + request_time_range_init(&mut request); + request.time_range.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "start-row" => { + request_time_range_init(&mut request); + request.start_row = Some(arg_from_str(value.unwrap_or("-0"), err, "start-row", "integer")); + }, + "row-count" => { + request_time_range_init(&mut request); + request.row_count = Some(arg_from_str(value.unwrap_or("-0"), err, "row-count", "integer")); + }, + "report-type" => { + request_time_range_init(&mut request); + request.report_type = Some(value.unwrap_or("").to_string()); + }, + "download-format" => { + request_time_range_init(&mut request); + request.download_format = Some(value.unwrap_or("").to_string()); + }, + "include-deleted-entities" => { + request_time_range_init(&mut request); + request.include_deleted_entities = Some(arg_from_str(value.unwrap_or("false"), err, "include-deleted-entities", "boolean")); + }, + "verify-single-time-zone" => { + request_time_range_init(&mut request); + request.verify_single_time_zone = Some(arg_from_str(value.unwrap_or("false"), err, "verify-single-time-zone", "boolean")); + }, + "include-removed-entities" => { + request_time_range_init(&mut request); + request.include_removed_entities = Some(arg_from_str(value.unwrap_or("false"), err, "include-removed-entities", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _saved_columns_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.saved_columns().list(&self.opt.arg_agency_id, &self.opt.arg_advertiser_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_conversion { + if self.opt.cmd_get { + call_result = self._conversion_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._conversion_insert(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._conversion_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._conversion_update(dry_run, &mut err); + } else if self.opt.cmd_update_availability { + call_result = self._conversion_update_availability(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_generate { + call_result = self._reports_generate(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._reports_get(dry_run, &mut err); + } else if self.opt.cmd_get_file { + call_result = self._reports_get_file(dry_run, &mut err); + } else if self.opt.cmd_request { + call_result = self._reports_request(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_saved_columns { + if self.opt.cmd_list { + call_result = self._saved_columns_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "doubleclicksearch2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "doubleclicksearch2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Doubleclicksearch::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/drive2-cli/Cargo.toml b/gen/drive2-cli/Cargo.toml new file mode 100644 index 00000000000..f5755dbc2c3 --- /dev/null +++ b/gen/drive2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-drive2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with drive (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/drive2-cli" +homepage = "https://developers.google.com/drive/" +documentation = "http://byron.github.io/google-apis-rs/google_drive2_cli" +license = "MIT" +keywords = ["drive", "google", "cli"] + +[[bin]] +name = "drive2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-drive2] +path = "../drive2" diff --git a/gen/drive2-cli/LICENSE.md b/gen/drive2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/drive2-cli/LICENSE.md @@ -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. diff --git a/gen/drive2-cli/README.md b/gen/drive2-cli/README.md new file mode 100644 index 00000000000..f608701e6ad --- /dev/null +++ b/gen/drive2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO DRIVE:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/drive2-cli/mkdocs.yml b/gen/drive2-cli/mkdocs.yml new file mode 100644 index 00000000000..37a34c28236 --- /dev/null +++ b/gen/drive2-cli/mkdocs.yml @@ -0,0 +1,75 @@ +site_name: drive v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-drive2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/drive2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['about_get.md', 'About', 'Get'] +- ['apps_get.md', 'Apps', 'Get'] +- ['apps_list.md', 'Apps', 'List'] +- ['changes_get.md', 'Changes', 'Get'] +- ['changes_list.md', 'Changes', 'List'] +- ['changes_watch.md', 'Changes', 'Watch'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['children_delete.md', 'Children', 'Delete'] +- ['children_get.md', 'Children', 'Get'] +- ['children_insert.md', 'Children', 'Insert'] +- ['children_list.md', 'Children', 'List'] +- ['comments_delete.md', 'Comments', 'Delete'] +- ['comments_get.md', 'Comments', 'Get'] +- ['comments_insert.md', 'Comments', 'Insert'] +- ['comments_list.md', 'Comments', 'List'] +- ['comments_patch.md', 'Comments', 'Patch'] +- ['comments_update.md', 'Comments', 'Update'] +- ['files_copy.md', 'Files', 'Copy'] +- ['files_delete.md', 'Files', 'Delete'] +- ['files_empty-trash.md', 'Files', 'Empty Trash'] +- ['files_get.md', 'Files', 'Get'] +- ['files_insert.md', 'Files', 'Insert'] +- ['files_list.md', 'Files', 'List'] +- ['files_patch.md', 'Files', 'Patch'] +- ['files_touch.md', 'Files', 'Touch'] +- ['files_trash.md', 'Files', 'Trash'] +- ['files_untrash.md', 'Files', 'Untrash'] +- ['files_update.md', 'Files', 'Update'] +- ['files_watch.md', 'Files', 'Watch'] +- ['parents_delete.md', 'Parents', 'Delete'] +- ['parents_get.md', 'Parents', 'Get'] +- ['parents_insert.md', 'Parents', 'Insert'] +- ['parents_list.md', 'Parents', 'List'] +- ['permissions_delete.md', 'Permissions', 'Delete'] +- ['permissions_get.md', 'Permissions', 'Get'] +- ['permissions_get-id-for-email.md', 'Permissions', 'Get Id For Email'] +- ['permissions_insert.md', 'Permissions', 'Insert'] +- ['permissions_list.md', 'Permissions', 'List'] +- ['permissions_patch.md', 'Permissions', 'Patch'] +- ['permissions_update.md', 'Permissions', 'Update'] +- ['properties_delete.md', 'Properties', 'Delete'] +- ['properties_get.md', 'Properties', 'Get'] +- ['properties_insert.md', 'Properties', 'Insert'] +- ['properties_list.md', 'Properties', 'List'] +- ['properties_patch.md', 'Properties', 'Patch'] +- ['properties_update.md', 'Properties', 'Update'] +- ['realtime_get.md', 'Realtime', 'Get'] +- ['realtime_update.md', 'Realtime', 'Update'] +- ['replies_delete.md', 'Replies', 'Delete'] +- ['replies_get.md', 'Replies', 'Get'] +- ['replies_insert.md', 'Replies', 'Insert'] +- ['replies_list.md', 'Replies', 'List'] +- ['replies_patch.md', 'Replies', 'Patch'] +- ['replies_update.md', 'Replies', 'Update'] +- ['revisions_delete.md', 'Revisions', 'Delete'] +- ['revisions_get.md', 'Revisions', 'Get'] +- ['revisions_list.md', 'Revisions', 'List'] +- ['revisions_patch.md', 'Revisions', 'Patch'] +- ['revisions_update.md', 'Revisions', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/drive2-cli/src/cmn.rs b/gen/drive2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/drive2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/drive2-cli/src/main.rs b/gen/drive2-cli/src/main.rs new file mode 100644 index 00000000000..f66e33278fc --- /dev/null +++ b/gen/drive2-cli/src/main.rs @@ -0,0 +1,6319 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_drive2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + drive2 [options] about get [-p <v>]... [-o <out>] + drive2 [options] apps get <app-id> [-p <v>]... [-o <out>] + drive2 [options] apps list [-p <v>]... [-o <out>] + drive2 [options] changes get <change-id> [-p <v>]... [-o <out>] + drive2 [options] changes list [-p <v>]... [-o <out>] + drive2 [options] changes watch -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] channels stop -r <kv>... [-p <v>]... + drive2 [options] children delete <folder-id> <child-id> [-p <v>]... + drive2 [options] children get <folder-id> <child-id> [-p <v>]... [-o <out>] + drive2 [options] children insert <folder-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] children list <folder-id> [-p <v>]... [-o <out>] + drive2 [options] comments delete <file-id> <comment-id> [-p <v>]... + drive2 [options] comments get <file-id> <comment-id> [-p <v>]... [-o <out>] + drive2 [options] comments insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] comments list <file-id> [-p <v>]... [-o <out>] + drive2 [options] comments patch <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] comments update <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files copy <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files delete <file-id> [-p <v>]... + drive2 [options] files empty-trash [-p <v>]... + drive2 [options] files get <file-id> [-p <v>]... [-o <out>] + drive2 [options] files insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + drive2 [options] files list [-p <v>]... [-o <out>] + drive2 [options] files patch <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] files touch <file-id> [-p <v>]... [-o <out>] + drive2 [options] files trash <file-id> [-p <v>]... [-o <out>] + drive2 [options] files untrash <file-id> [-p <v>]... [-o <out>] + drive2 [options] files update <file-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + drive2 [options] files watch <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] parents delete <file-id> <parent-id> [-p <v>]... + drive2 [options] parents get <file-id> <parent-id> [-p <v>]... [-o <out>] + drive2 [options] parents insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] parents list <file-id> [-p <v>]... [-o <out>] + drive2 [options] permissions delete <file-id> <permission-id> [-p <v>]... + drive2 [options] permissions get <file-id> <permission-id> [-p <v>]... [-o <out>] + drive2 [options] permissions get-id-for-email <email> [-p <v>]... [-o <out>] + drive2 [options] permissions insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] permissions list <file-id> [-p <v>]... [-o <out>] + drive2 [options] permissions patch <file-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] permissions update <file-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties delete <file-id> <property-key> [-p <v>]... + drive2 [options] properties get <file-id> <property-key> [-p <v>]... [-o <out>] + drive2 [options] properties insert <file-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties list <file-id> [-p <v>]... [-o <out>] + drive2 [options] properties patch <file-id> <property-key> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] properties update <file-id> <property-key> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] realtime get <file-id> [-p <v>]... [-o <out>] + drive2 [options] realtime update <file-id> -u (simple|resumable) <file> <mime> [-p <v>]... + drive2 [options] replies delete <file-id> <comment-id> <reply-id> [-p <v>]... + drive2 [options] replies get <file-id> <comment-id> <reply-id> [-p <v>]... [-o <out>] + drive2 [options] replies insert <file-id> <comment-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] replies list <file-id> <comment-id> [-p <v>]... [-o <out>] + drive2 [options] replies patch <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] replies update <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] revisions delete <file-id> <revision-id> [-p <v>]... + drive2 [options] revisions get <file-id> <revision-id> [-p <v>]... [-o <out>] + drive2 [options] revisions list <file-id> [-p <v>]... [-o <out>] + drive2 [options] revisions patch <file-id> <revision-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 [options] revisions update <file-id> <revision-id> -r <kv>... [-p <v>]... [-o <out>] + drive2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Drive<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _about_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.about().get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "max-change-id-count" => { + call = call.max_change_id_count(arg_from_str(value.unwrap_or("-0"), err, "max-change-id-count", "int64")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _apps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apps().get(&self.opt.arg_app_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _apps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.apps().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language-code" => { + call = call.language_code(value.unwrap_or("")); + }, + "app-filter-mime-types" => { + call = call.app_filter_mime_types(value.unwrap_or("")); + }, + "app-filter-extensions" => { + call = call.app_filter_extensions(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().get(&self.opt.arg_change_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.changes().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _changes_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.changes().watch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-change-id" => { + call = call.start_change_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-subscribed" => { + call = call.include_subscribed(arg_from_str(value.unwrap_or("false"), err, "include-subscribed", "boolean")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _children_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().delete(&self.opt.arg_folder_id, &self.opt.arg_child_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _children_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().get(&self.opt.arg_folder_id, &self.opt.arg_child_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _children_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ChildReference = Default::default(); + let mut call = self.hub.children().insert(&request, &self.opt.arg_folder_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "child-link" => { + request.child_link = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _children_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.children().list(&self.opt.arg_folder_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().delete(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _comments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().get(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Comment = Default::default(); + let mut call = self.hub.comments().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Comment = Default::default(); + let mut call = self.hub.comments().patch(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Comment = Default::default(); + let mut call = self.hub.comments().update(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Comment) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_context_init(request: &mut api::Comment) { + if request.context.is_none() { + request.context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "file-title" => { + request_author_init(&mut request); + request.file_title = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "context.type" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "context.value" => { + request_context_init(&mut request); + request.context.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "created-date" => { + request_context_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "comment-id" => { + request_context_init(&mut request); + request.comment_id = Some(value.unwrap_or("").to_string()); + }, + "anchor" => { + request_context_init(&mut request); + request.anchor = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_context_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "file-id" => { + request_context_init(&mut request); + request.file_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_copy(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::File = Default::default(); + let mut call = self.hub.files().copy(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean"); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean"); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean"); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean"); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean"); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "sharing-user.kind" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "sharing-user.display-name" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "sharing-user.permission-id" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean"); + }, + "sharing-user.email-address" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer"); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = value.unwrap_or("").to_string(); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer"); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + request.open_with_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number"); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number"); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number"); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer"); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number"); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = value.unwrap_or("").to_string(); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = value.unwrap_or("").to_string(); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number"); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number"); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number"); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer"); + }, + "image-media-metadata.height" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer"); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = value.unwrap_or("").to_string(); + }, + "image-media-metadata.date" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer"); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean"); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number"); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer"); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = value.unwrap_or("").to_string(); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = value.unwrap_or("").to_string(); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = value.unwrap_or("").to_string(); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().delete(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _files_empty_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().empty_trash(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _files_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.files().get(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "revision-id" => { + call = call.revision_id(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" => { + if value.unwrap_or("") == "media" { + download_mode = true; + } + call = call.alt(value.unwrap_or("")); + }, + "acknowledge-abuse" => { + call = call.acknowledge_abuse(arg_from_str(value.unwrap_or("false"), err, "acknowledge-abuse", "boolean")); + }, + "fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _files_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::File = Default::default(); + let mut call = self.hub.files().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean"); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean"); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean"); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean"); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean"); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "sharing-user.kind" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "sharing-user.display-name" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "sharing-user.permission-id" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean"); + }, + "sharing-user.email-address" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer"); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = value.unwrap_or("").to_string(); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer"); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + request.open_with_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number"); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number"); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number"); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer"); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number"); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = value.unwrap_or("").to_string(); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = value.unwrap_or("").to_string(); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number"); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number"); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number"); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer"); + }, + "image-media-metadata.height" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer"); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = value.unwrap_or("").to_string(); + }, + "image-media-metadata.date" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer"); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean"); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number"); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer"); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = value.unwrap_or("").to_string(); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = value.unwrap_or("").to_string(); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = value.unwrap_or("").to_string(); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "corpus" => { + call = call.corpus(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::File = Default::default(); + let mut call = self.hub.files().patch(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "set-modified-date" => { + call = call.set_modified_date(arg_from_str(value.unwrap_or("false"), err, "set-modified-date", "boolean")); + }, + "remove-parents" => { + call = call.remove_parents(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "new-revision" => { + call = call.new_revision(arg_from_str(value.unwrap_or("false"), err, "new-revision", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "add-parents" => { + call = call.add_parents(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean"); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean"); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean"); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean"); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean"); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "sharing-user.kind" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "sharing-user.display-name" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "sharing-user.permission-id" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean"); + }, + "sharing-user.email-address" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer"); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = value.unwrap_or("").to_string(); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer"); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + request.open_with_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number"); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number"); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number"); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer"); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number"); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = value.unwrap_or("").to_string(); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = value.unwrap_or("").to_string(); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number"); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number"); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number"); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer"); + }, + "image-media-metadata.height" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer"); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = value.unwrap_or("").to_string(); + }, + "image-media-metadata.date" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer"); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean"); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number"); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer"); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = value.unwrap_or("").to_string(); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = value.unwrap_or("").to_string(); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = value.unwrap_or("").to_string(); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_touch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().touch(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().trash(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_untrash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.files().untrash(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::File = Default::default(); + let mut call = self.hub.files().update(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "use-content-as-indexable-text" => { + call = call.use_content_as_indexable_text(arg_from_str(value.unwrap_or("false"), err, "use-content-as-indexable-text", "boolean")); + }, + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "timed-text-track-name" => { + call = call.timed_text_track_name(value.unwrap_or("")); + }, + "timed-text-language" => { + call = call.timed_text_language(value.unwrap_or("")); + }, + "set-modified-date" => { + call = call.set_modified_date(arg_from_str(value.unwrap_or("false"), err, "set-modified-date", "boolean")); + }, + "remove-parents" => { + call = call.remove_parents(value.unwrap_or("")); + }, + "pinned" => { + call = call.pinned(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "ocr-language" => { + call = call.ocr_language(value.unwrap_or("")); + }, + "ocr" => { + call = call.ocr(arg_from_str(value.unwrap_or("false"), err, "ocr", "boolean")); + }, + "new-revision" => { + call = call.new_revision(arg_from_str(value.unwrap_or("false"), err, "new-revision", "boolean")); + }, + "convert" => { + call = call.convert(arg_from_str(value.unwrap_or("false"), err, "convert", "boolean")); + }, + "add-parents" => { + call = call.add_parents(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_image_media_metadata_init(request: &mut api::File) { + if request.image_media_metadata.is_none() { + request.image_media_metadata = Some(Default::default()); + } + } + + fn request_indexable_text_init(request: &mut api::File) { + if request.indexable_text.is_none() { + request.indexable_text = Some(Default::default()); + } + } + + fn request_labels_init(request: &mut api::File) { + if request.labels.is_none() { + request.labels = Some(Default::default()); + } + } + + fn request_last_modifying_user_init(request: &mut api::File) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + fn request_sharing_user_init(request: &mut api::File) { + if request.sharing_user.is_none() { + request.sharing_user = Some(Default::default()); + } + } + + fn request_thumbnail_init(request: &mut api::File) { + if request.thumbnail.is_none() { + request.thumbnail = Some(Default::default()); + } + } + + fn request_user_permission_init(request: &mut api::File) { + if request.user_permission.is_none() { + request.user_permission = Some(Default::default()); + } + } + + fn request_video_media_metadata_init(request: &mut api::File) { + if request.video_media_metadata.is_none() { + request.video_media_metadata = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "last-viewed-by-me-date" => { + request.last_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "app-data-contents" => { + request.app_data_contents = Some(arg_from_str(value.unwrap_or("false"), err, "app-data-contents", "boolean")); + }, + "thumbnail-link" => { + request.thumbnail_link = Some(value.unwrap_or("").to_string()); + }, + "labels.restricted" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "labels.restricted", "boolean"); + }, + "labels.hidden" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().hidden = arg_from_str(value.unwrap_or("false"), err, "labels.hidden", "boolean"); + }, + "labels.viewed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().viewed = arg_from_str(value.unwrap_or("false"), err, "labels.viewed", "boolean"); + }, + "labels.starred" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().starred = arg_from_str(value.unwrap_or("false"), err, "labels.starred", "boolean"); + }, + "labels.trashed" => { + request_labels_init(&mut request); + request.labels.as_mut().unwrap().trashed = arg_from_str(value.unwrap_or("false"), err, "labels.trashed", "boolean"); + }, + "indexable-text.text" => { + request_indexable_text_init(&mut request); + request.indexable_text.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "explicitly-trashed" => { + request_indexable_text_init(&mut request); + request.explicitly_trashed = Some(arg_from_str(value.unwrap_or("false"), err, "explicitly-trashed", "boolean")); + }, + "etag" => { + request_indexable_text_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_indexable_text_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "writers-can-share" => { + request_indexable_text_init(&mut request); + request.writers_can_share = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-share", "boolean")); + }, + "id" => { + request_indexable_text_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "sharing-user.picture.url" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "sharing-user.kind" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "sharing-user.display-name" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "sharing-user.permission-id" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "sharing-user.is-authenticated-user" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "sharing-user.is-authenticated-user", "boolean"); + }, + "sharing-user.email-address" => { + request_sharing_user_init(&mut request); + request.sharing_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "video-media-metadata.width" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.width", "integer"); + }, + "video-media-metadata.duration-millis" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().duration_millis = value.unwrap_or("").to_string(); + }, + "video-media-metadata.height" => { + request_video_media_metadata_init(&mut request); + request.video_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "video-media-metadata.height", "integer"); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "copyable" => { + request_last_modifying_user_init(&mut request); + request.copyable = Some(arg_from_str(value.unwrap_or("false"), err, "copyable", "boolean")); + }, + "folder-color-rgb" => { + request_last_modifying_user_init(&mut request); + request.folder_color_rgb = Some(value.unwrap_or("").to_string()); + }, + "owner-names" => { + request_last_modifying_user_init(&mut request); + if request.owner_names.is_none() { + request.owner_names = Some(Default::default()); + } + request.owner_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared-with-me-date" => { + request_last_modifying_user_init(&mut request); + request.shared_with_me_date = Some(value.unwrap_or("").to_string()); + }, + "web-view-link" => { + request_last_modifying_user_init(&mut request); + request.web_view_link = Some(value.unwrap_or("").to_string()); + }, + "version" => { + request_last_modifying_user_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "shared" => { + request_last_modifying_user_init(&mut request); + request.shared = Some(arg_from_str(value.unwrap_or("false"), err, "shared", "boolean")); + }, + "thumbnail.mime-type" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "thumbnail.image" => { + request_thumbnail_init(&mut request); + request.thumbnail.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "open-with-links" => { + request_thumbnail_init(&mut request); + if request.open_with_links.is_none() { + request.open_with_links = Some(Default::default()); + } + request.open_with_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-media-metadata.exposure-bias" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_bias = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-bias", "number"); + }, + "image-media-metadata.exposure-time" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_time = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.exposure-time", "number"); + }, + "image-media-metadata.max-aperture-value" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().max_aperture_value = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.max-aperture-value", "number"); + }, + "image-media-metadata.width" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().width = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.width", "integer"); + }, + "image-media-metadata.focal-length" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().focal_length = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.focal-length", "number"); + }, + "image-media-metadata.camera-make" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_make = value.unwrap_or("").to_string(); + }, + "image-media-metadata.exposure-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().exposure_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.color-space" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().color_space = value.unwrap_or("").to_string(); + }, + "image-media-metadata.location.latitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.latitude", "number"); + }, + "image-media-metadata.location.altitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.altitude", "number"); + }, + "image-media-metadata.location.longitude" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.location.longitude", "number"); + }, + "image-media-metadata.subject-distance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().subject_distance = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.subject-distance", "integer"); + }, + "image-media-metadata.height" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().height = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.height", "integer"); + }, + "image-media-metadata.lens" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().lens = value.unwrap_or("").to_string(); + }, + "image-media-metadata.date" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().date = value.unwrap_or("").to_string(); + }, + "image-media-metadata.iso-speed" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().iso_speed = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.iso-speed", "integer"); + }, + "image-media-metadata.metering-mode" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().metering_mode = value.unwrap_or("").to_string(); + }, + "image-media-metadata.flash-used" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().flash_used = arg_from_str(value.unwrap_or("false"), err, "image-media-metadata.flash-used", "boolean"); + }, + "image-media-metadata.aperture" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().aperture = arg_from_str(value.unwrap_or("0.0"), err, "image-media-metadata.aperture", "number"); + }, + "image-media-metadata.rotation" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().rotation = arg_from_str(value.unwrap_or("-0"), err, "image-media-metadata.rotation", "integer"); + }, + "image-media-metadata.sensor" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().sensor = value.unwrap_or("").to_string(); + }, + "image-media-metadata.white-balance" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().white_balance = value.unwrap_or("").to_string(); + }, + "image-media-metadata.camera-model" => { + request_image_media_metadata_init(&mut request); + request.image_media_metadata.as_mut().unwrap().camera_model = value.unwrap_or("").to_string(); + }, + "description" => { + request_image_media_metadata_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "web-content-link" => { + request_image_media_metadata_init(&mut request); + request.web_content_link = Some(value.unwrap_or("").to_string()); + }, + "editable" => { + request_image_media_metadata_init(&mut request); + request.editable = Some(arg_from_str(value.unwrap_or("false"), err, "editable", "boolean")); + }, + "embed-link" => { + request_image_media_metadata_init(&mut request); + request.embed_link = Some(value.unwrap_or("").to_string()); + }, + "marked-viewed-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.marked_viewed_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "quota-bytes-used" => { + request_image_media_metadata_init(&mut request); + request.quota_bytes_used = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_image_media_metadata_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_image_media_metadata_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_image_media_metadata_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "icon-link" => { + request_image_media_metadata_init(&mut request); + request.icon_link = Some(value.unwrap_or("").to_string()); + }, + "default-open-with-link" => { + request_image_media_metadata_init(&mut request); + request.default_open_with_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_image_media_metadata_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "alternate-link" => { + request_image_media_metadata_init(&mut request); + request.alternate_link = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request_image_media_metadata_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "modified-by-me-date" => { + request_image_media_metadata_init(&mut request); + request.modified_by_me_date = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_image_media_metadata_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "user-permission.with-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().with_link = Some(arg_from_str(value.unwrap_or("false"), err, "user-permission.with-link", "boolean")); + }, + "user-permission.domain" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().domain = Some(value.unwrap_or("").to_string()); + }, + "user-permission.name" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "user-permission.kind" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "user-permission.value" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().value = Some(value.unwrap_or("").to_string()); + }, + "user-permission.id" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "user-permission.auth-key" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().auth_key = Some(value.unwrap_or("").to_string()); + }, + "user-permission.etag" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "user-permission.email-address" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().email_address = Some(value.unwrap_or("").to_string()); + }, + "user-permission.photo-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().photo_link = Some(value.unwrap_or("").to_string()); + }, + "user-permission.role" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().role = Some(value.unwrap_or("").to_string()); + }, + "user-permission.type" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "user-permission.additional-roles" => { + request_user_permission_init(&mut request); + if request.user_permission.as_mut().unwrap().additional_roles.is_none() { + request.user_permission.as_mut().unwrap().additional_roles = Some(Default::default()); + } + request.user_permission.as_mut().unwrap().additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "user-permission.self-link" => { + request_user_permission_init(&mut request); + request.user_permission.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_user_permission_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "file-extension" => { + request_user_permission_init(&mut request); + request.file_extension = Some(value.unwrap_or("").to_string()); + }, + "head-revision-id" => { + request_user_permission_init(&mut request); + request.head_revision_id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_user_permission_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_user_permission_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _files_watch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut download_mode = false; + let mut call = self.hub.files().watch(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "update-viewed-date" => { + call = call.update_viewed_date(arg_from_str(value.unwrap_or("false"), err, "update-viewed-date", "boolean")); + }, + "revision-id" => { + call = call.revision_id(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" => { + if value.unwrap_or("") == "media" { + download_mode = true; + } + call = call.alt(value.unwrap_or("")); + }, + "acknowledge-abuse" => { + call = call.acknowledge_abuse(arg_from_str(value.unwrap_or("false"), err, "acknowledge-abuse", "boolean")); + }, + "fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _parents_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().delete(&self.opt.arg_file_id, &self.opt.arg_parent_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _parents_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().get(&self.opt.arg_file_id, &self.opt.arg_parent_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _parents_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ParentReference = Default::default(); + let mut call = self.hub.parents().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "is-root" => { + request.is_root = Some(arg_from_str(value.unwrap_or("false"), err, "is-root", "boolean")); + }, + "parent-link" => { + request.parent_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.parents().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().delete(&self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().get(&self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_get_id_for_email(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().get_id_for_email(&self.opt.arg_email); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Permission = Default::default(); + let mut call = self.hub.permissions().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "send-notification-emails" => { + call = call.send_notification_emails(arg_from_str(value.unwrap_or("false"), err, "send-notification-emails", "boolean")); + }, + "email-message" => { + call = call.email_message(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.permissions().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Permission = Default::default(); + let mut call = self.hub.permissions().patch(&request, &self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "transfer-ownership" => { + call = call.transfer_ownership(arg_from_str(value.unwrap_or("false"), err, "transfer-ownership", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _permissions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Permission = Default::default(); + let mut call = self.hub.permissions().update(&request, &self.opt.arg_file_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "transfer-ownership" => { + call = call.transfer_ownership(arg_from_str(value.unwrap_or("false"), err, "transfer-ownership", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "with-link" => { + request.with_link = Some(arg_from_str(value.unwrap_or("false"), err, "with-link", "boolean")); + }, + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "auth-key" => { + request.auth_key = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "email-address" => { + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "photo-link" => { + request.photo_link = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "additional-roles" => { + if request.additional_roles.is_none() { + request.additional_roles = Some(Default::default()); + } + request.additional_roles.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().delete(&self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _properties_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().get(&self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Property = Default::default(); + let mut call = self.hub.properties().insert(&request, &self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.properties().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Property = Default::default(); + let mut call = self.hub.properties().patch(&request, &self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _properties_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Property = Default::default(); + let mut call = self.hub.properties().update(&request, &self.opt.arg_file_id, &self.opt.arg_property_key); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "visibility" => { + call = call.visibility(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "value" => { + request.value = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "visibility" => { + request.visibility = Some(value.unwrap_or("").to_string()); + }, + "key" => { + request.key = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _realtime_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.realtime().get(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "revision" => { + call = call.revision(arg_from_str(value.unwrap_or("-0"), err, "revision", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _realtime_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.realtime().update(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "base-revision" => { + call = call.base_revision(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _replies_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().delete(&self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _replies_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().get(&self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CommentReply = Default::default(); + let mut call = self.hub.replies().insert(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.replies().list(&self.opt.arg_file_id, &self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CommentReply = Default::default(); + let mut call = self.hub.replies().patch(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _replies_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CommentReply = Default::default(); + let mut call = self.hub.replies().update(&request, &self.opt.arg_file_id, &self.opt.arg_comment_id, &self.opt.arg_reply_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::CommentReply) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "author.picture.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "author.kind" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.permission-id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "author.is-authenticated-user" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "author.is-authenticated-user", "boolean"); + }, + "author.email-address" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "deleted" => { + request_author_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "html-content" => { + request_author_init(&mut request); + request.html_content = Some(value.unwrap_or("").to_string()); + }, + "content" => { + request_author_init(&mut request); + request.content = Some(value.unwrap_or("").to_string()); + }, + "verb" => { + request_author_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "reply-id" => { + request_author_init(&mut request); + request.reply_id = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_author_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "created-date" => { + request_author_init(&mut request); + request.created_date = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().delete(&self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _revisions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().get(&self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().list(&self.opt.arg_file_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Revision = Default::default(); + let mut call = self.hub.revisions().patch(&request, &self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_last_modifying_user_init(request: &mut api::Revision) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "pinned" => { + request.pinned = Some(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "publish-auto" => { + request.publish_auto = Some(arg_from_str(value.unwrap_or("false"), err, "publish-auto", "boolean")); + }, + "published-outside-domain" => { + request.published_outside_domain = Some(arg_from_str(value.unwrap_or("false"), err, "published-outside-domain", "boolean")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "published-link" => { + request_last_modifying_user_init(&mut request); + request.published_link = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_last_modifying_user_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_last_modifying_user_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_last_modifying_user_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_last_modifying_user_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_last_modifying_user_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_last_modifying_user_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_last_modifying_user_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_last_modifying_user_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_last_modifying_user_init(&mut request); + request.published = Some(arg_from_str(value.unwrap_or("false"), err, "published", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Revision = Default::default(); + let mut call = self.hub.revisions().update(&request, &self.opt.arg_file_id, &self.opt.arg_revision_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_last_modifying_user_init(request: &mut api::Revision) { + if request.last_modifying_user.is_none() { + request.last_modifying_user = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "mime-type" => { + request.mime_type = Some(value.unwrap_or("").to_string()); + }, + "pinned" => { + request.pinned = Some(arg_from_str(value.unwrap_or("false"), err, "pinned", "boolean")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "publish-auto" => { + request.publish_auto = Some(arg_from_str(value.unwrap_or("false"), err, "publish-auto", "boolean")); + }, + "published-outside-domain" => { + request.published_outside_domain = Some(arg_from_str(value.unwrap_or("false"), err, "published-outside-domain", "boolean")); + }, + "last-modifying-user.picture.url" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().picture.url = value.unwrap_or("").to_string(); + }, + "last-modifying-user.kind" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "last-modifying-user.display-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "last-modifying-user.permission-id" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().permission_id = value.unwrap_or("").to_string(); + }, + "last-modifying-user.is-authenticated-user" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().is_authenticated_user = arg_from_str(value.unwrap_or("false"), err, "last-modifying-user.is-authenticated-user", "boolean"); + }, + "last-modifying-user.email-address" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user.as_mut().unwrap().email_address = value.unwrap_or("").to_string(); + }, + "published-link" => { + request_last_modifying_user_init(&mut request); + request.published_link = Some(value.unwrap_or("").to_string()); + }, + "download-url" => { + request_last_modifying_user_init(&mut request); + request.download_url = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_last_modifying_user_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_last_modifying_user_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "file-size" => { + request_last_modifying_user_init(&mut request); + request.file_size = Some(value.unwrap_or("").to_string()); + }, + "export-links" => { + request_last_modifying_user_init(&mut request); + if request.export_links.is_none() { + request.export_links = Some(Default::default()); + } + request.export_links.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "last-modifying-user-name" => { + request_last_modifying_user_init(&mut request); + request.last_modifying_user_name = Some(value.unwrap_or("").to_string()); + }, + "modified-date" => { + request_last_modifying_user_init(&mut request); + request.modified_date = Some(value.unwrap_or("").to_string()); + }, + "original-filename" => { + request_last_modifying_user_init(&mut request); + request.original_filename = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_last_modifying_user_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "md5-checksum" => { + request_last_modifying_user_init(&mut request); + request.md5_checksum = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_last_modifying_user_init(&mut request); + request.published = Some(arg_from_str(value.unwrap_or("false"), err, "published", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_about { + if self.opt.cmd_get { + call_result = self._about_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_apps { + if self.opt.cmd_get { + call_result = self._apps_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._apps_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_changes { + if self.opt.cmd_get { + call_result = self._changes_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._changes_list(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._changes_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_children { + if self.opt.cmd_delete { + call_result = self._children_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._children_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._children_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._children_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_comments { + if self.opt.cmd_delete { + call_result = self._comments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._comments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._comments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._comments_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._comments_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._comments_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_files { + if self.opt.cmd_copy { + call_result = self._files_copy(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._files_delete(dry_run, &mut err); + } else if self.opt.cmd_empty_trash { + call_result = self._files_empty_trash(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._files_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._files_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._files_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._files_patch(dry_run, &mut err); + } else if self.opt.cmd_touch { + call_result = self._files_touch(dry_run, &mut err); + } else if self.opt.cmd_trash { + call_result = self._files_trash(dry_run, &mut err); + } else if self.opt.cmd_untrash { + call_result = self._files_untrash(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._files_update(dry_run, &mut err); + } else if self.opt.cmd_watch { + call_result = self._files_watch(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_parents { + if self.opt.cmd_delete { + call_result = self._parents_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._parents_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._parents_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._parents_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_permissions { + if self.opt.cmd_delete { + call_result = self._permissions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._permissions_get(dry_run, &mut err); + } else if self.opt.cmd_get_id_for_email { + call_result = self._permissions_get_id_for_email(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._permissions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._permissions_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._permissions_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._permissions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_properties { + if self.opt.cmd_delete { + call_result = self._properties_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._properties_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._properties_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._properties_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._properties_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._properties_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_realtime { + if self.opt.cmd_get { + call_result = self._realtime_get(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._realtime_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_replies { + if self.opt.cmd_delete { + call_result = self._replies_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._replies_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._replies_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._replies_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._replies_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._replies_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_revisions { + if self.opt.cmd_delete { + call_result = self._revisions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._revisions_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._revisions_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._revisions_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._revisions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "drive2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "drive2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Drive::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/fitness1-cli/Cargo.toml b/gen/fitness1-cli/Cargo.toml new file mode 100644 index 00000000000..220dbba6415 --- /dev/null +++ b/gen/fitness1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-fitness1-cli" +version = "0.0.1+20150222" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with fitness (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/fitness1-cli" +homepage = "https://developers.google.com/fit/rest/" +documentation = "http://byron.github.io/google-apis-rs/google_fitness1_cli" +license = "MIT" +keywords = ["fitness", "google", "cli"] + +[[bin]] +name = "fitness1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-fitness1] +path = "../fitness1" diff --git a/gen/fitness1-cli/LICENSE.md b/gen/fitness1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/fitness1-cli/LICENSE.md @@ -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. diff --git a/gen/fitness1-cli/README.md b/gen/fitness1-cli/README.md new file mode 100644 index 00000000000..d965bec7113 --- /dev/null +++ b/gen/fitness1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO FITNESS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/fitness1-cli/mkdocs.yml b/gen/fitness1-cli/mkdocs.yml new file mode 100644 index 00000000000..c87b7d1cffb --- /dev/null +++ b/gen/fitness1-cli/mkdocs.yml @@ -0,0 +1,27 @@ +site_name: fitness v0.0.1+20150222 +site_url: http://byron.github.io/google-apis-rs/google-fitness1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/fitness1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['users_data-sources-create.md', 'Users', 'Data Sources Create'] +- ['users_data-sources-datasets-delete.md', 'Users', 'Data Sources Datasets Delete'] +- ['users_data-sources-datasets-get.md', 'Users', 'Data Sources Datasets Get'] +- ['users_data-sources-datasets-patch.md', 'Users', 'Data Sources Datasets Patch'] +- ['users_data-sources-get.md', 'Users', 'Data Sources Get'] +- ['users_data-sources-list.md', 'Users', 'Data Sources List'] +- ['users_data-sources-patch.md', 'Users', 'Data Sources Patch'] +- ['users_data-sources-update.md', 'Users', 'Data Sources Update'] +- ['users_sessions-delete.md', 'Users', 'Sessions Delete'] +- ['users_sessions-list.md', 'Users', 'Sessions List'] +- ['users_sessions-update.md', 'Users', 'Sessions Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/fitness1-cli/src/cmn.rs b/gen/fitness1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/fitness1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/fitness1-cli/src/main.rs b/gen/fitness1-cli/src/main.rs new file mode 100644 index 00000000000..b344e5165a1 --- /dev/null +++ b/gen/fitness1-cli/src/main.rs @@ -0,0 +1,1014 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_fitness1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + fitness1 [options] users data-sources-create <user-id> -r <kv>... [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-datasets-delete <user-id> <data-source-id> <dataset-id> [-p <v>]... + fitness1 [options] users data-sources-datasets-get <user-id> <data-source-id> <dataset-id> [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-datasets-patch <user-id> <data-source-id> <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-get <user-id> <data-source-id> [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-list <user-id> [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-patch <user-id> <data-source-id> -r <kv>... [-p <v>]... [-o <out>] + fitness1 [options] users data-sources-update <user-id> <data-source-id> -r <kv>... [-p <v>]... [-o <out>] + fitness1 [options] users sessions-delete <user-id> <session-id> [-p <v>]... + fitness1 [options] users sessions-list <user-id> [-p <v>]... [-o <out>] + fitness1 [options] users sessions-update <user-id> <session-id> -r <kv>... [-p <v>]... [-o <out>] + fitness1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Fitness<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _users_data_sources_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DataSource = Default::default(); + let mut call = self.hub.users().data_sources_create(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_application_init(request: &mut api::DataSource) { + if request.application.is_none() { + request.application = Some(Default::default()); + } + } + + fn request_data_type_init(request: &mut api::DataSource) { + if request.data_type.is_none() { + request.data_type = Some(Default::default()); + } + } + + fn request_device_init(request: &mut api::DataSource) { + if request.device.is_none() { + request.device = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "data-stream-name" => { + request.data_stream_name = Some(value.unwrap_or("").to_string()); + }, + "data-type.name" => { + request_data_type_init(&mut request); + request.data_type.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.package-name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().package_name = value.unwrap_or("").to_string(); + }, + "application.version" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "application.name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.details-url" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().details_url = value.unwrap_or("").to_string(); + }, + "device.model" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().model = value.unwrap_or("").to_string(); + }, + "device.version" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "device.type" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "device.uid" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().uid = value.unwrap_or("").to_string(); + }, + "device.manufacturer" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().manufacturer = value.unwrap_or("").to_string(); + }, + "data-stream-id" => { + request_device_init(&mut request); + request.data_stream_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_device_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_datasets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().data_sources_datasets_delete(&self.opt.arg_user_id, &self.opt.arg_data_source_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "modified-time-millis" => { + call = call.modified_time_millis(value.unwrap_or("")); + }, + "current-time-millis" => { + call = call.current_time_millis(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_data_sources_datasets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().data_sources_datasets_get(&self.opt.arg_user_id, &self.opt.arg_data_source_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_datasets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.users().data_sources_datasets_patch(&request, &self.opt.arg_user_id, &self.opt.arg_data_source_id, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "current-time-millis" => { + call = call.current_time_millis(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "min-start-time-ns" => { + request.min_start_time_ns = Some(value.unwrap_or("").to_string()); + }, + "next-page-token" => { + request.next_page_token = Some(value.unwrap_or("").to_string()); + }, + "max-end-time-ns" => { + request.max_end_time_ns = Some(value.unwrap_or("").to_string()); + }, + "data-source-id" => { + request.data_source_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().data_sources_get(&self.opt.arg_user_id, &self.opt.arg_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().data_sources_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "data-type-name" => { + call = call.add_data_type_name(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DataSource = Default::default(); + let mut call = self.hub.users().data_sources_patch(&request, &self.opt.arg_user_id, &self.opt.arg_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_application_init(request: &mut api::DataSource) { + if request.application.is_none() { + request.application = Some(Default::default()); + } + } + + fn request_data_type_init(request: &mut api::DataSource) { + if request.data_type.is_none() { + request.data_type = Some(Default::default()); + } + } + + fn request_device_init(request: &mut api::DataSource) { + if request.device.is_none() { + request.device = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "data-stream-name" => { + request.data_stream_name = Some(value.unwrap_or("").to_string()); + }, + "data-type.name" => { + request_data_type_init(&mut request); + request.data_type.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.package-name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().package_name = value.unwrap_or("").to_string(); + }, + "application.version" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "application.name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.details-url" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().details_url = value.unwrap_or("").to_string(); + }, + "device.model" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().model = value.unwrap_or("").to_string(); + }, + "device.version" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "device.type" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "device.uid" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().uid = value.unwrap_or("").to_string(); + }, + "device.manufacturer" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().manufacturer = value.unwrap_or("").to_string(); + }, + "data-stream-id" => { + request_device_init(&mut request); + request.data_stream_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_device_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_data_sources_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DataSource = Default::default(); + let mut call = self.hub.users().data_sources_update(&request, &self.opt.arg_user_id, &self.opt.arg_data_source_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_application_init(request: &mut api::DataSource) { + if request.application.is_none() { + request.application = Some(Default::default()); + } + } + + fn request_data_type_init(request: &mut api::DataSource) { + if request.data_type.is_none() { + request.data_type = Some(Default::default()); + } + } + + fn request_device_init(request: &mut api::DataSource) { + if request.device.is_none() { + request.device = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "data-stream-name" => { + request.data_stream_name = Some(value.unwrap_or("").to_string()); + }, + "data-type.name" => { + request_data_type_init(&mut request); + request.data_type.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.package-name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().package_name = value.unwrap_or("").to_string(); + }, + "application.version" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "application.name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.details-url" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().details_url = value.unwrap_or("").to_string(); + }, + "device.model" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().model = value.unwrap_or("").to_string(); + }, + "device.version" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "device.type" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "device.uid" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().uid = value.unwrap_or("").to_string(); + }, + "device.manufacturer" => { + request_device_init(&mut request); + request.device.as_mut().unwrap().manufacturer = value.unwrap_or("").to_string(); + }, + "data-stream-id" => { + request_device_init(&mut request); + request.data_stream_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_device_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_sessions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().sessions_delete(&self.opt.arg_user_id, &self.opt.arg_session_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "current-time-millis" => { + call = call.current_time_millis(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_sessions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().sessions_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-time" => { + call = call.start_time(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "end-time" => { + call = call.end_time(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_sessions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Session = Default::default(); + let mut call = self.hub.users().sessions_update(&request, &self.opt.arg_user_id, &self.opt.arg_session_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "current-time-millis" => { + call = call.current_time_millis(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_application_init(request: &mut api::Session) { + if request.application.is_none() { + request.application = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "modified-time-millis" => { + request.modified_time_millis = Some(value.unwrap_or("").to_string()); + }, + "end-time-millis" => { + request.end_time_millis = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "activity-type" => { + request.activity_type = Some(arg_from_str(value.unwrap_or("-0"), err, "activity-type", "integer")); + }, + "application.package-name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().package_name = value.unwrap_or("").to_string(); + }, + "application.version" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().version = value.unwrap_or("").to_string(); + }, + "application.name" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "application.details-url" => { + request_application_init(&mut request); + request.application.as_mut().unwrap().details_url = value.unwrap_or("").to_string(); + }, + "start-time-millis" => { + request_application_init(&mut request); + request.start_time_millis = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_application_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_application_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_users { + if self.opt.cmd_data_sources_create { + call_result = self._users_data_sources_create(dry_run, &mut err); + } else if self.opt.cmd_data_sources_datasets_delete { + call_result = self._users_data_sources_datasets_delete(dry_run, &mut err); + } else if self.opt.cmd_data_sources_datasets_get { + call_result = self._users_data_sources_datasets_get(dry_run, &mut err); + } else if self.opt.cmd_data_sources_datasets_patch { + call_result = self._users_data_sources_datasets_patch(dry_run, &mut err); + } else if self.opt.cmd_data_sources_get { + call_result = self._users_data_sources_get(dry_run, &mut err); + } else if self.opt.cmd_data_sources_list { + call_result = self._users_data_sources_list(dry_run, &mut err); + } else if self.opt.cmd_data_sources_patch { + call_result = self._users_data_sources_patch(dry_run, &mut err); + } else if self.opt.cmd_data_sources_update { + call_result = self._users_data_sources_update(dry_run, &mut err); + } else if self.opt.cmd_sessions_delete { + call_result = self._users_sessions_delete(dry_run, &mut err); + } else if self.opt.cmd_sessions_list { + call_result = self._users_sessions_list(dry_run, &mut err); + } else if self.opt.cmd_sessions_update { + call_result = self._users_sessions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "fitness1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "fitness1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Fitness::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/freebase1-cli/Cargo.toml b/gen/freebase1-cli/Cargo.toml new file mode 100644 index 00000000000..1fdf64d1772 --- /dev/null +++ b/gen/freebase1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-freebase1-cli" +version = "0.0.1+20150330" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with freebase (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/freebase1-cli" +homepage = "https://developers.google.com/freebase/" +documentation = "http://byron.github.io/google-apis-rs/google_freebase1_cli" +license = "MIT" +keywords = ["freebase", "google", "cli"] + +[[bin]] +name = "freebase1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-freebase1] +path = "../freebase1" diff --git a/gen/freebase1-cli/LICENSE.md b/gen/freebase1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/freebase1-cli/LICENSE.md @@ -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. diff --git a/gen/freebase1-cli/README.md b/gen/freebase1-cli/README.md new file mode 100644 index 00000000000..afecab3fbec --- /dev/null +++ b/gen/freebase1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO FREEBASE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/freebase1-cli/mkdocs.yml b/gen/freebase1-cli/mkdocs.yml new file mode 100644 index 00000000000..00a94f7bf6e --- /dev/null +++ b/gen/freebase1-cli/mkdocs.yml @@ -0,0 +1,18 @@ +site_name: freebase v0.0.1+20150330 +site_url: http://byron.github.io/google-apis-rs/google-freebase1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/freebase1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['methods_reconcile.md', 'Methods', 'Reconcile'] +- ['methods_search.md', 'Methods', 'Search'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/freebase1-cli/src/cmn.rs b/gen/freebase1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/freebase1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/freebase1-cli/src/main.rs b/gen/freebase1-cli/src/main.rs new file mode 100644 index 00000000000..a1449e8a0c3 --- /dev/null +++ b/gen/freebase1-cli/src/main.rs @@ -0,0 +1,310 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_freebase1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + freebase1 [options] methods reconcile [-p <v>]... [-o <out>] + freebase1 [options] methods search [-p <v>]... [-o <out>] + freebase1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Freebase<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _methods_reconcile(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.methods().reconcile(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "prop" => { + call = call.add_prop(value.unwrap_or("")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "lang" => { + call = call.add_lang(value.unwrap_or("")); + }, + "kind" => { + call = call.add_kind(value.unwrap_or("")); + }, + "confidence" => { + call = call.confidence(arg_from_str(value.unwrap_or("0.0"), err, "confidence", "number")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _methods_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.methods().search(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "without" => { + call = call.add_without(value.unwrap_or("")); + }, + "with" => { + call = call.add_with(value.unwrap_or("")); + }, + "type" => { + call = call.add_type(value.unwrap_or("")); + }, + "stemmed" => { + call = call.stemmed(arg_from_str(value.unwrap_or("false"), err, "stemmed", "boolean")); + }, + "spell" => { + call = call.spell(value.unwrap_or("")); + }, + "scoring" => { + call = call.scoring(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "prefixed" => { + call = call.prefixed(arg_from_str(value.unwrap_or("false"), err, "prefixed", "boolean")); + }, + "output" => { + call = call.output(value.unwrap_or("")); + }, + "mql-output" => { + call = call.mql_output(value.unwrap_or("")); + }, + "mid" => { + call = call.add_mid(value.unwrap_or("")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "lang" => { + call = call.add_lang(value.unwrap_or("")); + }, + "indent" => { + call = call.indent(arg_from_str(value.unwrap_or("false"), err, "indent", "boolean")); + }, + "help" => { + call = call.help(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "exact" => { + call = call.exact(arg_from_str(value.unwrap_or("false"), err, "exact", "boolean")); + }, + "encode" => { + call = call.encode(value.unwrap_or("")); + }, + "domain" => { + call = call.add_domain(value.unwrap_or("")); + }, + "cursor" => { + call = call.cursor(arg_from_str(value.unwrap_or("-0"), err, "cursor", "integer")); + }, + "callback" => { + call = call.callback(value.unwrap_or("")); + }, + "as-of-time" => { + call = call.as_of_time(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_methods { + if self.opt.cmd_reconcile { + call_result = self._methods_reconcile(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._methods_search(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "freebase1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "freebase1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Freebase::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/freebase1_sandbox-cli/Cargo.toml b/gen/freebase1_sandbox-cli/Cargo.toml new file mode 100644 index 00000000000..c00cd926a1f --- /dev/null +++ b/gen/freebase1_sandbox-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-freebase1_sandbox-cli" +version = "0.0.1+20150330" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with freebase (protocol v1sandbox)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/freebase1_sandbox-cli" +homepage = "https://developers.google.com/freebase/" +documentation = "http://byron.github.io/google-apis-rs/google_freebase1_sandbox_cli" +license = "MIT" +keywords = ["freebase", "google", "cli"] + +[[bin]] +name = "freebase1-sandbox" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-freebase1_sandbox] +path = "../freebase1_sandbox" diff --git a/gen/freebase1_sandbox-cli/LICENSE.md b/gen/freebase1_sandbox-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/freebase1_sandbox-cli/LICENSE.md @@ -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. diff --git a/gen/freebase1_sandbox-cli/README.md b/gen/freebase1_sandbox-cli/README.md new file mode 100644 index 00000000000..499c4122a9b --- /dev/null +++ b/gen/freebase1_sandbox-cli/README.md @@ -0,0 +1,4 @@ +# HELLO FREEBASE:V1SANDBOX + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/freebase1_sandbox-cli/mkdocs.yml b/gen/freebase1_sandbox-cli/mkdocs.yml new file mode 100644 index 00000000000..a1532ed7e0f --- /dev/null +++ b/gen/freebase1_sandbox-cli/mkdocs.yml @@ -0,0 +1,18 @@ +site_name: freebase v0.0.1+20150330 +site_url: http://byron.github.io/google-apis-rs/google-freebase1_sandbox-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/freebase1_sandbox-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['methods_reconcile.md', 'Methods', 'Reconcile'] +- ['methods_search.md', 'Methods', 'Search'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/freebase1_sandbox-cli/src/cmn.rs b/gen/freebase1_sandbox-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/freebase1_sandbox-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/freebase1_sandbox-cli/src/main.rs b/gen/freebase1_sandbox-cli/src/main.rs new file mode 100644 index 00000000000..9fb21de172a --- /dev/null +++ b/gen/freebase1_sandbox-cli/src/main.rs @@ -0,0 +1,310 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_freebase1_sandbox as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + freebase1-sandbox [options] methods reconcile [-p <v>]... [-o <out>] + freebase1-sandbox [options] methods search [-p <v>]... [-o <out>] + freebase1-sandbox --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Freebase<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _methods_reconcile(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.methods().reconcile(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "prop" => { + call = call.add_prop(value.unwrap_or("")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "lang" => { + call = call.add_lang(value.unwrap_or("")); + }, + "kind" => { + call = call.add_kind(value.unwrap_or("")); + }, + "confidence" => { + call = call.confidence(arg_from_str(value.unwrap_or("0.0"), err, "confidence", "number")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _methods_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.methods().search(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "without" => { + call = call.add_without(value.unwrap_or("")); + }, + "with" => { + call = call.add_with(value.unwrap_or("")); + }, + "type" => { + call = call.add_type(value.unwrap_or("")); + }, + "stemmed" => { + call = call.stemmed(arg_from_str(value.unwrap_or("false"), err, "stemmed", "boolean")); + }, + "spell" => { + call = call.spell(value.unwrap_or("")); + }, + "scoring" => { + call = call.scoring(value.unwrap_or("")); + }, + "query" => { + call = call.query(value.unwrap_or("")); + }, + "prefixed" => { + call = call.prefixed(arg_from_str(value.unwrap_or("false"), err, "prefixed", "boolean")); + }, + "output" => { + call = call.output(value.unwrap_or("")); + }, + "mql-output" => { + call = call.mql_output(value.unwrap_or("")); + }, + "mid" => { + call = call.add_mid(value.unwrap_or("")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "lang" => { + call = call.add_lang(value.unwrap_or("")); + }, + "indent" => { + call = call.indent(arg_from_str(value.unwrap_or("false"), err, "indent", "boolean")); + }, + "help" => { + call = call.help(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "filter" => { + call = call.add_filter(value.unwrap_or("")); + }, + "exact" => { + call = call.exact(arg_from_str(value.unwrap_or("false"), err, "exact", "boolean")); + }, + "encode" => { + call = call.encode(value.unwrap_or("")); + }, + "domain" => { + call = call.add_domain(value.unwrap_or("")); + }, + "cursor" => { + call = call.cursor(arg_from_str(value.unwrap_or("-0"), err, "cursor", "integer")); + }, + "callback" => { + call = call.callback(value.unwrap_or("")); + }, + "as-of-time" => { + call = call.as_of_time(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_methods { + if self.opt.cmd_reconcile { + call_result = self._methods_reconcile(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._methods_search(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "freebase1-sandbox-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "freebase1-sandbox", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Freebase::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/fusiontables2-cli/Cargo.toml b/gen/fusiontables2-cli/Cargo.toml new file mode 100644 index 00000000000..e42614040f8 --- /dev/null +++ b/gen/fusiontables2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-fusiontables2-cli" +version = "0.0.1+20150226" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with fusiontables (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/fusiontables2-cli" +homepage = "https://developers.google.com/fusiontables" +documentation = "http://byron.github.io/google-apis-rs/google_fusiontables2_cli" +license = "MIT" +keywords = ["fusiontables", "google", "cli"] + +[[bin]] +name = "fusiontables2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-fusiontables2] +path = "../fusiontables2" diff --git a/gen/fusiontables2-cli/LICENSE.md b/gen/fusiontables2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/fusiontables2-cli/LICENSE.md @@ -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. diff --git a/gen/fusiontables2-cli/README.md b/gen/fusiontables2-cli/README.md new file mode 100644 index 00000000000..c878747849d --- /dev/null +++ b/gen/fusiontables2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO FUSIONTABLES:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/fusiontables2-cli/mkdocs.yml b/gen/fusiontables2-cli/mkdocs.yml new file mode 100644 index 00000000000..0e44ed848a4 --- /dev/null +++ b/gen/fusiontables2-cli/mkdocs.yml @@ -0,0 +1,49 @@ +site_name: fusiontables v0.0.1+20150226 +site_url: http://byron.github.io/google-apis-rs/google-fusiontables2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/fusiontables2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['column_delete.md', 'Column', 'Delete'] +- ['column_get.md', 'Column', 'Get'] +- ['column_insert.md', 'Column', 'Insert'] +- ['column_list.md', 'Column', 'List'] +- ['column_patch.md', 'Column', 'Patch'] +- ['column_update.md', 'Column', 'Update'] +- ['query_sql.md', 'Query', 'Sql'] +- ['query_sql-get.md', 'Query', 'Sql Get'] +- ['style_delete.md', 'Style', 'Delete'] +- ['style_get.md', 'Style', 'Get'] +- ['style_insert.md', 'Style', 'Insert'] +- ['style_list.md', 'Style', 'List'] +- ['style_patch.md', 'Style', 'Patch'] +- ['style_update.md', 'Style', 'Update'] +- ['table_copy.md', 'Table', 'Copy'] +- ['table_delete.md', 'Table', 'Delete'] +- ['table_get.md', 'Table', 'Get'] +- ['table_import-rows.md', 'Table', 'Import Rows'] +- ['table_import-table.md', 'Table', 'Import Table'] +- ['table_insert.md', 'Table', 'Insert'] +- ['table_list.md', 'Table', 'List'] +- ['table_patch.md', 'Table', 'Patch'] +- ['table_replace-rows.md', 'Table', 'Replace Rows'] +- ['table_update.md', 'Table', 'Update'] +- ['task_delete.md', 'Task', 'Delete'] +- ['task_get.md', 'Task', 'Get'] +- ['task_list.md', 'Task', 'List'] +- ['template_delete.md', 'Template', 'Delete'] +- ['template_get.md', 'Template', 'Get'] +- ['template_insert.md', 'Template', 'Insert'] +- ['template_list.md', 'Template', 'List'] +- ['template_patch.md', 'Template', 'Patch'] +- ['template_update.md', 'Template', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/fusiontables2-cli/src/cmn.rs b/gen/fusiontables2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/fusiontables2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/fusiontables2-cli/src/main.rs b/gen/fusiontables2-cli/src/main.rs new file mode 100644 index 00000000000..8714b8d4ca1 --- /dev/null +++ b/gen/fusiontables2-cli/src/main.rs @@ -0,0 +1,2836 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_fusiontables2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + fusiontables2 [options] column delete <table-id> <column-id> [-p <v>]... + fusiontables2 [options] column get <table-id> <column-id> [-p <v>]... [-o <out>] + fusiontables2 [options] column insert <table-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] column list <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] column patch <table-id> <column-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] column update <table-id> <column-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] query sql <sql> [-p <v>]... [-o <out>] + fusiontables2 [options] query sql-get <sql> [-p <v>]... [-o <out>] + fusiontables2 [options] style delete <table-id> <style-id> [-p <v>]... + fusiontables2 [options] style get <table-id> <style-id> [-p <v>]... [-o <out>] + fusiontables2 [options] style insert <table-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] style list <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] style patch <table-id> <style-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] style update <table-id> <style-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] table copy <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] table delete <table-id> [-p <v>]... + fusiontables2 [options] table get <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] table import-rows <table-id> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + fusiontables2 [options] table import-table <name> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + fusiontables2 [options] table insert -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] table list [-p <v>]... [-o <out>] + fusiontables2 [options] table patch <table-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] table replace-rows <table-id> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + fusiontables2 [options] table update <table-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] task delete <table-id> <task-id> [-p <v>]... + fusiontables2 [options] task get <table-id> <task-id> [-p <v>]... [-o <out>] + fusiontables2 [options] task list <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] template delete <table-id> <template-id> [-p <v>]... + fusiontables2 [options] template get <table-id> <template-id> [-p <v>]... [-o <out>] + fusiontables2 [options] template insert <table-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] template list <table-id> [-p <v>]... [-o <out>] + fusiontables2 [options] template patch <table-id> <template-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 [options] template update <table-id> <template-id> -r <kv>... [-p <v>]... [-o <out>] + fusiontables2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Fusiontables<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _column_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.column().delete(&self.opt.arg_table_id, &self.opt.arg_column_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _column_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.column().get(&self.opt.arg_table_id, &self.opt.arg_column_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _column_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Column = Default::default(); + let mut call = self.hub.column().insert(&request, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_base_column_init(request: &mut api::Column) { + if request.base_column.is_none() { + request.base_column = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "graph-predicate" => { + request.graph_predicate = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "valid-values" => { + if request.valid_values.is_none() { + request.valid_values = Some(Default::default()); + } + request.valid_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "base-column.table-index" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().table_index = arg_from_str(value.unwrap_or("-0"), err, "base-column.table-index", "integer"); + }, + "base-column.column-id" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().column_id = arg_from_str(value.unwrap_or("-0"), err, "base-column.column-id", "integer"); + }, + "name" => { + request_base_column_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json" => { + request_base_column_init(&mut request); + request.column_properties_json = Some(value.unwrap_or("").to_string()); + }, + "format-pattern" => { + request_base_column_init(&mut request); + request.format_pattern = Some(value.unwrap_or("").to_string()); + }, + "column-json-schema" => { + request_base_column_init(&mut request); + request.column_json_schema = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_base_column_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "validate-data" => { + request_base_column_init(&mut request); + request.validate_data = Some(arg_from_str(value.unwrap_or("false"), err, "validate-data", "boolean")); + }, + "column-id" => { + request_base_column_init(&mut request); + request.column_id = Some(arg_from_str(value.unwrap_or("-0"), err, "column-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _column_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.column().list(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _column_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Column = Default::default(); + let mut call = self.hub.column().patch(&request, &self.opt.arg_table_id, &self.opt.arg_column_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_base_column_init(request: &mut api::Column) { + if request.base_column.is_none() { + request.base_column = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "graph-predicate" => { + request.graph_predicate = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "valid-values" => { + if request.valid_values.is_none() { + request.valid_values = Some(Default::default()); + } + request.valid_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "base-column.table-index" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().table_index = arg_from_str(value.unwrap_or("-0"), err, "base-column.table-index", "integer"); + }, + "base-column.column-id" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().column_id = arg_from_str(value.unwrap_or("-0"), err, "base-column.column-id", "integer"); + }, + "name" => { + request_base_column_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json" => { + request_base_column_init(&mut request); + request.column_properties_json = Some(value.unwrap_or("").to_string()); + }, + "format-pattern" => { + request_base_column_init(&mut request); + request.format_pattern = Some(value.unwrap_or("").to_string()); + }, + "column-json-schema" => { + request_base_column_init(&mut request); + request.column_json_schema = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_base_column_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "validate-data" => { + request_base_column_init(&mut request); + request.validate_data = Some(arg_from_str(value.unwrap_or("false"), err, "validate-data", "boolean")); + }, + "column-id" => { + request_base_column_init(&mut request); + request.column_id = Some(arg_from_str(value.unwrap_or("-0"), err, "column-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _column_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Column = Default::default(); + let mut call = self.hub.column().update(&request, &self.opt.arg_table_id, &self.opt.arg_column_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_base_column_init(request: &mut api::Column) { + if request.base_column.is_none() { + request.base_column = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "graph-predicate" => { + request.graph_predicate = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "valid-values" => { + if request.valid_values.is_none() { + request.valid_values = Some(Default::default()); + } + request.valid_values.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "base-column.table-index" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().table_index = arg_from_str(value.unwrap_or("-0"), err, "base-column.table-index", "integer"); + }, + "base-column.column-id" => { + request_base_column_init(&mut request); + request.base_column.as_mut().unwrap().column_id = arg_from_str(value.unwrap_or("-0"), err, "base-column.column-id", "integer"); + }, + "name" => { + request_base_column_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json" => { + request_base_column_init(&mut request); + request.column_properties_json = Some(value.unwrap_or("").to_string()); + }, + "format-pattern" => { + request_base_column_init(&mut request); + request.format_pattern = Some(value.unwrap_or("").to_string()); + }, + "column-json-schema" => { + request_base_column_init(&mut request); + request.column_json_schema = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_base_column_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "validate-data" => { + request_base_column_init(&mut request); + request.validate_data = Some(arg_from_str(value.unwrap_or("false"), err, "validate-data", "boolean")); + }, + "column-id" => { + request_base_column_init(&mut request); + request.column_id = Some(arg_from_str(value.unwrap_or("-0"), err, "column-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _query_sql(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.query().sql(&self.opt.arg_sql); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "typed" => { + call = call.typed(arg_from_str(value.unwrap_or("false"), err, "typed", "boolean")); + }, + "hdrs" => { + call = call.hdrs(arg_from_str(value.unwrap_or("false"), err, "hdrs", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _query_sql_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.query().sql_get(&self.opt.arg_sql); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "typed" => { + call = call.typed(arg_from_str(value.unwrap_or("false"), err, "typed", "boolean")); + }, + "hdrs" => { + call = call.hdrs(arg_from_str(value.unwrap_or("false"), err, "hdrs", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _style_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let style_id: i32 = arg_from_str(&self.opt.arg_style_id, err, "<style-id>", "integer"); + let mut call = self.hub.style().delete(&self.opt.arg_table_id, style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _style_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let style_id: i32 = arg_from_str(&self.opt.arg_style_id, err, "<style-id>", "integer"); + let mut call = self.hub.style().get(&self.opt.arg_table_id, style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _style_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::StyleSetting = Default::default(); + let mut call = self.hub.style().insert(&request, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_marker_options_init(request: &mut api::StyleSetting) { + if request.marker_options.is_none() { + request.marker_options = Some(Default::default()); + } + } + + fn request_polygon_options_init(request: &mut api::StyleSetting) { + if request.polygon_options.is_none() { + request.polygon_options = Some(Default::default()); + } + } + + fn request_polyline_options_init(request: &mut api::StyleSetting) { + if request.polyline_options.is_none() { + request.polyline_options = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "marker-options.icon-styler.gradient.max" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.max", "number"); + }, + "marker-options.icon-styler.gradient.min" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.min", "number"); + }, + "marker-options.icon-styler.column-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.column_name = value.unwrap_or("").to_string(); + }, + "marker-options.icon-styler.kind" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.kind = value.unwrap_or("").to_string(); + }, + "marker-options.icon-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_name = value.unwrap_or("").to_string(); + }, + "kind" => { + request_marker_options_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_marker_options_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "polygon-options.stroke-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.max", "number"); + }, + "polygon-options.stroke-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.min", "number"); + }, + "polygon-options.stroke-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polygon-options.stroke-weight", "integer"); + }, + "polygon-options.stroke-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-opacity", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.max", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.min", "number"); + }, + "polygon-options.stroke-weight-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.max", "number"); + }, + "polygon-options.fill-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.min", "number"); + }, + "polygon-options.fill-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-opacity", "number"); + }, + "polyline-options.stroke-weight" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polyline-options.stroke-weight", "integer"); + }, + "polyline-options.stroke-weight-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.max", "number"); + }, + "polyline-options.stroke-weight-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.min", "number"); + }, + "polyline-options.stroke-weight-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-weight-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-opacity" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-opacity", "number"); + }, + "polyline-options.stroke-color-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.max", "number"); + }, + "polyline-options.stroke-color-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.min", "number"); + }, + "polyline-options.stroke-color-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "table-id" => { + request_polyline_options_init(&mut request); + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "style-id" => { + request_polyline_options_init(&mut request); + request.style_id = Some(arg_from_str(value.unwrap_or("-0"), err, "style-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _style_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.style().list(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _style_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::StyleSetting = Default::default(); + let style_id: i32 = arg_from_str(&self.opt.arg_style_id, err, "<style-id>", "integer"); + let mut call = self.hub.style().patch(&request, &self.opt.arg_table_id, style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_marker_options_init(request: &mut api::StyleSetting) { + if request.marker_options.is_none() { + request.marker_options = Some(Default::default()); + } + } + + fn request_polygon_options_init(request: &mut api::StyleSetting) { + if request.polygon_options.is_none() { + request.polygon_options = Some(Default::default()); + } + } + + fn request_polyline_options_init(request: &mut api::StyleSetting) { + if request.polyline_options.is_none() { + request.polyline_options = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "marker-options.icon-styler.gradient.max" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.max", "number"); + }, + "marker-options.icon-styler.gradient.min" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.min", "number"); + }, + "marker-options.icon-styler.column-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.column_name = value.unwrap_or("").to_string(); + }, + "marker-options.icon-styler.kind" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.kind = value.unwrap_or("").to_string(); + }, + "marker-options.icon-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_name = value.unwrap_or("").to_string(); + }, + "kind" => { + request_marker_options_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_marker_options_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "polygon-options.stroke-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.max", "number"); + }, + "polygon-options.stroke-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.min", "number"); + }, + "polygon-options.stroke-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polygon-options.stroke-weight", "integer"); + }, + "polygon-options.stroke-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-opacity", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.max", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.min", "number"); + }, + "polygon-options.stroke-weight-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.max", "number"); + }, + "polygon-options.fill-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.min", "number"); + }, + "polygon-options.fill-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-opacity", "number"); + }, + "polyline-options.stroke-weight" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polyline-options.stroke-weight", "integer"); + }, + "polyline-options.stroke-weight-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.max", "number"); + }, + "polyline-options.stroke-weight-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.min", "number"); + }, + "polyline-options.stroke-weight-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-weight-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-opacity" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-opacity", "number"); + }, + "polyline-options.stroke-color-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.max", "number"); + }, + "polyline-options.stroke-color-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.min", "number"); + }, + "polyline-options.stroke-color-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "table-id" => { + request_polyline_options_init(&mut request); + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "style-id" => { + request_polyline_options_init(&mut request); + request.style_id = Some(arg_from_str(value.unwrap_or("-0"), err, "style-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _style_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::StyleSetting = Default::default(); + let style_id: i32 = arg_from_str(&self.opt.arg_style_id, err, "<style-id>", "integer"); + let mut call = self.hub.style().update(&request, &self.opt.arg_table_id, style_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_marker_options_init(request: &mut api::StyleSetting) { + if request.marker_options.is_none() { + request.marker_options = Some(Default::default()); + } + } + + fn request_polygon_options_init(request: &mut api::StyleSetting) { + if request.polygon_options.is_none() { + request.polygon_options = Some(Default::default()); + } + } + + fn request_polyline_options_init(request: &mut api::StyleSetting) { + if request.polyline_options.is_none() { + request.polyline_options = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "marker-options.icon-styler.gradient.max" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.max", "number"); + }, + "marker-options.icon-styler.gradient.min" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "marker-options.icon-styler.gradient.min", "number"); + }, + "marker-options.icon-styler.column-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.column_name = value.unwrap_or("").to_string(); + }, + "marker-options.icon-styler.kind" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_styler.kind = value.unwrap_or("").to_string(); + }, + "marker-options.icon-name" => { + request_marker_options_init(&mut request); + request.marker_options.as_mut().unwrap().icon_name = value.unwrap_or("").to_string(); + }, + "kind" => { + request_marker_options_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_marker_options_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "polygon-options.stroke-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.max", "number"); + }, + "polygon-options.stroke-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-color-styler.gradient.min", "number"); + }, + "polygon-options.stroke-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polygon-options.stroke-weight", "integer"); + }, + "polygon-options.stroke-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-opacity", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.max", "number"); + }, + "polygon-options.stroke-weight-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.stroke-weight-styler.gradient.min", "number"); + }, + "polygon-options.stroke-weight-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-weight-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.gradient.max" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.max", "number"); + }, + "polygon-options.fill-color-styler.gradient.min" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-color-styler.gradient.min", "number"); + }, + "polygon-options.fill-color-styler.column-name" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color-styler.kind" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color_styler.kind = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_color = value.unwrap_or("").to_string(); + }, + "polygon-options.stroke-color" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polygon-options.fill-opacity" => { + request_polygon_options_init(&mut request); + request.polygon_options.as_mut().unwrap().fill_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polygon-options.fill-opacity", "number"); + }, + "polyline-options.stroke-weight" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight = arg_from_str(value.unwrap_or("-0"), err, "polyline-options.stroke-weight", "integer"); + }, + "polyline-options.stroke-weight-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.max", "number"); + }, + "polyline-options.stroke-weight-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-weight-styler.gradient.min", "number"); + }, + "polyline-options.stroke-weight-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-weight-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_weight_styler.kind = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-opacity" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_opacity = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-opacity", "number"); + }, + "polyline-options.stroke-color-styler.gradient.max" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.max = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.max", "number"); + }, + "polyline-options.stroke-color-styler.gradient.min" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.gradient.min = arg_from_str(value.unwrap_or("0.0"), err, "polyline-options.stroke-color-styler.gradient.min", "number"); + }, + "polyline-options.stroke-color-styler.column-name" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.column_name = value.unwrap_or("").to_string(); + }, + "polyline-options.stroke-color-styler.kind" => { + request_polyline_options_init(&mut request); + request.polyline_options.as_mut().unwrap().stroke_color_styler.kind = value.unwrap_or("").to_string(); + }, + "table-id" => { + request_polyline_options_init(&mut request); + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "style-id" => { + request_polyline_options_init(&mut request); + request.style_id = Some(arg_from_str(value.unwrap_or("-0"), err, "style-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_copy(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().copy(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "copy-presentation" => { + call = call.copy_presentation(arg_from_str(value.unwrap_or("false"), err, "copy-presentation", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().delete(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _table_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().get(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_import_rows(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().import_rows(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-line" => { + call = call.start_line(arg_from_str(value.unwrap_or("-0"), err, "start-line", "integer")); + }, + "is-strict" => { + call = call.is_strict(arg_from_str(value.unwrap_or("false"), err, "is-strict", "boolean")); + }, + "end-line" => { + call = call.end_line(arg_from_str(value.unwrap_or("-0"), err, "end-line", "integer")); + }, + "encoding" => { + call = call.encoding(value.unwrap_or("")); + }, + "delimiter" => { + call = call.delimiter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_import_table(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().import_table(&self.opt.arg_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "encoding" => { + call = call.encoding(value.unwrap_or("")); + }, + "delimiter" => { + call = call.delimiter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.table().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "table-properties-json-schema" => { + request.table_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "attribution" => { + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json-schema" => { + request.column_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "is-exportable" => { + request.is_exportable = Some(arg_from_str(value.unwrap_or("false"), err, "is-exportable", "boolean")); + }, + "base-table-ids" => { + if request.base_table_ids.is_none() { + request.base_table_ids = Some(Default::default()); + } + request.base_table_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-properties-json" => { + request.table_properties_json = Some(value.unwrap_or("").to_string()); + }, + "attribution-link" => { + request.attribution_link = Some(value.unwrap_or("").to_string()); + }, + "sql" => { + request.sql = Some(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.table().patch(&request, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "replace-view-definition" => { + call = call.replace_view_definition(arg_from_str(value.unwrap_or("false"), err, "replace-view-definition", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "table-properties-json-schema" => { + request.table_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "attribution" => { + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json-schema" => { + request.column_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "is-exportable" => { + request.is_exportable = Some(arg_from_str(value.unwrap_or("false"), err, "is-exportable", "boolean")); + }, + "base-table-ids" => { + if request.base_table_ids.is_none() { + request.base_table_ids = Some(Default::default()); + } + request.base_table_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-properties-json" => { + request.table_properties_json = Some(value.unwrap_or("").to_string()); + }, + "attribution-link" => { + request.attribution_link = Some(value.unwrap_or("").to_string()); + }, + "sql" => { + request.sql = Some(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_replace_rows(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.table().replace_rows(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-line" => { + call = call.start_line(arg_from_str(value.unwrap_or("-0"), err, "start-line", "integer")); + }, + "is-strict" => { + call = call.is_strict(arg_from_str(value.unwrap_or("false"), err, "is-strict", "boolean")); + }, + "end-line" => { + call = call.end_line(arg_from_str(value.unwrap_or("-0"), err, "end-line", "integer")); + }, + "encoding" => { + call = call.encoding(value.unwrap_or("")); + }, + "delimiter" => { + call = call.delimiter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _table_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.table().update(&request, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "replace-view-definition" => { + call = call.replace_view_definition(arg_from_str(value.unwrap_or("false"), err, "replace-view-definition", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "table-properties-json-schema" => { + request.table_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "attribution" => { + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "column-properties-json-schema" => { + request.column_properties_json_schema = Some(value.unwrap_or("").to_string()); + }, + "is-exportable" => { + request.is_exportable = Some(arg_from_str(value.unwrap_or("false"), err, "is-exportable", "boolean")); + }, + "base-table-ids" => { + if request.base_table_ids.is_none() { + request.base_table_ids = Some(Default::default()); + } + request.base_table_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-properties-json" => { + request.table_properties_json = Some(value.unwrap_or("").to_string()); + }, + "attribution-link" => { + request.attribution_link = Some(value.unwrap_or("").to_string()); + }, + "sql" => { + request.sql = Some(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _task_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.task().delete(&self.opt.arg_table_id, &self.opt.arg_task_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _task_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.task().get(&self.opt.arg_table_id, &self.opt.arg_task_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _task_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.task().list(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _template_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let template_id: i32 = arg_from_str(&self.opt.arg_template_id, err, "<template-id>", "integer"); + let mut call = self.hub.template().delete(&self.opt.arg_table_id, template_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _template_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let template_id: i32 = arg_from_str(&self.opt.arg_template_id, err, "<template-id>", "integer"); + let mut call = self.hub.template().get(&self.opt.arg_table_id, template_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _template_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Template = Default::default(); + let mut call = self.hub.template().insert(&request, &self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "automatic-column-names" => { + if request.automatic_column_names.is_none() { + request.automatic_column_names = Some(Default::default()); + } + request.automatic_column_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "template-id" => { + request.template_id = Some(arg_from_str(value.unwrap_or("-0"), err, "template-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _template_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.template().list(&self.opt.arg_table_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _template_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Template = Default::default(); + let template_id: i32 = arg_from_str(&self.opt.arg_template_id, err, "<template-id>", "integer"); + let mut call = self.hub.template().patch(&request, &self.opt.arg_table_id, template_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "automatic-column-names" => { + if request.automatic_column_names.is_none() { + request.automatic_column_names = Some(Default::default()); + } + request.automatic_column_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "template-id" => { + request.template_id = Some(arg_from_str(value.unwrap_or("-0"), err, "template-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _template_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Template = Default::default(); + let template_id: i32 = arg_from_str(&self.opt.arg_template_id, err, "<template-id>", "integer"); + let mut call = self.hub.template().update(&request, &self.opt.arg_table_id, template_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "body" => { + request.body = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "automatic-column-names" => { + if request.automatic_column_names.is_none() { + request.automatic_column_names = Some(Default::default()); + } + request.automatic_column_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "table-id" => { + request.table_id = Some(value.unwrap_or("").to_string()); + }, + "template-id" => { + request.template_id = Some(arg_from_str(value.unwrap_or("-0"), err, "template-id", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_column { + if self.opt.cmd_delete { + call_result = self._column_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._column_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._column_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._column_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._column_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._column_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_query { + if self.opt.cmd_sql { + call_result = self._query_sql(dry_run, &mut err); + } else if self.opt.cmd_sql_get { + call_result = self._query_sql_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_style { + if self.opt.cmd_delete { + call_result = self._style_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._style_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._style_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._style_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._style_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._style_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_table { + if self.opt.cmd_copy { + call_result = self._table_copy(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._table_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._table_get(dry_run, &mut err); + } else if self.opt.cmd_import_rows { + call_result = self._table_import_rows(dry_run, &mut err); + } else if self.opt.cmd_import_table { + call_result = self._table_import_table(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._table_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._table_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._table_patch(dry_run, &mut err); + } else if self.opt.cmd_replace_rows { + call_result = self._table_replace_rows(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._table_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_task { + if self.opt.cmd_delete { + call_result = self._task_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._task_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._task_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_template { + if self.opt.cmd_delete { + call_result = self._template_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._template_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._template_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._template_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._template_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._template_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "fusiontables2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "fusiontables2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Fusiontables::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/games1-cli/Cargo.toml b/gen/games1-cli/Cargo.toml new file mode 100644 index 00000000000..f7a551f3776 --- /dev/null +++ b/gen/games1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-games1-cli" +version = "0.0.1+20150325" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Games (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/games1-cli" +homepage = "https://developers.google.com/games/services/" +documentation = "http://byron.github.io/google-apis-rs/google_games1_cli" +license = "MIT" +keywords = ["games", "google", "cli"] + +[[bin]] +name = "games1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-games1] +path = "../games1" diff --git a/gen/games1-cli/LICENSE.md b/gen/games1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/games1-cli/LICENSE.md @@ -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. diff --git a/gen/games1-cli/README.md b/gen/games1-cli/README.md new file mode 100644 index 00000000000..f03dc20a846 --- /dev/null +++ b/gen/games1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GAMES:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/games1-cli/mkdocs.yml b/gen/games1-cli/mkdocs.yml new file mode 100644 index 00000000000..163358d6fbd --- /dev/null +++ b/gen/games1-cli/mkdocs.yml @@ -0,0 +1,68 @@ +site_name: Games v0.0.1+20150325 +site_url: http://byron.github.io/google-apis-rs/google-games1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/games1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['achievement-definitions_list.md', 'Achievement Definitions', 'List'] +- ['achievements_increment.md', 'Achievements', 'Increment'] +- ['achievements_list.md', 'Achievements', 'List'] +- ['achievements_reveal.md', 'Achievements', 'Reveal'] +- ['achievements_set-steps-at-least.md', 'Achievements', 'Set Steps At Least'] +- ['achievements_unlock.md', 'Achievements', 'Unlock'] +- ['achievements_update-multiple.md', 'Achievements', 'Update Multiple'] +- ['applications_get.md', 'Applications', 'Get'] +- ['applications_played.md', 'Applications', 'Played'] +- ['events_list-by-player.md', 'Events', 'List By Player'] +- ['events_list-definitions.md', 'Events', 'List Definitions'] +- ['events_record.md', 'Events', 'Record'] +- ['leaderboards_get.md', 'Leaderboards', 'Get'] +- ['leaderboards_list.md', 'Leaderboards', 'List'] +- ['metagame_get-metagame-config.md', 'Metagame', 'Get Metagame Config'] +- ['metagame_list-categories-by-player.md', 'Metagame', 'List Categories By Player'] +- ['players_get.md', 'Players', 'Get'] +- ['players_list.md', 'Players', 'List'] +- ['pushtokens_remove.md', 'Pushtokens', 'Remove'] +- ['pushtokens_update.md', 'Pushtokens', 'Update'] +- ['quest-milestones_claim.md', 'Quest Milestones', 'Claim'] +- ['quests_accept.md', 'Quests', 'Accept'] +- ['quests_list.md', 'Quests', 'List'] +- ['revisions_check.md', 'Revisions', 'Check'] +- ['rooms_create.md', 'Rooms', 'Create'] +- ['rooms_decline.md', 'Rooms', 'Decline'] +- ['rooms_dismiss.md', 'Rooms', 'Dismiss'] +- ['rooms_get.md', 'Rooms', 'Get'] +- ['rooms_join.md', 'Rooms', 'Join'] +- ['rooms_leave.md', 'Rooms', 'Leave'] +- ['rooms_list.md', 'Rooms', 'List'] +- ['rooms_report-status.md', 'Rooms', 'Report Status'] +- ['scores_get.md', 'Scores', 'Get'] +- ['scores_list.md', 'Scores', 'List'] +- ['scores_list-window.md', 'Scores', 'List Window'] +- ['scores_submit.md', 'Scores', 'Submit'] +- ['scores_submit-multiple.md', 'Scores', 'Submit Multiple'] +- ['snapshots_get.md', 'Snapshots', 'Get'] +- ['snapshots_list.md', 'Snapshots', 'List'] +- ['turn-based-matches_cancel.md', 'Turn Based Matches', 'Cancel'] +- ['turn-based-matches_create.md', 'Turn Based Matches', 'Create'] +- ['turn-based-matches_decline.md', 'Turn Based Matches', 'Decline'] +- ['turn-based-matches_dismiss.md', 'Turn Based Matches', 'Dismiss'] +- ['turn-based-matches_finish.md', 'Turn Based Matches', 'Finish'] +- ['turn-based-matches_get.md', 'Turn Based Matches', 'Get'] +- ['turn-based-matches_join.md', 'Turn Based Matches', 'Join'] +- ['turn-based-matches_leave.md', 'Turn Based Matches', 'Leave'] +- ['turn-based-matches_leave-turn.md', 'Turn Based Matches', 'Leave Turn'] +- ['turn-based-matches_list.md', 'Turn Based Matches', 'List'] +- ['turn-based-matches_rematch.md', 'Turn Based Matches', 'Rematch'] +- ['turn-based-matches_sync.md', 'Turn Based Matches', 'Sync'] +- ['turn-based-matches_take-turn.md', 'Turn Based Matches', 'Take Turn'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/games1-cli/src/cmn.rs b/gen/games1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/games1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/games1-cli/src/main.rs b/gen/games1-cli/src/main.rs new file mode 100644 index 00000000000..4e2d3905043 --- /dev/null +++ b/gen/games1-cli/src/main.rs @@ -0,0 +1,3366 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_games1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + games1 [options] achievement-definitions list [-p <v>]... [-o <out>] + games1 [options] achievements increment <achievement-id> <steps-to-increment> [-p <v>]... [-o <out>] + games1 [options] achievements list <player-id> [-p <v>]... [-o <out>] + games1 [options] achievements reveal <achievement-id> [-p <v>]... [-o <out>] + games1 [options] achievements set-steps-at-least <achievement-id> <steps> [-p <v>]... [-o <out>] + games1 [options] achievements unlock <achievement-id> [-p <v>]... [-o <out>] + games1 [options] achievements update-multiple -r <kv>... [-p <v>]... [-o <out>] + games1 [options] applications get <application-id> [-p <v>]... [-o <out>] + games1 [options] applications played [-p <v>]... + games1 [options] events list-by-player [-p <v>]... [-o <out>] + games1 [options] events list-definitions [-p <v>]... [-o <out>] + games1 [options] events record -r <kv>... [-p <v>]... [-o <out>] + games1 [options] leaderboards get <leaderboard-id> [-p <v>]... [-o <out>] + games1 [options] leaderboards list [-p <v>]... [-o <out>] + games1 [options] metagame get-metagame-config [-p <v>]... [-o <out>] + games1 [options] metagame list-categories-by-player <player-id> <collection> [-p <v>]... [-o <out>] + games1 [options] players get <player-id> [-p <v>]... [-o <out>] + games1 [options] players list <collection> [-p <v>]... [-o <out>] + games1 [options] pushtokens remove -r <kv>... [-p <v>]... + games1 [options] pushtokens update -r <kv>... [-p <v>]... + games1 [options] quest-milestones claim <quest-id> <milestone-id> <request-id> [-p <v>]... + games1 [options] quests accept <quest-id> [-p <v>]... [-o <out>] + games1 [options] quests list <player-id> [-p <v>]... [-o <out>] + games1 [options] revisions check <client-revision> [-p <v>]... [-o <out>] + games1 [options] rooms create -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms decline <room-id> [-p <v>]... [-o <out>] + games1 [options] rooms dismiss <room-id> [-p <v>]... + games1 [options] rooms get <room-id> [-p <v>]... [-o <out>] + games1 [options] rooms join <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms leave <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] rooms list [-p <v>]... [-o <out>] + games1 [options] rooms report-status <room-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] scores get <player-id> <leaderboard-id> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores list <leaderboard-id> <collection> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores list-window <leaderboard-id> <collection> <time-span> [-p <v>]... [-o <out>] + games1 [options] scores submit <leaderboard-id> <score> [-p <v>]... [-o <out>] + games1 [options] scores submit-multiple -r <kv>... [-p <v>]... [-o <out>] + games1 [options] snapshots get <snapshot-id> [-p <v>]... [-o <out>] + games1 [options] snapshots list <player-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches cancel <match-id> [-p <v>]... + games1 [options] turn-based-matches create -r <kv>... [-p <v>]... [-o <out>] + games1 [options] turn-based-matches decline <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches dismiss <match-id> [-p <v>]... + games1 [options] turn-based-matches finish <match-id> -r <kv>... [-p <v>]... [-o <out>] + games1 [options] turn-based-matches get <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches join <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches leave <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches leave-turn <match-id> <match-version> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches list [-p <v>]... [-o <out>] + games1 [options] turn-based-matches rematch <match-id> [-p <v>]... [-o <out>] + games1 [options] turn-based-matches sync [-p <v>]... [-o <out>] + games1 [options] turn-based-matches take-turn <match-id> -r <kv>... [-p <v>]... [-o <out>] + games1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Games<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _achievement_definitions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievement_definitions().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_increment(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let steps_to_increment: i32 = arg_from_str(&self.opt.arg_steps_to_increment, err, "<steps-to-increment>", "integer"); + let mut call = self.hub.achievements().increment(&self.opt.arg_achievement_id, steps_to_increment); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "request-id" => { + call = call.request_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "state" => { + call = call.state(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_reveal(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reveal(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_set_steps_at_least(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let steps: i32 = arg_from_str(&self.opt.arg_steps, err, "<steps>", "integer"); + let mut call = self.hub.achievements().set_steps_at_least(&self.opt.arg_achievement_id, steps); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_unlock(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().unlock(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_update_multiple(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AchievementUpdateMultipleRequest = Default::default(); + let mut call = self.hub.achievements().update_multiple(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _applications_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.applications().get(&self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "platform-type" => { + call = call.platform_type(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _applications_played(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.applications().played(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_list_by_player(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().list_by_player(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_list_definitions(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().list_definitions(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_record(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::EventRecordRequest = Default::default(); + let mut call = self.hub.events().record(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "request-id" => { + request.request_id = Some(value.unwrap_or("").to_string()); + }, + "current-time-millis" => { + request.current_time_millis = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboards_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboards().get(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboards_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboards().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metagame_get_metagame_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.metagame().get_metagame_config(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _metagame_list_categories_by_player(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.metagame().list_categories_by_player(&self.opt.arg_player_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _players_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().get(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _players_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().list(&self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _pushtokens_remove(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PushTokenId = Default::default(); + let mut call = self.hub.pushtokens().remove(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_ios_init(request: &mut api::PushTokenId) { + if request.ios.is_none() { + request.ios = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "ios.apns-device-token" => { + request_ios_init(&mut request); + request.ios.as_mut().unwrap().apns_device_token = value.unwrap_or("").to_string(); + }, + "ios.apns-environment" => { + request_ios_init(&mut request); + request.ios.as_mut().unwrap().apns_environment = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _pushtokens_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PushToken = Default::default(); + let mut call = self.hub.pushtokens().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_id_init(request: &mut api::PushToken) { + if request.id.is_none() { + request.id = Some(Default::default()); + } + } + + fn request_id_ios_init(request: &mut api::PushToken) { + request_id_init(request); + if request.id.as_mut().unwrap().ios.is_none() { + request.id.as_mut().unwrap().ios = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "client-revision" => { + request.client_revision = Some(value.unwrap_or("").to_string()); + }, + "id.kind" => { + request_id_init(&mut request); + request.id.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "id.ios.apns-device-token" => { + request_id_ios_init(&mut request); + request.id.as_mut().unwrap().ios.as_mut().unwrap().apns_device_token = value.unwrap_or("").to_string(); + }, + "id.ios.apns-environment" => { + request_id_ios_init(&mut request); + request.id.as_mut().unwrap().ios.as_mut().unwrap().apns_environment = value.unwrap_or("").to_string(); + }, + "language" => { + request_id_init(&mut request); + request.language = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quest_milestones_claim(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quest_milestones().claim(&self.opt.arg_quest_id, &self.opt.arg_milestone_id, &self.opt.arg_request_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_accept(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().accept(&self.opt.arg_quest_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _quests_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _revisions_check(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.revisions().check(&self.opt.arg_client_revision); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RoomCreateRequest = Default::default(); + let mut call = self.hub.rooms().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_auto_matching_criteria_init(request: &mut api::RoomCreateRequest) { + if request.auto_matching_criteria.is_none() { + request.auto_matching_criteria = Some(Default::default()); + } + } + + fn request_client_address_init(request: &mut api::RoomCreateRequest) { + if request.client_address.is_none() { + request.client_address = Some(Default::default()); + } + } + + fn request_network_diagnostics_init(request: &mut api::RoomCreateRequest) { + if request.network_diagnostics.is_none() { + request.network_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.kind" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "auto-matching-criteria.min-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().min_auto_matching_players = arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.min-auto-matching-players", "integer"); + }, + "auto-matching-criteria.exclusive-bitmask" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().exclusive_bitmask = value.unwrap_or("").to_string(); + }, + "auto-matching-criteria.max-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().max_auto_matching_players = arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.max-auto-matching-players", "integer"); + }, + "invited-player-ids" => { + request_auto_matching_criteria_init(&mut request); + if request.invited_player_ids.is_none() { + request.invited_player_ids = Some(Default::default()); + } + request.invited_player_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "variant" => { + request_auto_matching_criteria_init(&mut request); + request.variant = Some(arg_from_str(value.unwrap_or("-0"), err, "variant", "integer")); + }, + "capabilities" => { + request_auto_matching_criteria_init(&mut request); + if request.capabilities.is_none() { + request.capabilities = Some(Default::default()); + } + request.capabilities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "network-diagnostics.kind" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "network-diagnostics.ios-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().ios_network_type = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.ios-network-type", "integer"); + }, + "network-diagnostics.network-operator-code" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_code = value.unwrap_or("").to_string(); + }, + "network-diagnostics.android-network-subtype" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_subtype = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-subtype", "integer"); + }, + "network-diagnostics.network-operator-name" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_name = value.unwrap_or("").to_string(); + }, + "network-diagnostics.registration-latency-millis" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().registration_latency_millis = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.registration-latency-millis", "integer"); + }, + "network-diagnostics.android-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_type = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-type", "integer"); + }, + "client-address.kind" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "client-address.xmpp-address" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().xmpp_address = value.unwrap_or("").to_string(); + }, + "request-id" => { + request_client_address_init(&mut request); + request.request_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_decline(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().decline(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_dismiss(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().dismiss(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rooms_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().get(&self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_join(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RoomJoinRequest = Default::default(); + let mut call = self.hub.rooms().join(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_client_address_init(request: &mut api::RoomJoinRequest) { + if request.client_address.is_none() { + request.client_address = Some(Default::default()); + } + } + + fn request_network_diagnostics_init(request: &mut api::RoomJoinRequest) { + if request.network_diagnostics.is_none() { + request.network_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "network-diagnostics.kind" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "network-diagnostics.ios-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().ios_network_type = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.ios-network-type", "integer"); + }, + "network-diagnostics.network-operator-code" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_code = value.unwrap_or("").to_string(); + }, + "network-diagnostics.android-network-subtype" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_subtype = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-subtype", "integer"); + }, + "network-diagnostics.network-operator-name" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().network_operator_name = value.unwrap_or("").to_string(); + }, + "network-diagnostics.registration-latency-millis" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().registration_latency_millis = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.registration-latency-millis", "integer"); + }, + "network-diagnostics.android-network-type" => { + request_network_diagnostics_init(&mut request); + request.network_diagnostics.as_mut().unwrap().android_network_type = arg_from_str(value.unwrap_or("-0"), err, "network-diagnostics.android-network-type", "integer"); + }, + "client-address.kind" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "client-address.xmpp-address" => { + request_client_address_init(&mut request); + request.client_address.as_mut().unwrap().xmpp_address = value.unwrap_or("").to_string(); + }, + "kind" => { + request_client_address_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "capabilities" => { + request_client_address_init(&mut request); + if request.capabilities.is_none() { + request.capabilities = Some(Default::default()); + } + request.capabilities.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_leave(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RoomLeaveRequest = Default::default(); + let mut call = self.hub.rooms().leave(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_leave_diagnostics_init(request: &mut api::RoomLeaveRequest) { + if request.leave_diagnostics.is_none() { + request.leave_diagnostics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "reason" => { + request.reason = Some(value.unwrap_or("").to_string()); + }, + "leave-diagnostics.kind" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "leave-diagnostics.sockets-used" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().sockets_used = arg_from_str(value.unwrap_or("false"), err, "leave-diagnostics.sockets-used", "boolean"); + }, + "leave-diagnostics.ios-network-type" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().ios_network_type = arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.ios-network-type", "integer"); + }, + "leave-diagnostics.network-operator-code" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().network_operator_code = value.unwrap_or("").to_string(); + }, + "leave-diagnostics.android-network-subtype" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().android_network_subtype = arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.android-network-subtype", "integer"); + }, + "leave-diagnostics.network-operator-name" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().network_operator_name = value.unwrap_or("").to_string(); + }, + "leave-diagnostics.android-network-type" => { + request_leave_diagnostics_init(&mut request); + request.leave_diagnostics.as_mut().unwrap().android_network_type = arg_from_str(value.unwrap_or("-0"), err, "leave-diagnostics.android-network-type", "integer"); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rooms_report_status(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RoomP2PStatuses = Default::default(); + let mut call = self.hub.rooms().report_status(&request, &self.opt.arg_room_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().get(&self.opt.arg_player_id, &self.opt.arg_leaderboard_id, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-rank-type" => { + call = call.include_rank_type(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().list(&self.opt.arg_leaderboard_id, &self.opt.arg_collection, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_list_window(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().list_window(&self.opt.arg_leaderboard_id, &self.opt.arg_collection, &self.opt.arg_time_span); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "return-top-if-absent" => { + call = call.return_top_if_absent(arg_from_str(value.unwrap_or("false"), err, "return-top-if-absent", "boolean")); + }, + "results-above" => { + call = call.results_above(arg_from_str(value.unwrap_or("-0"), err, "results-above", "integer")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_submit(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().submit(&self.opt.arg_leaderboard_id, &self.opt.arg_score); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "score-tag" => { + call = call.score_tag(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_submit_multiple(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlayerScoreSubmissionList = Default::default(); + let mut call = self.hub.scores().submit_multiple(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.snapshots().get(&self.opt.arg_snapshot_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _snapshots_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.snapshots().list(&self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_cancel(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().cancel(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _turn_based_matches_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TurnBasedMatchCreateRequest = Default::default(); + let mut call = self.hub.turn_based_matches().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_auto_matching_criteria_init(request: &mut api::TurnBasedMatchCreateRequest) { + if request.auto_matching_criteria.is_none() { + request.auto_matching_criteria = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "invited-player-ids" => { + if request.invited_player_ids.is_none() { + request.invited_player_ids = Some(Default::default()); + } + request.invited_player_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "auto-matching-criteria.kind" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "auto-matching-criteria.min-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().min_auto_matching_players = arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.min-auto-matching-players", "integer"); + }, + "auto-matching-criteria.exclusive-bitmask" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().exclusive_bitmask = value.unwrap_or("").to_string(); + }, + "auto-matching-criteria.max-auto-matching-players" => { + request_auto_matching_criteria_init(&mut request); + request.auto_matching_criteria.as_mut().unwrap().max_auto_matching_players = arg_from_str(value.unwrap_or("-0"), err, "auto-matching-criteria.max-auto-matching-players", "integer"); + }, + "variant" => { + request_auto_matching_criteria_init(&mut request); + request.variant = Some(arg_from_str(value.unwrap_or("-0"), err, "variant", "integer")); + }, + "request-id" => { + request_auto_matching_criteria_init(&mut request); + request.request_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_decline(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().decline(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_dismiss(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().dismiss(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _turn_based_matches_finish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TurnBasedMatchResults = Default::default(); + let mut call = self.hub.turn_based_matches().finish(&request, &self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_data_init(request: &mut api::TurnBasedMatchResults) { + if request.data.is_none() { + request.data = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "data.kind" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "data.data" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().data = value.unwrap_or("").to_string(); + }, + "match-version" => { + request_data_init(&mut request); + request.match_version = Some(arg_from_str(value.unwrap_or("-0"), err, "match-version", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().get(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_join(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().join(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_leave(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().leave(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_leave_turn(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let match_version: i32 = arg_from_str(&self.opt.arg_match_version, err, "<match-version>", "integer"); + let mut call = self.hub.turn_based_matches().leave_turn(&self.opt.arg_match_id, match_version); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "pending-participant-id" => { + call = call.pending_participant_id(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-completed-matches" => { + call = call.max_completed_matches(arg_from_str(value.unwrap_or("-0"), err, "max-completed-matches", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_rematch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().rematch(&self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "request-id" => { + call = call.request_id(value.unwrap_or("")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_sync(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().sync(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "max-completed-matches" => { + call = call.max_completed_matches(arg_from_str(value.unwrap_or("-0"), err, "max-completed-matches", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "include-match-data" => { + call = call.include_match_data(arg_from_str(value.unwrap_or("false"), err, "include-match-data", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _turn_based_matches_take_turn(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TurnBasedMatchTurn = Default::default(); + let mut call = self.hub.turn_based_matches().take_turn(&request, &self.opt.arg_match_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_data_init(request: &mut api::TurnBasedMatchTurn) { + if request.data.is_none() { + request.data = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "data.kind" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "data.data" => { + request_data_init(&mut request); + request.data.as_mut().unwrap().data = value.unwrap_or("").to_string(); + }, + "match-version" => { + request_data_init(&mut request); + request.match_version = Some(arg_from_str(value.unwrap_or("-0"), err, "match-version", "integer")); + }, + "pending-participant-id" => { + request_data_init(&mut request); + request.pending_participant_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_achievement_definitions { + if self.opt.cmd_list { + call_result = self._achievement_definitions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_achievements { + if self.opt.cmd_increment { + call_result = self._achievements_increment(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._achievements_list(dry_run, &mut err); + } else if self.opt.cmd_reveal { + call_result = self._achievements_reveal(dry_run, &mut err); + } else if self.opt.cmd_set_steps_at_least { + call_result = self._achievements_set_steps_at_least(dry_run, &mut err); + } else if self.opt.cmd_unlock { + call_result = self._achievements_unlock(dry_run, &mut err); + } else if self.opt.cmd_update_multiple { + call_result = self._achievements_update_multiple(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_applications { + if self.opt.cmd_get { + call_result = self._applications_get(dry_run, &mut err); + } else if self.opt.cmd_played { + call_result = self._applications_played(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_events { + if self.opt.cmd_list_by_player { + call_result = self._events_list_by_player(dry_run, &mut err); + } else if self.opt.cmd_list_definitions { + call_result = self._events_list_definitions(dry_run, &mut err); + } else if self.opt.cmd_record { + call_result = self._events_record(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_leaderboards { + if self.opt.cmd_get { + call_result = self._leaderboards_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._leaderboards_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_metagame { + if self.opt.cmd_get_metagame_config { + call_result = self._metagame_get_metagame_config(dry_run, &mut err); + } else if self.opt.cmd_list_categories_by_player { + call_result = self._metagame_list_categories_by_player(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_players { + if self.opt.cmd_get { + call_result = self._players_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._players_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_pushtokens { + if self.opt.cmd_remove { + call_result = self._pushtokens_remove(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._pushtokens_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_quest_milestones { + if self.opt.cmd_claim { + call_result = self._quest_milestones_claim(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_quests { + if self.opt.cmd_accept { + call_result = self._quests_accept(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._quests_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_revisions { + if self.opt.cmd_check { + call_result = self._revisions_check(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_rooms { + if self.opt.cmd_create { + call_result = self._rooms_create(dry_run, &mut err); + } else if self.opt.cmd_decline { + call_result = self._rooms_decline(dry_run, &mut err); + } else if self.opt.cmd_dismiss { + call_result = self._rooms_dismiss(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._rooms_get(dry_run, &mut err); + } else if self.opt.cmd_join { + call_result = self._rooms_join(dry_run, &mut err); + } else if self.opt.cmd_leave { + call_result = self._rooms_leave(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._rooms_list(dry_run, &mut err); + } else if self.opt.cmd_report_status { + call_result = self._rooms_report_status(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_scores { + if self.opt.cmd_get { + call_result = self._scores_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._scores_list(dry_run, &mut err); + } else if self.opt.cmd_list_window { + call_result = self._scores_list_window(dry_run, &mut err); + } else if self.opt.cmd_submit { + call_result = self._scores_submit(dry_run, &mut err); + } else if self.opt.cmd_submit_multiple { + call_result = self._scores_submit_multiple(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_snapshots { + if self.opt.cmd_get { + call_result = self._snapshots_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._snapshots_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_turn_based_matches { + if self.opt.cmd_cancel { + call_result = self._turn_based_matches_cancel(dry_run, &mut err); + } else if self.opt.cmd_create { + call_result = self._turn_based_matches_create(dry_run, &mut err); + } else if self.opt.cmd_decline { + call_result = self._turn_based_matches_decline(dry_run, &mut err); + } else if self.opt.cmd_dismiss { + call_result = self._turn_based_matches_dismiss(dry_run, &mut err); + } else if self.opt.cmd_finish { + call_result = self._turn_based_matches_finish(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._turn_based_matches_get(dry_run, &mut err); + } else if self.opt.cmd_join { + call_result = self._turn_based_matches_join(dry_run, &mut err); + } else if self.opt.cmd_leave { + call_result = self._turn_based_matches_leave(dry_run, &mut err); + } else if self.opt.cmd_leave_turn { + call_result = self._turn_based_matches_leave_turn(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._turn_based_matches_list(dry_run, &mut err); + } else if self.opt.cmd_rematch { + call_result = self._turn_based_matches_rematch(dry_run, &mut err); + } else if self.opt.cmd_sync { + call_result = self._turn_based_matches_sync(dry_run, &mut err); + } else if self.opt.cmd_take_turn { + call_result = self._turn_based_matches_take_turn(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "games1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "games1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Games::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/games1/src/cmn.rs b/gen/games1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/games1/src/cmn.rs +++ b/gen/games1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/gamesconfiguration1_configuration-cli/Cargo.toml b/gen/gamesconfiguration1_configuration-cli/Cargo.toml new file mode 100644 index 00000000000..bc8c9787279 --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-gamesconfiguration1_configuration-cli" +version = "0.0.1+20150325" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Games Configuration (protocol v1configuration)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/gamesconfiguration1_configuration-cli" +homepage = "https://developers.google.com/games/services" +documentation = "http://byron.github.io/google-apis-rs/google_gamesconfiguration1_configuration_cli" +license = "MIT" +keywords = ["gamesConfiguration", "google", "cli"] + +[[bin]] +name = "gamesconfiguration1-configuration" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-gamesconfiguration1_configuration] +path = "../gamesconfiguration1_configuration" diff --git a/gen/gamesconfiguration1_configuration-cli/LICENSE.md b/gen/gamesconfiguration1_configuration-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/LICENSE.md @@ -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. diff --git a/gen/gamesconfiguration1_configuration-cli/README.md b/gen/gamesconfiguration1_configuration-cli/README.md new file mode 100644 index 00000000000..70e029245ec --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GAMESCONFIGURATION:V1CONFIGURATION + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/gamesconfiguration1_configuration-cli/mkdocs.yml b/gen/gamesconfiguration1_configuration-cli/mkdocs.yml new file mode 100644 index 00000000000..c11c8648da6 --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/mkdocs.yml @@ -0,0 +1,29 @@ +site_name: Games Configuration v0.0.1+20150325 +site_url: http://byron.github.io/google-apis-rs/google-gamesconfiguration1_configuration-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/gamesconfiguration1_configuration-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['achievement-configurations_delete.md', 'Achievement Configurations', 'Delete'] +- ['achievement-configurations_get.md', 'Achievement Configurations', 'Get'] +- ['achievement-configurations_insert.md', 'Achievement Configurations', 'Insert'] +- ['achievement-configurations_list.md', 'Achievement Configurations', 'List'] +- ['achievement-configurations_patch.md', 'Achievement Configurations', 'Patch'] +- ['achievement-configurations_update.md', 'Achievement Configurations', 'Update'] +- ['image-configurations_upload.md', 'Image Configurations', 'Upload'] +- ['leaderboard-configurations_delete.md', 'Leaderboard Configurations', 'Delete'] +- ['leaderboard-configurations_get.md', 'Leaderboard Configurations', 'Get'] +- ['leaderboard-configurations_insert.md', 'Leaderboard Configurations', 'Insert'] +- ['leaderboard-configurations_list.md', 'Leaderboard Configurations', 'List'] +- ['leaderboard-configurations_patch.md', 'Leaderboard Configurations', 'Patch'] +- ['leaderboard-configurations_update.md', 'Leaderboard Configurations', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/gamesconfiguration1_configuration-cli/src/cmn.rs b/gen/gamesconfiguration1_configuration-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/gamesconfiguration1_configuration-cli/src/main.rs b/gen/gamesconfiguration1_configuration-cli/src/main.rs new file mode 100644 index 00000000000..c3bdf6253fb --- /dev/null +++ b/gen/gamesconfiguration1_configuration-cli/src/main.rs @@ -0,0 +1,1483 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_gamesconfiguration1_configuration as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + gamesconfiguration1-configuration [options] achievement-configurations delete <achievement-id> [-p <v>]... + gamesconfiguration1-configuration [options] achievement-configurations get <achievement-id> [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] achievement-configurations insert <application-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] achievement-configurations list <application-id> [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] achievement-configurations patch <achievement-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] achievement-configurations update <achievement-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] image-configurations upload <resource-id> <image-type> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] leaderboard-configurations delete <leaderboard-id> [-p <v>]... + gamesconfiguration1-configuration [options] leaderboard-configurations get <leaderboard-id> [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] leaderboard-configurations insert <application-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] leaderboard-configurations list <application-id> [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] leaderboard-configurations patch <leaderboard-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration [options] leaderboard-configurations update <leaderboard-id> -r <kv>... [-p <v>]... [-o <out>] + gamesconfiguration1-configuration --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::GamesConfiguration<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _achievement_configurations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievement_configurations().delete(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _achievement_configurations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievement_configurations().get(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievement_configurations_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AchievementConfiguration = Default::default(); + let mut call = self.hub.achievement_configurations().insert(&request, &self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::AchievementConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::AchievementConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "achievement-type" => { + request.achievement_type = Some(value.unwrap_or("").to_string()); + }, + "steps-to-unlock" => { + request.steps_to_unlock = Some(arg_from_str(value.unwrap_or("-0"), err, "steps-to-unlock", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "initial-state" => { + request.initial_state = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.description.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.point-value" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "draft.point-value", "integer"); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.description.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.point-value" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "published.point-value", "integer"); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "id" => { + request_published_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievement_configurations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievement_configurations().list(&self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievement_configurations_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AchievementConfiguration = Default::default(); + let mut call = self.hub.achievement_configurations().patch(&request, &self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::AchievementConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::AchievementConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "achievement-type" => { + request.achievement_type = Some(value.unwrap_or("").to_string()); + }, + "steps-to-unlock" => { + request.steps_to_unlock = Some(arg_from_str(value.unwrap_or("-0"), err, "steps-to-unlock", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "initial-state" => { + request.initial_state = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.description.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.point-value" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "draft.point-value", "integer"); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.description.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.point-value" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "published.point-value", "integer"); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "id" => { + request_published_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievement_configurations_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AchievementConfiguration = Default::default(); + let mut call = self.hub.achievement_configurations().update(&request, &self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::AchievementConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::AchievementConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "achievement-type" => { + request.achievement_type = Some(value.unwrap_or("").to_string()); + }, + "steps-to-unlock" => { + request.steps_to_unlock = Some(arg_from_str(value.unwrap_or("-0"), err, "steps-to-unlock", "integer")); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "initial-state" => { + request.initial_state = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.description.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.point-value" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "draft.point-value", "integer"); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.description.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().description.kind = value.unwrap_or("").to_string(); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.point-value" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().point_value = arg_from_str(value.unwrap_or("-0"), err, "published.point-value", "integer"); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "id" => { + request_published_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _image_configurations_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.image_configurations().upload(&self.opt.arg_resource_id, &self.opt.arg_image_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboard_configurations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboard_configurations().delete(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _leaderboard_configurations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboard_configurations().get(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboard_configurations_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LeaderboardConfiguration = Default::default(); + let mut call = self.hub.leaderboard_configurations().insert(&request, &self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::LeaderboardConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::LeaderboardConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "score-order" => { + request.score_order = Some(value.unwrap_or("").to_string()); + }, + "score-min" => { + request.score_min = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "score-max" => { + request.score_max = Some(value.unwrap_or("").to_string()); + }, + "published.score-format.currency-code" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.many.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.two.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.one.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.few.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.zero.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.other.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.number-format-type" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "published.score-format.num-decimal-places" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "published.score-format.num-decimal-places", "integer"); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "draft.score-format.currency-code" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.many.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.two.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.one.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.few.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.zero.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.other.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.number-format-type" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "draft.score-format.num-decimal-places" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "draft.score-format.num-decimal-places", "integer"); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "id" => { + request_draft_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboard_configurations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.leaderboard_configurations().list(&self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboard_configurations_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LeaderboardConfiguration = Default::default(); + let mut call = self.hub.leaderboard_configurations().patch(&request, &self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::LeaderboardConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::LeaderboardConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "score-order" => { + request.score_order = Some(value.unwrap_or("").to_string()); + }, + "score-min" => { + request.score_min = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "score-max" => { + request.score_max = Some(value.unwrap_or("").to_string()); + }, + "published.score-format.currency-code" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.many.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.two.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.one.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.few.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.zero.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.other.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.number-format-type" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "published.score-format.num-decimal-places" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "published.score-format.num-decimal-places", "integer"); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "draft.score-format.currency-code" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.many.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.two.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.one.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.few.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.zero.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.other.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.number-format-type" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "draft.score-format.num-decimal-places" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "draft.score-format.num-decimal-places", "integer"); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "id" => { + request_draft_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _leaderboard_configurations_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LeaderboardConfiguration = Default::default(); + let mut call = self.hub.leaderboard_configurations().update(&request, &self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_draft_init(request: &mut api::LeaderboardConfiguration) { + if request.draft.is_none() { + request.draft = Some(Default::default()); + } + } + + fn request_published_init(request: &mut api::LeaderboardConfiguration) { + if request.published.is_none() { + request.published = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "score-order" => { + request.score_order = Some(value.unwrap_or("").to_string()); + }, + "score-min" => { + request.score_min = Some(value.unwrap_or("").to_string()); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "score-max" => { + request.score_max = Some(value.unwrap_or("").to_string()); + }, + "published.score-format.currency-code" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.many.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.two.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.one.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.few.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.zero.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.suffix.other.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "published.score-format.number-format-type" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "published.score-format.num-decimal-places" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "published.score-format.num-decimal-places", "integer"); + }, + "published.icon-url" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "published.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "published.name.kind" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "published.sort-rank" => { + request_published_init(&mut request); + request.published.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "published.sort-rank", "integer"); + }, + "draft.score-format.currency-code" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.currency_code = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.many.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.many.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.two.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.two.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.one.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.one.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.few.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.few.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.zero.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.zero.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.suffix.other.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.suffix.other.kind = value.unwrap_or("").to_string(); + }, + "draft.score-format.number-format-type" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.number_format_type = value.unwrap_or("").to_string(); + }, + "draft.score-format.num-decimal-places" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().score_format.num_decimal_places = arg_from_str(value.unwrap_or("-0"), err, "draft.score-format.num-decimal-places", "integer"); + }, + "draft.icon-url" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().icon_url = value.unwrap_or("").to_string(); + }, + "draft.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "draft.name.kind" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().name.kind = value.unwrap_or("").to_string(); + }, + "draft.sort-rank" => { + request_draft_init(&mut request); + request.draft.as_mut().unwrap().sort_rank = arg_from_str(value.unwrap_or("-0"), err, "draft.sort-rank", "integer"); + }, + "id" => { + request_draft_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_achievement_configurations { + if self.opt.cmd_delete { + call_result = self._achievement_configurations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._achievement_configurations_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._achievement_configurations_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._achievement_configurations_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._achievement_configurations_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._achievement_configurations_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_image_configurations { + if self.opt.cmd_upload { + call_result = self._image_configurations_upload(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_leaderboard_configurations { + if self.opt.cmd_delete { + call_result = self._leaderboard_configurations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._leaderboard_configurations_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._leaderboard_configurations_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._leaderboard_configurations_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._leaderboard_configurations_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._leaderboard_configurations_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "gamesconfiguration1-configuration-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "gamesconfiguration1-configuration", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::GamesConfiguration::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/gamesmanagement1_management-cli/Cargo.toml b/gen/gamesmanagement1_management-cli/Cargo.toml new file mode 100644 index 00000000000..df870fcfa67 --- /dev/null +++ b/gen/gamesmanagement1_management-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-gamesmanagement1_management-cli" +version = "0.0.1+20150325" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Games Management (protocol v1management)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/gamesmanagement1_management-cli" +homepage = "https://developers.google.com/games/services" +documentation = "http://byron.github.io/google-apis-rs/google_gamesmanagement1_management_cli" +license = "MIT" +keywords = ["gamesManagement", "google", "cli"] + +[[bin]] +name = "gamesmanagement1-management" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-gamesmanagement1_management] +path = "../gamesmanagement1_management" diff --git a/gen/gamesmanagement1_management-cli/LICENSE.md b/gen/gamesmanagement1_management-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/gamesmanagement1_management-cli/LICENSE.md @@ -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. diff --git a/gen/gamesmanagement1_management-cli/README.md b/gen/gamesmanagement1_management-cli/README.md new file mode 100644 index 00000000000..264ad8be944 --- /dev/null +++ b/gen/gamesmanagement1_management-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GAMESMANAGEMENT:V1MANAGEMENT + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/gamesmanagement1_management-cli/mkdocs.yml b/gen/gamesmanagement1_management-cli/mkdocs.yml new file mode 100644 index 00000000000..8110d34f676 --- /dev/null +++ b/gen/gamesmanagement1_management-cli/mkdocs.yml @@ -0,0 +1,43 @@ +site_name: Games Management v0.0.1+20150325 +site_url: http://byron.github.io/google-apis-rs/google-gamesmanagement1_management-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/gamesmanagement1_management-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['achievements_reset.md', 'Achievements', 'Reset'] +- ['achievements_reset-all.md', 'Achievements', 'Reset All'] +- ['achievements_reset-all-for-all-players.md', 'Achievements', 'Reset All For All Players'] +- ['achievements_reset-for-all-players.md', 'Achievements', 'Reset For All Players'] +- ['achievements_reset-multiple-for-all-players.md', 'Achievements', 'Reset Multiple For All Players'] +- ['applications_list-hidden.md', 'Applications', 'List Hidden'] +- ['events_reset.md', 'Events', 'Reset'] +- ['events_reset-all.md', 'Events', 'Reset All'] +- ['events_reset-all-for-all-players.md', 'Events', 'Reset All For All Players'] +- ['events_reset-for-all-players.md', 'Events', 'Reset For All Players'] +- ['events_reset-multiple-for-all-players.md', 'Events', 'Reset Multiple For All Players'] +- ['players_hide.md', 'Players', 'Hide'] +- ['players_unhide.md', 'Players', 'Unhide'] +- ['quests_reset.md', 'Quests', 'Reset'] +- ['quests_reset-all.md', 'Quests', 'Reset All'] +- ['quests_reset-all-for-all-players.md', 'Quests', 'Reset All For All Players'] +- ['quests_reset-for-all-players.md', 'Quests', 'Reset For All Players'] +- ['quests_reset-multiple-for-all-players.md', 'Quests', 'Reset Multiple For All Players'] +- ['rooms_reset.md', 'Rooms', 'Reset'] +- ['rooms_reset-for-all-players.md', 'Rooms', 'Reset For All Players'] +- ['scores_reset.md', 'Scores', 'Reset'] +- ['scores_reset-all.md', 'Scores', 'Reset All'] +- ['scores_reset-all-for-all-players.md', 'Scores', 'Reset All For All Players'] +- ['scores_reset-for-all-players.md', 'Scores', 'Reset For All Players'] +- ['scores_reset-multiple-for-all-players.md', 'Scores', 'Reset Multiple For All Players'] +- ['turn-based-matches_reset.md', 'Turn Based Matches', 'Reset'] +- ['turn-based-matches_reset-for-all-players.md', 'Turn Based Matches', 'Reset For All Players'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/gamesmanagement1_management-cli/src/cmn.rs b/gen/gamesmanagement1_management-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/gamesmanagement1_management-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/gamesmanagement1_management-cli/src/main.rs b/gen/gamesmanagement1_management-cli/src/main.rs new file mode 100644 index 00000000000..2d0da1400fe --- /dev/null +++ b/gen/gamesmanagement1_management-cli/src/main.rs @@ -0,0 +1,1473 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_gamesmanagement1_management as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + gamesmanagement1-management [options] achievements reset <achievement-id> [-p <v>]... [-o <out>] + gamesmanagement1-management [options] achievements reset-all [-p <v>]... [-o <out>] + gamesmanagement1-management [options] achievements reset-all-for-all-players [-p <v>]... + gamesmanagement1-management [options] achievements reset-for-all-players <achievement-id> [-p <v>]... + gamesmanagement1-management [options] achievements reset-multiple-for-all-players -r <kv>... [-p <v>]... + gamesmanagement1-management [options] applications list-hidden <application-id> [-p <v>]... [-o <out>] + gamesmanagement1-management [options] events reset <event-id> [-p <v>]... + gamesmanagement1-management [options] events reset-all [-p <v>]... + gamesmanagement1-management [options] events reset-all-for-all-players [-p <v>]... + gamesmanagement1-management [options] events reset-for-all-players <event-id> [-p <v>]... + gamesmanagement1-management [options] events reset-multiple-for-all-players -r <kv>... [-p <v>]... + gamesmanagement1-management [options] players hide <application-id> <player-id> [-p <v>]... + gamesmanagement1-management [options] players unhide <application-id> <player-id> [-p <v>]... + gamesmanagement1-management [options] quests reset <quest-id> [-p <v>]... + gamesmanagement1-management [options] quests reset-all [-p <v>]... + gamesmanagement1-management [options] quests reset-all-for-all-players [-p <v>]... + gamesmanagement1-management [options] quests reset-for-all-players <quest-id> [-p <v>]... + gamesmanagement1-management [options] quests reset-multiple-for-all-players -r <kv>... [-p <v>]... + gamesmanagement1-management [options] rooms reset [-p <v>]... + gamesmanagement1-management [options] rooms reset-for-all-players [-p <v>]... + gamesmanagement1-management [options] scores reset <leaderboard-id> [-p <v>]... [-o <out>] + gamesmanagement1-management [options] scores reset-all [-p <v>]... [-o <out>] + gamesmanagement1-management [options] scores reset-all-for-all-players [-p <v>]... + gamesmanagement1-management [options] scores reset-for-all-players <leaderboard-id> [-p <v>]... + gamesmanagement1-management [options] scores reset-multiple-for-all-players -r <kv>... [-p <v>]... + gamesmanagement1-management [options] turn-based-matches reset [-p <v>]... + gamesmanagement1-management [options] turn-based-matches reset-for-all-players [-p <v>]... + gamesmanagement1-management --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::GamesManagement<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _achievements_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reset(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_reset_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reset_all(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _achievements_reset_all_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reset_all_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _achievements_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.achievements().reset_for_all_players(&self.opt.arg_achievement_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _achievements_reset_multiple_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AchievementResetMultipleForAllRequest = Default::default(); + let mut call = self.hub.achievements().reset_multiple_for_all_players(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "achievement-ids" => { + if request.achievement_ids.is_none() { + request.achievement_ids = Some(Default::default()); + } + request.achievement_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _applications_list_hidden(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.applications().list_hidden(&self.opt.arg_application_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().reset(&self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_reset_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().reset_all(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_reset_all_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().reset_all_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().reset_for_all_players(&self.opt.arg_event_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _events_reset_multiple_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::EventsResetMultipleForAllRequest = Default::default(); + let mut call = self.hub.events().reset_multiple_for_all_players(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "event-ids" => { + if request.event_ids.is_none() { + request.event_ids = Some(Default::default()); + } + request.event_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _players_hide(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().hide(&self.opt.arg_application_id, &self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _players_unhide(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.players().unhide(&self.opt.arg_application_id, &self.opt.arg_player_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().reset(&self.opt.arg_quest_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_reset_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().reset_all(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_reset_all_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().reset_all_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.quests().reset_for_all_players(&self.opt.arg_quest_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _quests_reset_multiple_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::QuestsResetMultipleForAllRequest = Default::default(); + let mut call = self.hub.quests().reset_multiple_for_all_players(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "quest-ids" => { + if request.quest_ids.is_none() { + request.quest_ids = Some(Default::default()); + } + request.quest_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rooms_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().reset(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rooms_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rooms().reset_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _scores_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().reset(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_reset_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().reset_all(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _scores_reset_all_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().reset_all_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _scores_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.scores().reset_for_all_players(&self.opt.arg_leaderboard_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _scores_reset_multiple_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ScoresResetMultipleForAllRequest = Default::default(); + let mut call = self.hub.scores().reset_multiple_for_all_players(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "leaderboard-ids" => { + if request.leaderboard_ids.is_none() { + request.leaderboard_ids = Some(Default::default()); + } + request.leaderboard_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _turn_based_matches_reset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().reset(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _turn_based_matches_reset_for_all_players(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.turn_based_matches().reset_for_all_players(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_achievements { + if self.opt.cmd_reset { + call_result = self._achievements_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_all { + call_result = self._achievements_reset_all(dry_run, &mut err); + } else if self.opt.cmd_reset_all_for_all_players { + call_result = self._achievements_reset_all_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._achievements_reset_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_multiple_for_all_players { + call_result = self._achievements_reset_multiple_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_applications { + if self.opt.cmd_list_hidden { + call_result = self._applications_list_hidden(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_events { + if self.opt.cmd_reset { + call_result = self._events_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_all { + call_result = self._events_reset_all(dry_run, &mut err); + } else if self.opt.cmd_reset_all_for_all_players { + call_result = self._events_reset_all_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._events_reset_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_multiple_for_all_players { + call_result = self._events_reset_multiple_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_players { + if self.opt.cmd_hide { + call_result = self._players_hide(dry_run, &mut err); + } else if self.opt.cmd_unhide { + call_result = self._players_unhide(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_quests { + if self.opt.cmd_reset { + call_result = self._quests_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_all { + call_result = self._quests_reset_all(dry_run, &mut err); + } else if self.opt.cmd_reset_all_for_all_players { + call_result = self._quests_reset_all_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._quests_reset_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_multiple_for_all_players { + call_result = self._quests_reset_multiple_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_rooms { + if self.opt.cmd_reset { + call_result = self._rooms_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._rooms_reset_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_scores { + if self.opt.cmd_reset { + call_result = self._scores_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_all { + call_result = self._scores_reset_all(dry_run, &mut err); + } else if self.opt.cmd_reset_all_for_all_players { + call_result = self._scores_reset_all_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._scores_reset_for_all_players(dry_run, &mut err); + } else if self.opt.cmd_reset_multiple_for_all_players { + call_result = self._scores_reset_multiple_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_turn_based_matches { + if self.opt.cmd_reset { + call_result = self._turn_based_matches_reset(dry_run, &mut err); + } else if self.opt.cmd_reset_for_all_players { + call_result = self._turn_based_matches_reset_for_all_players(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "gamesmanagement1-management-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "gamesmanagement1-management", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::GamesManagement::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/gan1_beta1-cli/Cargo.toml b/gen/gan1_beta1-cli/Cargo.toml new file mode 100644 index 00000000000..cc76737f2d9 --- /dev/null +++ b/gen/gan1_beta1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-gan1_beta1-cli" +version = "0.0.1+20130205" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with gan (protocol v1beta1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/gan1_beta1-cli" +homepage = "https://developers.google.com/affiliate-network/" +documentation = "http://byron.github.io/google-apis-rs/google_gan1_beta1_cli" +license = "MIT" +keywords = ["gan", "google", "cli"] + +[[bin]] +name = "gan1-beta1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-gan1_beta1] +path = "../gan1_beta1" diff --git a/gen/gan1_beta1-cli/LICENSE.md b/gen/gan1_beta1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/gan1_beta1-cli/LICENSE.md @@ -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. diff --git a/gen/gan1_beta1-cli/README.md b/gen/gan1_beta1-cli/README.md new file mode 100644 index 00000000000..b647b465b40 --- /dev/null +++ b/gen/gan1_beta1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GAN:V1BETA1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/gan1_beta1-cli/mkdocs.yml b/gen/gan1_beta1-cli/mkdocs.yml new file mode 100644 index 00000000000..9849d35f0fa --- /dev/null +++ b/gen/gan1_beta1-cli/mkdocs.yml @@ -0,0 +1,26 @@ +site_name: gan v0.0.1+20130205 +site_url: http://byron.github.io/google-apis-rs/google-gan1_beta1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/gan1_beta1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['advertisers_get.md', 'Advertisers', 'Get'] +- ['advertisers_list.md', 'Advertisers', 'List'] +- ['cc-offers_list.md', 'Cc Offers', 'List'] +- ['events_list.md', 'Events', 'List'] +- ['links_get.md', 'Links', 'Get'] +- ['links_insert.md', 'Links', 'Insert'] +- ['links_list.md', 'Links', 'List'] +- ['publishers_get.md', 'Publishers', 'Get'] +- ['publishers_list.md', 'Publishers', 'List'] +- ['reports_get.md', 'Reports', 'Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/gan1_beta1-cli/src/cmn.rs b/gen/gan1_beta1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/gan1_beta1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/gan1_beta1-cli/src/main.rs b/gen/gan1_beta1-cli/src/main.rs new file mode 100644 index 00000000000..21b0ba6bb92 --- /dev/null +++ b/gen/gan1_beta1-cli/src/main.rs @@ -0,0 +1,947 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_gan1_beta1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + gan1-beta1 [options] advertisers get <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] advertisers list <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] cc-offers list <publisher> [-p <v>]... [-o <out>] + gan1-beta1 [options] events list <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] links get <role> <role-id> <link-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] links insert <role> <role-id> -r <kv>... [-p <v>]... [-o <out>] + gan1-beta1 [options] links list <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] publishers get <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] publishers list <role> <role-id> [-p <v>]... [-o <out>] + gan1-beta1 [options] reports get <role> <role-id> <report-type> [-p <v>]... [-o <out>] + gan1-beta1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Gan<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _advertisers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertisers().get(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _advertisers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.advertisers().list(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "relationship-status" => { + call = call.relationship_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-seven-day-epc" => { + call = call.min_seven_day_epc(arg_from_str(value.unwrap_or("0.0"), err, "min-seven-day-epc", "number")); + }, + "min-payout-rank" => { + call = call.min_payout_rank(arg_from_str(value.unwrap_or("-0"), err, "min-payout-rank", "integer")); + }, + "min-ninety-day-epc" => { + call = call.min_ninety_day_epc(arg_from_str(value.unwrap_or("0.0"), err, "min-ninety-day-epc", "number")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "advertiser-category" => { + call = call.advertiser_category(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _cc_offers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.cc_offers().list(&self.opt.arg_publisher); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "advertiser" => { + call = call.add_advertiser(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _events_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.events().list(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "status" => { + call = call.status(value.unwrap_or("")); + }, + "sku" => { + call = call.sku(value.unwrap_or("")); + }, + "publisher-id" => { + call = call.publisher_id(value.unwrap_or("")); + }, + "product-category" => { + call = call.product_category(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-id" => { + call = call.order_id(value.unwrap_or("")); + }, + "modify-date-min" => { + call = call.modify_date_min(value.unwrap_or("")); + }, + "modify-date-max" => { + call = call.modify_date_max(value.unwrap_or("")); + }, + "member-id" => { + call = call.member_id(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "link-id" => { + call = call.link_id(value.unwrap_or("")); + }, + "event-date-min" => { + call = call.event_date_min(value.unwrap_or("")); + }, + "event-date-max" => { + call = call.event_date_max(value.unwrap_or("")); + }, + "charge-type" => { + call = call.charge_type(value.unwrap_or("")); + }, + "advertiser-id" => { + call = call.advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _links_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.links().get(&self.opt.arg_role, &self.opt.arg_role_id, &self.opt.arg_link_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _links_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Link = Default::default(); + let mut call = self.hub.links().insert(&request, &self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_epc_ninety_day_average_init(request: &mut api::Link) { + if request.epc_ninety_day_average.is_none() { + request.epc_ninety_day_average = Some(Default::default()); + } + } + + fn request_epc_seven_day_average_init(request: &mut api::Link) { + if request.epc_seven_day_average.is_none() { + request.epc_seven_day_average = Some(Default::default()); + } + } + + fn request_special_offers_init(request: &mut api::Link) { + if request.special_offers.is_none() { + request.special_offers = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "link-type" => { + request.link_type = Some(value.unwrap_or("").to_string()); + }, + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "end-date" => { + request.end_date = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "special-offers.price-cut.amount" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().price_cut.amount = arg_from_str(value.unwrap_or("0.0"), err, "special-offers.price-cut.amount", "number"); + }, + "special-offers.price-cut.currency-code" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().price_cut.currency_code = value.unwrap_or("").to_string(); + }, + "special-offers.price-cut-min.amount" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().price_cut_min.amount = arg_from_str(value.unwrap_or("0.0"), err, "special-offers.price-cut-min.amount", "number"); + }, + "special-offers.price-cut-min.currency-code" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().price_cut_min.currency_code = value.unwrap_or("").to_string(); + }, + "special-offers.free-shipping" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().free_shipping = arg_from_str(value.unwrap_or("false"), err, "special-offers.free-shipping", "boolean"); + }, + "special-offers.promotion-codes" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().promotion_codes.push(value.unwrap_or("").to_string()); + }, + "special-offers.percent-off" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().percent_off = arg_from_str(value.unwrap_or("0.0"), err, "special-offers.percent-off", "number"); + }, + "special-offers.percent-off-min.amount" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().percent_off_min.amount = arg_from_str(value.unwrap_or("0.0"), err, "special-offers.percent-off-min.amount", "number"); + }, + "special-offers.percent-off-min.currency-code" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().percent_off_min.currency_code = value.unwrap_or("").to_string(); + }, + "special-offers.free-gift" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().free_gift = arg_from_str(value.unwrap_or("false"), err, "special-offers.free-gift", "boolean"); + }, + "special-offers.free-shipping-min.amount" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().free_shipping_min.amount = arg_from_str(value.unwrap_or("0.0"), err, "special-offers.free-shipping-min.amount", "number"); + }, + "special-offers.free-shipping-min.currency-code" => { + request_special_offers_init(&mut request); + request.special_offers.as_mut().unwrap().free_shipping_min.currency_code = value.unwrap_or("").to_string(); + }, + "epc-seven-day-average.amount" => { + request_epc_seven_day_average_init(&mut request); + request.epc_seven_day_average.as_mut().unwrap().amount = arg_from_str(value.unwrap_or("0.0"), err, "epc-seven-day-average.amount", "number"); + }, + "epc-seven-day-average.currency-code" => { + request_epc_seven_day_average_init(&mut request); + request.epc_seven_day_average.as_mut().unwrap().currency_code = value.unwrap_or("").to_string(); + }, + "create-date" => { + request_epc_seven_day_average_init(&mut request); + request.create_date = Some(value.unwrap_or("").to_string()); + }, + "image-alt-text" => { + request_epc_seven_day_average_init(&mut request); + request.image_alt_text = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_epc_seven_day_average_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "advertiser-id" => { + request_epc_seven_day_average_init(&mut request); + request.advertiser_id = Some(value.unwrap_or("").to_string()); + }, + "is-active" => { + request_epc_seven_day_average_init(&mut request); + request.is_active = Some(arg_from_str(value.unwrap_or("false"), err, "is-active", "boolean")); + }, + "promotion-type" => { + request_epc_seven_day_average_init(&mut request); + request.promotion_type = Some(value.unwrap_or("").to_string()); + }, + "duration" => { + request_epc_seven_day_average_init(&mut request); + request.duration = Some(value.unwrap_or("").to_string()); + }, + "authorship" => { + request_epc_seven_day_average_init(&mut request); + request.authorship = Some(value.unwrap_or("").to_string()); + }, + "impression-tracking-url" => { + request_epc_seven_day_average_init(&mut request); + request.impression_tracking_url = Some(value.unwrap_or("").to_string()); + }, + "epc-ninety-day-average.amount" => { + request_epc_ninety_day_average_init(&mut request); + request.epc_ninety_day_average.as_mut().unwrap().amount = arg_from_str(value.unwrap_or("0.0"), err, "epc-ninety-day-average.amount", "number"); + }, + "epc-ninety-day-average.currency-code" => { + request_epc_ninety_day_average_init(&mut request); + request.epc_ninety_day_average.as_mut().unwrap().currency_code = value.unwrap_or("").to_string(); + }, + "availability" => { + request_epc_ninety_day_average_init(&mut request); + request.availability = Some(value.unwrap_or("").to_string()); + }, + "click-tracking-url" => { + request_epc_ninety_day_average_init(&mut request); + request.click_tracking_url = Some(value.unwrap_or("").to_string()); + }, + "destination-url" => { + request_epc_ninety_day_average_init(&mut request); + request.destination_url = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _links_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.links().list(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-date-min" => { + call = call.start_date_min(value.unwrap_or("")); + }, + "start-date-max" => { + call = call.start_date_max(value.unwrap_or("")); + }, + "search-text" => { + call = call.search_text(value.unwrap_or("")); + }, + "relationship-status" => { + call = call.relationship_status(value.unwrap_or("")); + }, + "promotion-type" => { + call = call.add_promotion_type(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "link-type" => { + call = call.link_type(value.unwrap_or("")); + }, + "create-date-min" => { + call = call.create_date_min(value.unwrap_or("")); + }, + "create-date-max" => { + call = call.create_date_max(value.unwrap_or("")); + }, + "authorship" => { + call = call.authorship(value.unwrap_or("")); + }, + "asset-size" => { + call = call.add_asset_size(value.unwrap_or("")); + }, + "advertiser-id" => { + call = call.add_advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _publishers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.publishers().get(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "publisher-id" => { + call = call.publisher_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _publishers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.publishers().list(&self.opt.arg_role, &self.opt.arg_role_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "relationship-status" => { + call = call.relationship_status(value.unwrap_or("")); + }, + "publisher-category" => { + call = call.publisher_category(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "min-seven-day-epc" => { + call = call.min_seven_day_epc(arg_from_str(value.unwrap_or("0.0"), err, "min-seven-day-epc", "number")); + }, + "min-payout-rank" => { + call = call.min_payout_rank(arg_from_str(value.unwrap_or("-0"), err, "min-payout-rank", "integer")); + }, + "min-ninety-day-epc" => { + call = call.min_ninety_day_epc(arg_from_str(value.unwrap_or("0.0"), err, "min-ninety-day-epc", "number")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().get(&self.opt.arg_role, &self.opt.arg_role_id, &self.opt.arg_report_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "status" => { + call = call.status(value.unwrap_or("")); + }, + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "start-date" => { + call = call.start_date(value.unwrap_or("")); + }, + "publisher-id" => { + call = call.add_publisher_id(value.unwrap_or("")); + }, + "order-id" => { + call = call.add_order_id(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "link-id" => { + call = call.add_link_id(value.unwrap_or("")); + }, + "event-type" => { + call = call.event_type(value.unwrap_or("")); + }, + "end-date" => { + call = call.end_date(value.unwrap_or("")); + }, + "calculate-totals" => { + call = call.calculate_totals(arg_from_str(value.unwrap_or("false"), err, "calculate-totals", "boolean")); + }, + "advertiser-id" => { + call = call.add_advertiser_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_advertisers { + if self.opt.cmd_get { + call_result = self._advertisers_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._advertisers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_cc_offers { + if self.opt.cmd_list { + call_result = self._cc_offers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_events { + if self.opt.cmd_list { + call_result = self._events_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_links { + if self.opt.cmd_get { + call_result = self._links_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._links_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._links_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_publishers { + if self.opt.cmd_get { + call_result = self._publishers_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._publishers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_get { + call_result = self._reports_get(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "gan1-beta1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "gan1-beta1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Gan::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/genomics1_beta2-cli/Cargo.toml b/gen/genomics1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..0ed61f4278e --- /dev/null +++ b/gen/genomics1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-genomics1_beta2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with genomics (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/genomics1_beta2-cli" +homepage = "https://developers.google.com/genomics/v1beta2/reference" +documentation = "http://byron.github.io/google-apis-rs/google_genomics1_beta2_cli" +license = "MIT" +keywords = ["genomics", "google", "cli"] + +[[bin]] +name = "genomics1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-genomics1_beta2] +path = "../genomics1_beta2" diff --git a/gen/genomics1_beta2-cli/LICENSE.md b/gen/genomics1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/genomics1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/genomics1_beta2-cli/README.md b/gen/genomics1_beta2-cli/README.md new file mode 100644 index 00000000000..678804b0a21 --- /dev/null +++ b/gen/genomics1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GENOMICS:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/genomics1_beta2-cli/mkdocs.yml b/gen/genomics1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..8dc274dc098 --- /dev/null +++ b/gen/genomics1_beta2-cli/mkdocs.yml @@ -0,0 +1,76 @@ +site_name: genomics v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-genomics1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/genomics1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['annotation-sets_create.md', 'Annotation Sets', 'Create'] +- ['annotation-sets_delete.md', 'Annotation Sets', 'Delete'] +- ['annotation-sets_get.md', 'Annotation Sets', 'Get'] +- ['annotation-sets_patch.md', 'Annotation Sets', 'Patch'] +- ['annotation-sets_search.md', 'Annotation Sets', 'Search'] +- ['annotation-sets_update.md', 'Annotation Sets', 'Update'] +- ['annotations_batch-create.md', 'Annotations', 'Batch Create'] +- ['annotations_create.md', 'Annotations', 'Create'] +- ['annotations_delete.md', 'Annotations', 'Delete'] +- ['annotations_get.md', 'Annotations', 'Get'] +- ['annotations_patch.md', 'Annotations', 'Patch'] +- ['annotations_search.md', 'Annotations', 'Search'] +- ['annotations_update.md', 'Annotations', 'Update'] +- ['callsets_create.md', 'Callsets', 'Create'] +- ['callsets_delete.md', 'Callsets', 'Delete'] +- ['callsets_get.md', 'Callsets', 'Get'] +- ['callsets_patch.md', 'Callsets', 'Patch'] +- ['callsets_search.md', 'Callsets', 'Search'] +- ['callsets_update.md', 'Callsets', 'Update'] +- ['datasets_create.md', 'Datasets', 'Create'] +- ['datasets_delete.md', 'Datasets', 'Delete'] +- ['datasets_get.md', 'Datasets', 'Get'] +- ['datasets_list.md', 'Datasets', 'List'] +- ['datasets_patch.md', 'Datasets', 'Patch'] +- ['datasets_undelete.md', 'Datasets', 'Undelete'] +- ['datasets_update.md', 'Datasets', 'Update'] +- ['experimental_jobs-create.md', 'Experimental', 'Jobs Create'] +- ['jobs_cancel.md', 'Jobs', 'Cancel'] +- ['jobs_get.md', 'Jobs', 'Get'] +- ['jobs_search.md', 'Jobs', 'Search'] +- ['readgroupsets_align.md', 'Readgroupsets', 'Align'] +- ['readgroupsets_call.md', 'Readgroupsets', 'Call'] +- ['readgroupsets_coveragebuckets-list.md', 'Readgroupsets', 'Coveragebuckets List'] +- ['readgroupsets_delete.md', 'Readgroupsets', 'Delete'] +- ['readgroupsets_export.md', 'Readgroupsets', 'Export'] +- ['readgroupsets_get.md', 'Readgroupsets', 'Get'] +- ['readgroupsets_import.md', 'Readgroupsets', 'Import'] +- ['readgroupsets_patch.md', 'Readgroupsets', 'Patch'] +- ['readgroupsets_search.md', 'Readgroupsets', 'Search'] +- ['readgroupsets_update.md', 'Readgroupsets', 'Update'] +- ['reads_search.md', 'Reads', 'Search'] +- ['references_bases-list.md', 'References', 'Bases List'] +- ['references_get.md', 'References', 'Get'] +- ['references_search.md', 'References', 'Search'] +- ['referencesets_get.md', 'Referencesets', 'Get'] +- ['referencesets_search.md', 'Referencesets', 'Search'] +- ['streaming-variant-store_streamvariants.md', 'Streaming Variant Store', 'Streamvariants'] +- ['variants_create.md', 'Variants', 'Create'] +- ['variants_delete.md', 'Variants', 'Delete'] +- ['variants_get.md', 'Variants', 'Get'] +- ['variants_search.md', 'Variants', 'Search'] +- ['variants_update.md', 'Variants', 'Update'] +- ['variantsets_delete.md', 'Variantsets', 'Delete'] +- ['variantsets_export.md', 'Variantsets', 'Export'] +- ['variantsets_get.md', 'Variantsets', 'Get'] +- ['variantsets_import-variants.md', 'Variantsets', 'Import Variants'] +- ['variantsets_merge-variants.md', 'Variantsets', 'Merge Variants'] +- ['variantsets_patch.md', 'Variantsets', 'Patch'] +- ['variantsets_search.md', 'Variantsets', 'Search'] +- ['variantsets_update.md', 'Variantsets', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/genomics1_beta2-cli/src/cmn.rs b/gen/genomics1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/genomics1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/genomics1_beta2-cli/src/main.rs b/gen/genomics1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..cad52393039 --- /dev/null +++ b/gen/genomics1_beta2-cli/src/main.rs @@ -0,0 +1,4467 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_genomics1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + genomics1-beta2 [options] annotation-sets create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotation-sets delete <annotation-set-id> [-p <v>]... + genomics1-beta2 [options] annotation-sets get <annotation-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotation-sets patch <annotation-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotation-sets search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotation-sets update <annotation-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations batch-create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations delete <annotation-id> [-p <v>]... + genomics1-beta2 [options] annotations get <annotation-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations patch <annotation-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] annotations update <annotation-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] callsets create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] callsets delete <call-set-id> [-p <v>]... + genomics1-beta2 [options] callsets get <call-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] callsets patch <call-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] callsets search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] callsets update <call-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets delete <dataset-id> [-p <v>]... + genomics1-beta2 [options] datasets get <dataset-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets list [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets patch <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets undelete <dataset-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] datasets update <dataset-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] experimental jobs-create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] jobs cancel <job-id> [-p <v>]... + genomics1-beta2 [options] jobs get <job-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] jobs search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets align -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets call -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets coveragebuckets-list <read-group-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets delete <read-group-set-id> [-p <v>]... + genomics1-beta2 [options] readgroupsets export -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets get <read-group-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets import -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets patch <read-group-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] readgroupsets update <read-group-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] reads search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] references bases-list <reference-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] references get <reference-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] references search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] referencesets get <reference-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] referencesets search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] streaming-variant-store streamvariants -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variants create -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variants delete <variant-id> [-p <v>]... + genomics1-beta2 [options] variants get <variant-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] variants search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variants update <variant-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets delete <variant-set-id> [-p <v>]... + genomics1-beta2 [options] variantsets export <variant-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets get <variant-set-id> [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets import-variants <variant-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets merge-variants <variant-set-id> -r <kv>... [-p <v>]... + genomics1-beta2 [options] variantsets patch <variant-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets search -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 [options] variantsets update <variant-set-id> -r <kv>... [-p <v>]... [-o <out>] + genomics1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Genomics<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _annotation_sets_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AnnotationSet = Default::default(); + let mut call = self.hub.annotation_sets().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "source-uri" => { + request.source_uri = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotation_sets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.annotation_sets().delete(&self.opt.arg_annotation_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _annotation_sets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.annotation_sets().get(&self.opt.arg_annotation_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotation_sets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AnnotationSet = Default::default(); + let mut call = self.hub.annotation_sets().patch(&request, &self.opt.arg_annotation_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "source-uri" => { + request.source_uri = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotation_sets_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchAnnotationSetsRequest = Default::default(); + let mut call = self.hub.annotation_sets().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "dataset-ids" => { + if request.dataset_ids.is_none() { + request.dataset_ids = Some(Default::default()); + } + request.dataset_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "types" => { + if request.types.is_none() { + request.types = Some(Default::default()); + } + request.types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotation_sets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AnnotationSet = Default::default(); + let mut call = self.hub.annotation_sets().update(&request, &self.opt.arg_annotation_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "source-uri" => { + request.source_uri = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_batch_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::BatchCreateAnnotationsRequest = Default::default(); + let mut call = self.hub.annotations().batch_create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Annotation = Default::default(); + let mut call = self.hub.annotations().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_position_init(request: &mut api::Annotation) { + if request.position.is_none() { + request.position = Some(Default::default()); + } + } + + fn request_transcript_init(request: &mut api::Annotation) { + if request.transcript.is_none() { + request.transcript = Some(Default::default()); + } + } + + fn request_variant_init(request: &mut api::Annotation) { + if request.variant.is_none() { + request.variant = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "transcript.coding-sequence.start" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.start = value.unwrap_or("").to_string(); + }, + "transcript.coding-sequence.end" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.end = value.unwrap_or("").to_string(); + }, + "transcript.gene-id" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "variant.effect" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().effect = value.unwrap_or("").to_string(); + }, + "variant.transcript-ids" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().transcript_ids.push(value.unwrap_or("").to_string()); + }, + "variant.alternate-bases" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().alternate_bases = value.unwrap_or("").to_string(); + }, + "variant.clinical-significance" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().clinical_significance = value.unwrap_or("").to_string(); + }, + "variant.type" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "variant.gene-id" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "annotation-set-id" => { + request_variant_init(&mut request); + request.annotation_set_id = Some(value.unwrap_or("").to_string()); + }, + "position.start" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "position.reference-id" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_id = value.unwrap_or("").to_string(); + }, + "position.end" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "position.reverse-strand" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reverse_strand = arg_from_str(value.unwrap_or("false"), err, "position.reverse-strand", "boolean"); + }, + "position.reference-name" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_name = value.unwrap_or("").to_string(); + }, + "type" => { + request_position_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_position_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.annotations().delete(&self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _annotations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.annotations().get(&self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Annotation = Default::default(); + let mut call = self.hub.annotations().patch(&request, &self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_position_init(request: &mut api::Annotation) { + if request.position.is_none() { + request.position = Some(Default::default()); + } + } + + fn request_transcript_init(request: &mut api::Annotation) { + if request.transcript.is_none() { + request.transcript = Some(Default::default()); + } + } + + fn request_variant_init(request: &mut api::Annotation) { + if request.variant.is_none() { + request.variant = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "transcript.coding-sequence.start" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.start = value.unwrap_or("").to_string(); + }, + "transcript.coding-sequence.end" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.end = value.unwrap_or("").to_string(); + }, + "transcript.gene-id" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "variant.effect" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().effect = value.unwrap_or("").to_string(); + }, + "variant.transcript-ids" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().transcript_ids.push(value.unwrap_or("").to_string()); + }, + "variant.alternate-bases" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().alternate_bases = value.unwrap_or("").to_string(); + }, + "variant.clinical-significance" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().clinical_significance = value.unwrap_or("").to_string(); + }, + "variant.type" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "variant.gene-id" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "annotation-set-id" => { + request_variant_init(&mut request); + request.annotation_set_id = Some(value.unwrap_or("").to_string()); + }, + "position.start" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "position.reference-id" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_id = value.unwrap_or("").to_string(); + }, + "position.end" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "position.reverse-strand" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reverse_strand = arg_from_str(value.unwrap_or("false"), err, "position.reverse-strand", "boolean"); + }, + "position.reference-name" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_name = value.unwrap_or("").to_string(); + }, + "type" => { + request_position_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_position_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchAnnotationsRequest = Default::default(); + let mut call = self.hub.annotations().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_range_init(request: &mut api::SearchAnnotationsRequest) { + if request.range.is_none() { + request.range = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "range.start" => { + request_range_init(&mut request); + request.range.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "range.reference-id" => { + request_range_init(&mut request); + request.range.as_mut().unwrap().reference_id = value.unwrap_or("").to_string(); + }, + "range.end" => { + request_range_init(&mut request); + request.range.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "range.reference-name" => { + request_range_init(&mut request); + request.range.as_mut().unwrap().reference_name = value.unwrap_or("").to_string(); + }, + "annotation-set-ids" => { + request_range_init(&mut request); + if request.annotation_set_ids.is_none() { + request.annotation_set_ids = Some(Default::default()); + } + request.annotation_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-size" => { + request_range_init(&mut request); + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _annotations_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Annotation = Default::default(); + let mut call = self.hub.annotations().update(&request, &self.opt.arg_annotation_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_position_init(request: &mut api::Annotation) { + if request.position.is_none() { + request.position = Some(Default::default()); + } + } + + fn request_transcript_init(request: &mut api::Annotation) { + if request.transcript.is_none() { + request.transcript = Some(Default::default()); + } + } + + fn request_variant_init(request: &mut api::Annotation) { + if request.variant.is_none() { + request.variant = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "transcript.coding-sequence.start" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.start = value.unwrap_or("").to_string(); + }, + "transcript.coding-sequence.end" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().coding_sequence.end = value.unwrap_or("").to_string(); + }, + "transcript.gene-id" => { + request_transcript_init(&mut request); + request.transcript.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "variant.effect" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().effect = value.unwrap_or("").to_string(); + }, + "variant.transcript-ids" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().transcript_ids.push(value.unwrap_or("").to_string()); + }, + "variant.alternate-bases" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().alternate_bases = value.unwrap_or("").to_string(); + }, + "variant.clinical-significance" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().clinical_significance = value.unwrap_or("").to_string(); + }, + "variant.type" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "variant.gene-id" => { + request_variant_init(&mut request); + request.variant.as_mut().unwrap().gene_id = value.unwrap_or("").to_string(); + }, + "annotation-set-id" => { + request_variant_init(&mut request); + request.annotation_set_id = Some(value.unwrap_or("").to_string()); + }, + "position.start" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "position.reference-id" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_id = value.unwrap_or("").to_string(); + }, + "position.end" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "position.reverse-strand" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reverse_strand = arg_from_str(value.unwrap_or("false"), err, "position.reverse-strand", "boolean"); + }, + "position.reference-name" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().reference_name = value.unwrap_or("").to_string(); + }, + "type" => { + request_position_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_position_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _callsets_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CallSet = Default::default(); + let mut call = self.hub.callsets().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "sample-id" => { + request.sample_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _callsets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.callsets().delete(&self.opt.arg_call_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _callsets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.callsets().get(&self.opt.arg_call_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _callsets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CallSet = Default::default(); + let mut call = self.hub.callsets().patch(&request, &self.opt.arg_call_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "sample-id" => { + request.sample_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _callsets_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchCallSetsRequest = Default::default(); + let mut call = self.hub.callsets().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _callsets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CallSet = Default::default(); + let mut call = self.hub.callsets().update(&request, &self.opt.arg_call_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "sample-id" => { + request.sample_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "is-public" => { + request.is_public = Some(arg_from_str(value.unwrap_or("false"), err, "is-public", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.datasets().delete(&self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _datasets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.datasets().get(&self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.datasets().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "project-number" => { + call = call.project_number(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().patch(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "is-public" => { + request.is_public = Some(arg_from_str(value.unwrap_or("false"), err, "is-public", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_undelete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.datasets().undelete(&self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _datasets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Dataset = Default::default(); + let mut call = self.hub.datasets().update(&request, &self.opt.arg_dataset_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "is-public" => { + request.is_public = Some(arg_from_str(value.unwrap_or("false"), err, "is-public", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _experimental_jobs_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ExperimentalCreateJobRequest = Default::default(); + let mut call = self.hub.experimental().jobs_create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "paired-source-uris" => { + if request.paired_source_uris.is_none() { + request.paired_source_uris = Some(Default::default()); + } + request.paired_source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "align" => { + request.align = Some(arg_from_str(value.unwrap_or("false"), err, "align", "boolean")); + }, + "call-variants" => { + request.call_variants = Some(arg_from_str(value.unwrap_or("false"), err, "call-variants", "boolean")); + }, + "source-uris" => { + if request.source_uris.is_none() { + request.source_uris = Some(Default::default()); + } + request.source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "gcs-output-path" => { + request.gcs_output_path = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_cancel(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().cancel(&self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _jobs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.jobs().get(&self.opt.arg_job_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _jobs_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchJobsRequest = Default::default(); + let mut call = self.hub.jobs().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + if request.status.is_none() { + request.status = Some(Default::default()); + } + request.status.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "created-after" => { + request.created_after = Some(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "created-before" => { + request.created_before = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_align(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AlignReadGroupSetsRequest = Default::default(); + let mut call = self.hub.readgroupsets().align(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_interleaved_fastq_source_init(request: &mut api::AlignReadGroupSetsRequest) { + if request.interleaved_fastq_source.is_none() { + request.interleaved_fastq_source = Some(Default::default()); + } + } + + fn request_paired_fastq_source_init(request: &mut api::AlignReadGroupSetsRequest) { + if request.paired_fastq_source.is_none() { + request.paired_fastq_source = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "interleaved-fastq-source.source-uris" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().source_uris.push(value.unwrap_or("").to_string()); + }, + "interleaved-fastq-source.metadata.read-group-name" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().metadata.read_group_name = value.unwrap_or("").to_string(); + }, + "interleaved-fastq-source.metadata.sample-name" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().metadata.sample_name = value.unwrap_or("").to_string(); + }, + "interleaved-fastq-source.metadata.library-name" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().metadata.library_name = value.unwrap_or("").to_string(); + }, + "interleaved-fastq-source.metadata.platform-name" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().metadata.platform_name = value.unwrap_or("").to_string(); + }, + "interleaved-fastq-source.metadata.platform-unit" => { + request_interleaved_fastq_source_init(&mut request); + request.interleaved_fastq_source.as_mut().unwrap().metadata.platform_unit = value.unwrap_or("").to_string(); + }, + "bam-source-uris" => { + request_interleaved_fastq_source_init(&mut request); + if request.bam_source_uris.is_none() { + request.bam_source_uris = Some(Default::default()); + } + request.bam_source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "paired-fastq-source.second-source-uris" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().second_source_uris.push(value.unwrap_or("").to_string()); + }, + "paired-fastq-source.metadata.read-group-name" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().metadata.read_group_name = value.unwrap_or("").to_string(); + }, + "paired-fastq-source.metadata.sample-name" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().metadata.sample_name = value.unwrap_or("").to_string(); + }, + "paired-fastq-source.metadata.library-name" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().metadata.library_name = value.unwrap_or("").to_string(); + }, + "paired-fastq-source.metadata.platform-name" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().metadata.platform_name = value.unwrap_or("").to_string(); + }, + "paired-fastq-source.metadata.platform-unit" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().metadata.platform_unit = value.unwrap_or("").to_string(); + }, + "paired-fastq-source.first-source-uris" => { + request_paired_fastq_source_init(&mut request); + request.paired_fastq_source.as_mut().unwrap().first_source_uris.push(value.unwrap_or("").to_string()); + }, + "read-group-set-id" => { + request_paired_fastq_source_init(&mut request); + request.read_group_set_id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request_paired_fastq_source_init(&mut request); + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_call(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CallReadGroupSetsRequest = Default::default(); + let mut call = self.hub.readgroupsets().call(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "source-uris" => { + if request.source_uris.is_none() { + request.source_uris = Some(Default::default()); + } + request.source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "read-group-set-id" => { + request.read_group_set_id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_coveragebuckets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.readgroupsets().coveragebuckets_list(&self.opt.arg_read_group_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "target-bucket-width" => { + call = call.target_bucket_width(value.unwrap_or("")); + }, + "range-start" => { + call = call.range_start(value.unwrap_or("")); + }, + "range-reference-name" => { + call = call.range_reference_name(value.unwrap_or("")); + }, + "range-end" => { + call = call.range_end(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.readgroupsets().delete(&self.opt.arg_read_group_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _readgroupsets_export(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ExportReadGroupSetsRequest = Default::default(); + let mut call = self.hub.readgroupsets().export(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "export-uri" => { + request.export_uri = Some(value.unwrap_or("").to_string()); + }, + "reference-names" => { + if request.reference_names.is_none() { + request.reference_names = Some(Default::default()); + } + request.reference_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "read-group-set-ids" => { + if request.read_group_set_ids.is_none() { + request.read_group_set_ids = Some(Default::default()); + } + request.read_group_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.readgroupsets().get(&self.opt.arg_read_group_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_import(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ImportReadGroupSetsRequest = Default::default(); + let mut call = self.hub.readgroupsets().import(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "source-uris" => { + if request.source_uris.is_none() { + request.source_uris = Some(Default::default()); + } + request.source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "partition-strategy" => { + request.partition_strategy = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ReadGroupSet = Default::default(); + let mut call = self.hub.readgroupsets().patch(&request, &self.opt.arg_read_group_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "filename" => { + request.filename = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchReadGroupSetsRequest = Default::default(); + let mut call = self.hub.readgroupsets().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "dataset-ids" => { + if request.dataset_ids.is_none() { + request.dataset_ids = Some(Default::default()); + } + request.dataset_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _readgroupsets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ReadGroupSet = Default::default(); + let mut call = self.hub.readgroupsets().update(&request, &self.opt.arg_read_group_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "filename" => { + request.filename = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reads_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchReadsRequest = Default::default(); + let mut call = self.hub.reads().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "read-group-set-ids" => { + if request.read_group_set_ids.is_none() { + request.read_group_set_ids = Some(Default::default()); + } + request.read_group_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "read-group-ids" => { + if request.read_group_ids.is_none() { + request.read_group_ids = Some(Default::default()); + } + request.read_group_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "start" => { + request.start = Some(value.unwrap_or("").to_string()); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "reference-name" => { + request.reference_name = Some(value.unwrap_or("").to_string()); + }, + "end" => { + request.end = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _references_bases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.references().bases_list(&self.opt.arg_reference_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start" => { + call = call.start(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "end" => { + call = call.end(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _references_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.references().get(&self.opt.arg_reference_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _references_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchReferencesRequest = Default::default(); + let mut call = self.hub.references().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "md5checksums" => { + if request.md5checksums.is_none() { + request.md5checksums = Some(Default::default()); + } + request.md5checksums.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "reference-set-id" => { + request.reference_set_id = Some(value.unwrap_or("").to_string()); + }, + "accessions" => { + if request.accessions.is_none() { + request.accessions = Some(Default::default()); + } + request.accessions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _referencesets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.referencesets().get(&self.opt.arg_reference_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _referencesets_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchReferenceSetsRequest = Default::default(); + let mut call = self.hub.referencesets().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "md5checksums" => { + if request.md5checksums.is_none() { + request.md5checksums = Some(Default::default()); + } + request.md5checksums.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "assembly-id" => { + request.assembly_id = Some(value.unwrap_or("").to_string()); + }, + "accessions" => { + if request.accessions.is_none() { + request.accessions = Some(Default::default()); + } + request.accessions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _streaming_variant_store_streamvariants(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::StreamVariantsRequest = Default::default(); + let mut call = self.hub.streaming_variant_store().streamvariants(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "call-set-ids" => { + if request.call_set_ids.is_none() { + request.call_set_ids = Some(Default::default()); + } + request.call_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "end" => { + request.end = Some(value.unwrap_or("").to_string()); + }, + "start" => { + request.start = Some(value.unwrap_or("").to_string()); + }, + "reference-name" => { + request.reference_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variants_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Variant = Default::default(); + let mut call = self.hub.variants().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "variant-set-id" => { + request.variant_set_id = Some(value.unwrap_or("").to_string()); + }, + "end" => { + request.end = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "reference-bases" => { + request.reference_bases = Some(value.unwrap_or("").to_string()); + }, + "filter" => { + if request.filter.is_none() { + request.filter = Some(Default::default()); + } + request.filter.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start" => { + request.start = Some(value.unwrap_or("").to_string()); + }, + "names" => { + if request.names.is_none() { + request.names = Some(Default::default()); + } + request.names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "alternate-bases" => { + if request.alternate_bases.is_none() { + request.alternate_bases = Some(Default::default()); + } + request.alternate_bases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "reference-name" => { + request.reference_name = Some(value.unwrap_or("").to_string()); + }, + "quality" => { + request.quality = Some(arg_from_str(value.unwrap_or("0.0"), err, "quality", "number")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variants_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.variants().delete(&self.opt.arg_variant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _variants_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.variants().get(&self.opt.arg_variant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variants_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchVariantsRequest = Default::default(); + let mut call = self.hub.variants().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "end" => { + request.end = Some(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "start" => { + request.start = Some(value.unwrap_or("").to_string()); + }, + "max-calls" => { + request.max_calls = Some(arg_from_str(value.unwrap_or("-0"), err, "max-calls", "integer")); + }, + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "call-set-ids" => { + if request.call_set_ids.is_none() { + request.call_set_ids = Some(Default::default()); + } + request.call_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "variant-name" => { + request.variant_name = Some(value.unwrap_or("").to_string()); + }, + "reference-name" => { + request.reference_name = Some(value.unwrap_or("").to_string()); + }, + "variant-set-ids" => { + if request.variant_set_ids.is_none() { + request.variant_set_ids = Some(Default::default()); + } + request.variant_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variants_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Variant = Default::default(); + let mut call = self.hub.variants().update(&request, &self.opt.arg_variant_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "variant-set-id" => { + request.variant_set_id = Some(value.unwrap_or("").to_string()); + }, + "end" => { + request.end = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "reference-bases" => { + request.reference_bases = Some(value.unwrap_or("").to_string()); + }, + "filter" => { + if request.filter.is_none() { + request.filter = Some(Default::default()); + } + request.filter.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "start" => { + request.start = Some(value.unwrap_or("").to_string()); + }, + "names" => { + if request.names.is_none() { + request.names = Some(Default::default()); + } + request.names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "alternate-bases" => { + if request.alternate_bases.is_none() { + request.alternate_bases = Some(Default::default()); + } + request.alternate_bases.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "reference-name" => { + request.reference_name = Some(value.unwrap_or("").to_string()); + }, + "quality" => { + request.quality = Some(arg_from_str(value.unwrap_or("0.0"), err, "quality", "number")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.variantsets().delete(&self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _variantsets_export(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ExportVariantSetRequest = Default::default(); + let mut call = self.hub.variantsets().export(&request, &self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "bigquery-dataset" => { + request.bigquery_dataset = Some(value.unwrap_or("").to_string()); + }, + "format" => { + request.format = Some(value.unwrap_or("").to_string()); + }, + "call-set-ids" => { + if request.call_set_ids.is_none() { + request.call_set_ids = Some(Default::default()); + } + request.call_set_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "project-number" => { + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "bigquery-table" => { + request.bigquery_table = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.variantsets().get(&self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_import_variants(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ImportVariantsRequest = Default::default(); + let mut call = self.hub.variantsets().import_variants(&request, &self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "source-uris" => { + if request.source_uris.is_none() { + request.source_uris = Some(Default::default()); + } + request.source_uris.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "format" => { + request.format = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_merge_variants(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::MergeVariantsRequest = Default::default(); + let mut call = self.hub.variantsets().merge_variants(&request, &self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _variantsets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::VariantSet = Default::default(); + let mut call = self.hub.variantsets().patch(&request, &self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SearchVariantSetsRequest = Default::default(); + let mut call = self.hub.variantsets().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "page-token" => { + request.page_token = Some(value.unwrap_or("").to_string()); + }, + "dataset-ids" => { + if request.dataset_ids.is_none() { + request.dataset_ids = Some(Default::default()); + } + request.dataset_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "page-size" => { + request.page_size = Some(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _variantsets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::VariantSet = Default::default(); + let mut call = self.hub.variantsets().update(&request, &self.opt.arg_variant_set_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "dataset-id" => { + request.dataset_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_annotation_sets { + if self.opt.cmd_create { + call_result = self._annotation_sets_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._annotation_sets_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._annotation_sets_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._annotation_sets_patch(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._annotation_sets_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._annotation_sets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_annotations { + if self.opt.cmd_batch_create { + call_result = self._annotations_batch_create(dry_run, &mut err); + } else if self.opt.cmd_create { + call_result = self._annotations_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._annotations_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._annotations_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._annotations_patch(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._annotations_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._annotations_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_callsets { + if self.opt.cmd_create { + call_result = self._callsets_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._callsets_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._callsets_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._callsets_patch(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._callsets_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._callsets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_datasets { + if self.opt.cmd_create { + call_result = self._datasets_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._datasets_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._datasets_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._datasets_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._datasets_patch(dry_run, &mut err); + } else if self.opt.cmd_undelete { + call_result = self._datasets_undelete(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._datasets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_experimental { + if self.opt.cmd_jobs_create { + call_result = self._experimental_jobs_create(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_jobs { + if self.opt.cmd_cancel { + call_result = self._jobs_cancel(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._jobs_get(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._jobs_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_readgroupsets { + if self.opt.cmd_align { + call_result = self._readgroupsets_align(dry_run, &mut err); + } else if self.opt.cmd_call { + call_result = self._readgroupsets_call(dry_run, &mut err); + } else if self.opt.cmd_coveragebuckets_list { + call_result = self._readgroupsets_coveragebuckets_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._readgroupsets_delete(dry_run, &mut err); + } else if self.opt.cmd_export { + call_result = self._readgroupsets_export(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._readgroupsets_get(dry_run, &mut err); + } else if self.opt.cmd_import { + call_result = self._readgroupsets_import(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._readgroupsets_patch(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._readgroupsets_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._readgroupsets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reads { + if self.opt.cmd_search { + call_result = self._reads_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_references { + if self.opt.cmd_bases_list { + call_result = self._references_bases_list(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._references_get(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._references_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_referencesets { + if self.opt.cmd_get { + call_result = self._referencesets_get(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._referencesets_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_streaming_variant_store { + if self.opt.cmd_streamvariants { + call_result = self._streaming_variant_store_streamvariants(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_variants { + if self.opt.cmd_create { + call_result = self._variants_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._variants_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._variants_get(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._variants_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._variants_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_variantsets { + if self.opt.cmd_delete { + call_result = self._variantsets_delete(dry_run, &mut err); + } else if self.opt.cmd_export { + call_result = self._variantsets_export(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._variantsets_get(dry_run, &mut err); + } else if self.opt.cmd_import_variants { + call_result = self._variantsets_import_variants(dry_run, &mut err); + } else if self.opt.cmd_merge_variants { + call_result = self._variantsets_merge_variants(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._variantsets_patch(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._variantsets_search(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._variantsets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "genomics1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "genomics1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Genomics::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/gmail1-cli/Cargo.toml b/gen/gmail1-cli/Cargo.toml new file mode 100644 index 00000000000..ca7c3ac068c --- /dev/null +++ b/gen/gmail1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-gmail1-cli" +version = "0.0.1+20150303" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with gmail (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/gmail1-cli" +homepage = "https://developers.google.com/gmail/api/" +documentation = "http://byron.github.io/google-apis-rs/google_gmail1_cli" +license = "MIT" +keywords = ["gmail", "google", "cli"] + +[[bin]] +name = "gmail1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-gmail1] +path = "../gmail1" diff --git a/gen/gmail1-cli/LICENSE.md b/gen/gmail1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/gmail1-cli/LICENSE.md @@ -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. diff --git a/gen/gmail1-cli/README.md b/gen/gmail1-cli/README.md new file mode 100644 index 00000000000..40a1d34cc4a --- /dev/null +++ b/gen/gmail1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GMAIL:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/gmail1-cli/mkdocs.yml b/gen/gmail1-cli/mkdocs.yml new file mode 100644 index 00000000000..8802363c1c1 --- /dev/null +++ b/gen/gmail1-cli/mkdocs.yml @@ -0,0 +1,46 @@ +site_name: gmail v0.0.1+20150303 +site_url: http://byron.github.io/google-apis-rs/google-gmail1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/gmail1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['users_drafts-create.md', 'Users', 'Drafts Create'] +- ['users_drafts-delete.md', 'Users', 'Drafts Delete'] +- ['users_drafts-get.md', 'Users', 'Drafts Get'] +- ['users_drafts-list.md', 'Users', 'Drafts List'] +- ['users_drafts-send.md', 'Users', 'Drafts Send'] +- ['users_drafts-update.md', 'Users', 'Drafts Update'] +- ['users_get-profile.md', 'Users', 'Get Profile'] +- ['users_history-list.md', 'Users', 'History List'] +- ['users_labels-create.md', 'Users', 'Labels Create'] +- ['users_labels-delete.md', 'Users', 'Labels Delete'] +- ['users_labels-get.md', 'Users', 'Labels Get'] +- ['users_labels-list.md', 'Users', 'Labels List'] +- ['users_labels-patch.md', 'Users', 'Labels Patch'] +- ['users_labels-update.md', 'Users', 'Labels Update'] +- ['users_messages-attachments-get.md', 'Users', 'Messages Attachments Get'] +- ['users_messages-delete.md', 'Users', 'Messages Delete'] +- ['users_messages-get.md', 'Users', 'Messages Get'] +- ['users_messages-import.md', 'Users', 'Messages Import'] +- ['users_messages-insert.md', 'Users', 'Messages Insert'] +- ['users_messages-list.md', 'Users', 'Messages List'] +- ['users_messages-modify.md', 'Users', 'Messages Modify'] +- ['users_messages-send.md', 'Users', 'Messages Send'] +- ['users_messages-trash.md', 'Users', 'Messages Trash'] +- ['users_messages-untrash.md', 'Users', 'Messages Untrash'] +- ['users_threads-delete.md', 'Users', 'Threads Delete'] +- ['users_threads-get.md', 'Users', 'Threads Get'] +- ['users_threads-list.md', 'Users', 'Threads List'] +- ['users_threads-modify.md', 'Users', 'Threads Modify'] +- ['users_threads-trash.md', 'Users', 'Threads Trash'] +- ['users_threads-untrash.md', 'Users', 'Threads Untrash'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/gmail1-cli/src/cmn.rs b/gen/gmail1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/gmail1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/gmail1-cli/src/main.rs b/gen/gmail1-cli/src/main.rs new file mode 100644 index 00000000000..7c1b6ba7ce7 --- /dev/null +++ b/gen/gmail1-cli/src/main.rs @@ -0,0 +1,2313 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_gmail1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + gmail1 [options] users drafts-create <user-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users drafts-delete <user-id> <id> [-p <v>]... + gmail1 [options] users drafts-get <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users drafts-list <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users drafts-send <user-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users drafts-update <user-id> <id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users get-profile <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users history-list <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users labels-create <user-id> -r <kv>... [-p <v>]... [-o <out>] + gmail1 [options] users labels-delete <user-id> <id> [-p <v>]... + gmail1 [options] users labels-get <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users labels-list <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users labels-patch <user-id> <id> -r <kv>... [-p <v>]... [-o <out>] + gmail1 [options] users labels-update <user-id> <id> -r <kv>... [-p <v>]... [-o <out>] + gmail1 [options] users messages-attachments-get <user-id> <message-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users messages-delete <user-id> <id> [-p <v>]... + gmail1 [options] users messages-get <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users messages-import <user-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users messages-insert <user-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users messages-list <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users messages-modify <user-id> <id> -r <kv>... [-p <v>]... [-o <out>] + gmail1 [options] users messages-send <user-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + gmail1 [options] users messages-trash <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users messages-untrash <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users threads-delete <user-id> <id> [-p <v>]... + gmail1 [options] users threads-get <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users threads-list <user-id> [-p <v>]... [-o <out>] + gmail1 [options] users threads-modify <user-id> <id> -r <kv>... [-p <v>]... [-o <out>] + gmail1 [options] users threads-trash <user-id> <id> [-p <v>]... [-o <out>] + gmail1 [options] users threads-untrash <user-id> <id> [-p <v>]... [-o <out>] + gmail1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Gmail<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _users_drafts_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Draft = Default::default(); + let mut call = self.hub.users().drafts_create(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_message_init(request: &mut api::Draft) { + if request.message.is_none() { + request.message = Some(Default::default()); + } + } + + fn request_message_payload_init(request: &mut api::Draft) { + request_message_init(request); + if request.message.as_mut().unwrap().payload.is_none() { + request.message.as_mut().unwrap().payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "message.history-id" => { + request_message_init(&mut request); + request.message.as_mut().unwrap().history_id = Some(value.unwrap_or("").to_string()); + }, + "message.payload.body.data" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "message.payload.body.attachment-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "message.payload.body.size" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "message.payload.body.size", "integer"); + }, + "message.payload.mime-type" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "message.payload.part-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "message.payload.filename" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "message.snippet" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().snippet = Some(value.unwrap_or("").to_string()); + }, + "message.raw" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().raw = Some(value.unwrap_or("").to_string()); + }, + "message.size-estimate" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "message.size-estimate", "integer")); + }, + "message.thread-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().thread_id = Some(value.unwrap_or("").to_string()); + }, + "message.label-ids" => { + request_message_payload_init(&mut request); + if request.message.as_mut().unwrap().label_ids.is_none() { + request.message.as_mut().unwrap().label_ids = Some(Default::default()); + } + request.message.as_mut().unwrap().label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "message.id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_message_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_drafts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().drafts_delete(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_drafts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().drafts_get(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "format" => { + call = call.format(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_drafts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().drafts_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_drafts_send(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Draft = Default::default(); + let mut call = self.hub.users().drafts_send(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_message_init(request: &mut api::Draft) { + if request.message.is_none() { + request.message = Some(Default::default()); + } + } + + fn request_message_payload_init(request: &mut api::Draft) { + request_message_init(request); + if request.message.as_mut().unwrap().payload.is_none() { + request.message.as_mut().unwrap().payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "message.history-id" => { + request_message_init(&mut request); + request.message.as_mut().unwrap().history_id = Some(value.unwrap_or("").to_string()); + }, + "message.payload.body.data" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "message.payload.body.attachment-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "message.payload.body.size" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "message.payload.body.size", "integer"); + }, + "message.payload.mime-type" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "message.payload.part-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "message.payload.filename" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "message.snippet" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().snippet = Some(value.unwrap_or("").to_string()); + }, + "message.raw" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().raw = Some(value.unwrap_or("").to_string()); + }, + "message.size-estimate" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "message.size-estimate", "integer")); + }, + "message.thread-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().thread_id = Some(value.unwrap_or("").to_string()); + }, + "message.label-ids" => { + request_message_payload_init(&mut request); + if request.message.as_mut().unwrap().label_ids.is_none() { + request.message.as_mut().unwrap().label_ids = Some(Default::default()); + } + request.message.as_mut().unwrap().label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "message.id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_message_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_drafts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Draft = Default::default(); + let mut call = self.hub.users().drafts_update(&request, &self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_message_init(request: &mut api::Draft) { + if request.message.is_none() { + request.message = Some(Default::default()); + } + } + + fn request_message_payload_init(request: &mut api::Draft) { + request_message_init(request); + if request.message.as_mut().unwrap().payload.is_none() { + request.message.as_mut().unwrap().payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "message.history-id" => { + request_message_init(&mut request); + request.message.as_mut().unwrap().history_id = Some(value.unwrap_or("").to_string()); + }, + "message.payload.body.data" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "message.payload.body.attachment-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "message.payload.body.size" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "message.payload.body.size", "integer"); + }, + "message.payload.mime-type" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "message.payload.part-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "message.payload.filename" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "message.snippet" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().snippet = Some(value.unwrap_or("").to_string()); + }, + "message.raw" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().raw = Some(value.unwrap_or("").to_string()); + }, + "message.size-estimate" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "message.size-estimate", "integer")); + }, + "message.thread-id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().thread_id = Some(value.unwrap_or("").to_string()); + }, + "message.label-ids" => { + request_message_payload_init(&mut request); + if request.message.as_mut().unwrap().label_ids.is_none() { + request.message.as_mut().unwrap().label_ids = Some(Default::default()); + } + request.message.as_mut().unwrap().label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "message.id" => { + request_message_payload_init(&mut request); + request.message.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_message_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_get_profile(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().get_profile(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_history_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().history_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-history-id" => { + call = call.start_history_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "label-id" => { + call = call.label_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_labels_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Label = Default::default(); + let mut call = self.hub.users().labels_create(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "messages-total" => { + request.messages_total = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-total", "integer")); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "threads-total" => { + request.threads_total = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-total", "integer")); + }, + "label-list-visibility" => { + request.label_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "threads-unread" => { + request.threads_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-unread", "integer")); + }, + "message-list-visibility" => { + request.message_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "messages-unread" => { + request.messages_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-unread", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_labels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().labels_delete(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_labels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().labels_get(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_labels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().labels_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_labels_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Label = Default::default(); + let mut call = self.hub.users().labels_patch(&request, &self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "messages-total" => { + request.messages_total = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-total", "integer")); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "threads-total" => { + request.threads_total = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-total", "integer")); + }, + "label-list-visibility" => { + request.label_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "threads-unread" => { + request.threads_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-unread", "integer")); + }, + "message-list-visibility" => { + request.message_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "messages-unread" => { + request.messages_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-unread", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_labels_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Label = Default::default(); + let mut call = self.hub.users().labels_update(&request, &self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "messages-total" => { + request.messages_total = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-total", "integer")); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "threads-total" => { + request.threads_total = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-total", "integer")); + }, + "label-list-visibility" => { + request.label_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "threads-unread" => { + request.threads_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "threads-unread", "integer")); + }, + "message-list-visibility" => { + request.message_list_visibility = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "messages-unread" => { + request.messages_unread = Some(arg_from_str(value.unwrap_or("-0"), err, "messages-unread", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_attachments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_attachments_get(&self.opt.arg_user_id, &self.opt.arg_message_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_delete(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_messages_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_get(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "metadata-headers" => { + call = call.add_metadata_headers(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_import(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Message = Default::default(); + let mut call = self.hub.users().messages_import(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "process-for-calendar" => { + call = call.process_for_calendar(arg_from_str(value.unwrap_or("false"), err, "process-for-calendar", "boolean")); + }, + "never-mark-spam" => { + call = call.never_mark_spam(arg_from_str(value.unwrap_or("false"), err, "never-mark-spam", "boolean")); + }, + "internal-date-source" => { + call = call.internal_date_source(value.unwrap_or("")); + }, + "deleted" => { + call = call.deleted(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_payload_init(request: &mut api::Message) { + if request.payload.is_none() { + request.payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "history-id" => { + request.history_id = Some(value.unwrap_or("").to_string()); + }, + "payload.body.data" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "payload.body.attachment-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "payload.body.size" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "payload.body.size", "integer"); + }, + "payload.mime-type" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "payload.part-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "payload.filename" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "snippet" => { + request_payload_init(&mut request); + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "raw" => { + request_payload_init(&mut request); + request.raw = Some(value.unwrap_or("").to_string()); + }, + "size-estimate" => { + request_payload_init(&mut request); + request.size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "size-estimate", "integer")); + }, + "thread-id" => { + request_payload_init(&mut request); + request.thread_id = Some(value.unwrap_or("").to_string()); + }, + "label-ids" => { + request_payload_init(&mut request); + if request.label_ids.is_none() { + request.label_ids = Some(Default::default()); + } + request.label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_payload_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Message = Default::default(); + let mut call = self.hub.users().messages_insert(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "internal-date-source" => { + call = call.internal_date_source(value.unwrap_or("")); + }, + "deleted" => { + call = call.deleted(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_payload_init(request: &mut api::Message) { + if request.payload.is_none() { + request.payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "history-id" => { + request.history_id = Some(value.unwrap_or("").to_string()); + }, + "payload.body.data" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "payload.body.attachment-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "payload.body.size" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "payload.body.size", "integer"); + }, + "payload.mime-type" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "payload.part-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "payload.filename" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "snippet" => { + request_payload_init(&mut request); + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "raw" => { + request_payload_init(&mut request); + request.raw = Some(value.unwrap_or("").to_string()); + }, + "size-estimate" => { + request_payload_init(&mut request); + request.size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "size-estimate", "integer")); + }, + "thread-id" => { + request_payload_init(&mut request); + request.thread_id = Some(value.unwrap_or("").to_string()); + }, + "label-ids" => { + request_payload_init(&mut request); + if request.label_ids.is_none() { + request.label_ids = Some(Default::default()); + } + request.label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_payload_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "label-ids" => { + call = call.add_label_ids(value.unwrap_or("")); + }, + "include-spam-trash" => { + call = call.include_spam_trash(arg_from_str(value.unwrap_or("false"), err, "include-spam-trash", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_modify(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ModifyMessageRequest = Default::default(); + let mut call = self.hub.users().messages_modify(&request, &self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "remove-label-ids" => { + if request.remove_label_ids.is_none() { + request.remove_label_ids = Some(Default::default()); + } + request.remove_label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "add-label-ids" => { + if request.add_label_ids.is_none() { + request.add_label_ids = Some(Default::default()); + } + request.add_label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_send(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Message = Default::default(); + let mut call = self.hub.users().messages_send(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_payload_init(request: &mut api::Message) { + if request.payload.is_none() { + request.payload = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "history-id" => { + request.history_id = Some(value.unwrap_or("").to_string()); + }, + "payload.body.data" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.data = value.unwrap_or("").to_string(); + }, + "payload.body.attachment-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.attachment_id = value.unwrap_or("").to_string(); + }, + "payload.body.size" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().body.size = arg_from_str(value.unwrap_or("-0"), err, "payload.body.size", "integer"); + }, + "payload.mime-type" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().mime_type = value.unwrap_or("").to_string(); + }, + "payload.part-id" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().part_id = value.unwrap_or("").to_string(); + }, + "payload.filename" => { + request_payload_init(&mut request); + request.payload.as_mut().unwrap().filename = value.unwrap_or("").to_string(); + }, + "snippet" => { + request_payload_init(&mut request); + request.snippet = Some(value.unwrap_or("").to_string()); + }, + "raw" => { + request_payload_init(&mut request); + request.raw = Some(value.unwrap_or("").to_string()); + }, + "size-estimate" => { + request_payload_init(&mut request); + request.size_estimate = Some(arg_from_str(value.unwrap_or("-0"), err, "size-estimate", "integer")); + }, + "thread-id" => { + request_payload_init(&mut request); + request.thread_id = Some(value.unwrap_or("").to_string()); + }, + "label-ids" => { + request_payload_init(&mut request); + if request.label_ids.is_none() { + request.label_ids = Some(Default::default()); + } + request.label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_payload_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_trash(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_messages_untrash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().messages_untrash(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_threads_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().threads_delete(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _users_threads_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().threads_get(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "metadata-headers" => { + call = call.add_metadata_headers(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_threads_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().threads_list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "q" => { + call = call.q(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "label-ids" => { + call = call.add_label_ids(value.unwrap_or("")); + }, + "include-spam-trash" => { + call = call.include_spam_trash(arg_from_str(value.unwrap_or("false"), err, "include-spam-trash", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_threads_modify(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ModifyThreadRequest = Default::default(); + let mut call = self.hub.users().threads_modify(&request, &self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "remove-label-ids" => { + if request.remove_label_ids.is_none() { + request.remove_label_ids = Some(Default::default()); + } + request.remove_label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "add-label-ids" => { + if request.add_label_ids.is_none() { + request.add_label_ids = Some(Default::default()); + } + request.add_label_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_threads_trash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().threads_trash(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_threads_untrash(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().threads_untrash(&self.opt.arg_user_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_users { + if self.opt.cmd_drafts_create { + call_result = self._users_drafts_create(dry_run, &mut err); + } else if self.opt.cmd_drafts_delete { + call_result = self._users_drafts_delete(dry_run, &mut err); + } else if self.opt.cmd_drafts_get { + call_result = self._users_drafts_get(dry_run, &mut err); + } else if self.opt.cmd_drafts_list { + call_result = self._users_drafts_list(dry_run, &mut err); + } else if self.opt.cmd_drafts_send { + call_result = self._users_drafts_send(dry_run, &mut err); + } else if self.opt.cmd_drafts_update { + call_result = self._users_drafts_update(dry_run, &mut err); + } else if self.opt.cmd_get_profile { + call_result = self._users_get_profile(dry_run, &mut err); + } else if self.opt.cmd_history_list { + call_result = self._users_history_list(dry_run, &mut err); + } else if self.opt.cmd_labels_create { + call_result = self._users_labels_create(dry_run, &mut err); + } else if self.opt.cmd_labels_delete { + call_result = self._users_labels_delete(dry_run, &mut err); + } else if self.opt.cmd_labels_get { + call_result = self._users_labels_get(dry_run, &mut err); + } else if self.opt.cmd_labels_list { + call_result = self._users_labels_list(dry_run, &mut err); + } else if self.opt.cmd_labels_patch { + call_result = self._users_labels_patch(dry_run, &mut err); + } else if self.opt.cmd_labels_update { + call_result = self._users_labels_update(dry_run, &mut err); + } else if self.opt.cmd_messages_attachments_get { + call_result = self._users_messages_attachments_get(dry_run, &mut err); + } else if self.opt.cmd_messages_delete { + call_result = self._users_messages_delete(dry_run, &mut err); + } else if self.opt.cmd_messages_get { + call_result = self._users_messages_get(dry_run, &mut err); + } else if self.opt.cmd_messages_import { + call_result = self._users_messages_import(dry_run, &mut err); + } else if self.opt.cmd_messages_insert { + call_result = self._users_messages_insert(dry_run, &mut err); + } else if self.opt.cmd_messages_list { + call_result = self._users_messages_list(dry_run, &mut err); + } else if self.opt.cmd_messages_modify { + call_result = self._users_messages_modify(dry_run, &mut err); + } else if self.opt.cmd_messages_send { + call_result = self._users_messages_send(dry_run, &mut err); + } else if self.opt.cmd_messages_trash { + call_result = self._users_messages_trash(dry_run, &mut err); + } else if self.opt.cmd_messages_untrash { + call_result = self._users_messages_untrash(dry_run, &mut err); + } else if self.opt.cmd_threads_delete { + call_result = self._users_threads_delete(dry_run, &mut err); + } else if self.opt.cmd_threads_get { + call_result = self._users_threads_get(dry_run, &mut err); + } else if self.opt.cmd_threads_list { + call_result = self._users_threads_list(dry_run, &mut err); + } else if self.opt.cmd_threads_modify { + call_result = self._users_threads_modify(dry_run, &mut err); + } else if self.opt.cmd_threads_trash { + call_result = self._users_threads_trash(dry_run, &mut err); + } else if self.opt.cmd_threads_untrash { + call_result = self._users_threads_untrash(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "gmail1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "gmail1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Gmail::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/groupsmigration1-cli/Cargo.toml b/gen/groupsmigration1-cli/Cargo.toml index b935d7dc906..b739c5bec27 100644 --- a/gen/groupsmigration1-cli/Cargo.toml +++ b/gen/groupsmigration1-cli/Cargo.toml @@ -20,9 +20,11 @@ name = "groupsmigration1" hyper = "*" mime = "*" yup-oauth2 = "*" -docopt = "*" -docopt_macros = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" [dependencies.google-groupsmigration1] path = "../groupsmigration1" diff --git a/gen/groupsmigration1-cli/README.md b/gen/groupsmigration1-cli/README.md index c2a1dfe3f0c..dc0dd013270 100644 --- a/gen/groupsmigration1-cli/README.md +++ b/gen/groupsmigration1-cli/README.md @@ -1 +1,4 @@ -# HELLO GROUPSMIGRATION:V1 \ No newline at end of file +# HELLO GROUPSMIGRATION:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/groupsmigration1-cli/src/cmn.rs b/gen/groupsmigration1-cli/src/cmn.rs index 1d43a4a85c2..fd8d66fa4c3 100644 --- a/gen/groupsmigration1-cli/src/cmn.rs +++ b/gen/groupsmigration1-cli/src/cmn.rs @@ -1,2 +1,439 @@ // 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/groupsmigration1-cli/src/main.rs b/gen/groupsmigration1-cli/src/main.rs index 42a582ac266..d172162d9e9 100644 --- a/gen/groupsmigration1-cli/src/main.rs +++ b/gen/groupsmigration1-cli/src/main.rs @@ -1,19 +1,183 @@ // DO NOT EDIT ! // This file was generated automatically from 'src/mako/cli/main.rs.mako' // DO NOT EDIT ! -#![feature(plugin)] +#![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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_groupsmigration1 as api; -docopt!(Args derive Debug, " +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " Usage: - groupsmigration1 archive insert - groupsmigration1 --help + groupsmigration1 [options] archive insert <group-id> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + groupsmigration1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] "); +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::GroupsMigration<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _archive_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.archive().insert(&self.opt.arg_group_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_archive { + if self.opt.cmd_insert { + call_result = self._archive_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "groupsmigration1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "groupsmigration1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::GroupsMigration::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + fn main() { - let _: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); - println!("Hello, groupsmigration:v1 !"); + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } } \ No newline at end of file diff --git a/gen/groupsmigration1/README.md b/gen/groupsmigration1/README.md index d36d156dac4..fb5f65253b3 100644 --- a/gen/groupsmigration1/README.md +++ b/gen/groupsmigration1/README.md @@ -102,16 +102,18 @@ let result = hub.archive().insert("groupId") match result { Err(e) => match e { - Error::HttpError(err) => println!("HTTPERROR: {:?}", err), - Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), - Error::MissingToken => println!("OAuth2: Missing Token"), - Error::Cancelled => println!("Operation canceled by user"), - Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), - Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), - Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), - Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), + // The Error enum provides details about what exactly happened. + // You can also just use its `Debug`, `Display` or `Error` traits + Error::HttpError(_) + |Error::MissingAPIKey + |Error::MissingToken + |Error::Cancelled + |Error::UploadSizeLimitExceeded(_, _) + |Error::Failure(_) + |Error::FieldClash(_) + |Error::JsonDecodeError(_) => println!("{}", e), }, - Ok(_) => println!("Success (value doesn't print)"), + Ok(res) => println!("Success: {:?}", res), } ``` diff --git a/gen/groupsmigration1/src/cmn.rs b/gen/groupsmigration1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/groupsmigration1/src/cmn.rs +++ b/gen/groupsmigration1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/groupsmigration1/src/lib.rs b/gen/groupsmigration1/src/lib.rs index 82ddd7151c7..a227a3d5a3e 100644 --- a/gen/groupsmigration1/src/lib.rs +++ b/gen/groupsmigration1/src/lib.rs @@ -103,16 +103,18 @@ //! //! match result { //! Err(e) => match e { -//! Error::HttpError(err) => println!("HTTPERROR: {:?}", err), -//! Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), -//! Error::MissingToken => println!("OAuth2: Missing Token"), -//! Error::Cancelled => println!("Operation canceled by user"), -//! Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), -//! Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), -//! Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), -//! Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +//! // The Error enum provides details about what exactly happened. +//! // You can also just use its `Debug`, `Display` or `Error` traits +//! Error::HttpError(_) +//! |Error::MissingAPIKey +//! |Error::MissingToken +//! |Error::Cancelled +//! |Error::UploadSizeLimitExceeded(_, _) +//! |Error::Failure(_) +//! |Error::FieldClash(_) +//! |Error::JsonDecodeError(_) => println!("{}", e), //! }, -//! Ok(_) => println!("Success (value doesn't print)"), +//! Ok(res) => println!("Success: {:?}", res), //! } //! # } //! ``` @@ -271,16 +273,18 @@ impl Default for Scope { /// /// match result { /// Err(e) => match e { -/// Error::HttpError(err) => println!("HTTPERROR: {:?}", err), -/// Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), -/// Error::MissingToken => println!("OAuth2: Missing Token"), -/// Error::Cancelled => println!("Operation canceled by user"), -/// Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), -/// Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), -/// Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), -/// Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +/// // The Error enum provides details about what exactly happened. +/// // You can also just use its `Debug`, `Display` or `Error` traits +/// Error::HttpError(_) +/// |Error::MissingAPIKey +/// |Error::MissingToken +/// |Error::Cancelled +/// |Error::UploadSizeLimitExceeded(_, _) +/// |Error::Failure(_) +/// |Error::FieldClash(_) +/// |Error::JsonDecodeError(_) => println!("{}", e), /// }, -/// Ok(_) => println!("Success (value doesn't print)"), +/// Ok(res) => println!("Success: {:?}", res), /// } /// # } /// ``` @@ -331,7 +335,7 @@ impl<'a, C, A> GroupsMigration<C, A> /// /// * [insert archive](struct.ArchiveInsertCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Groups { /// The kind of insert resource this is. pub kind: String, @@ -690,23 +694,22 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: self.doit(resumeable_stream, mime_type, "resumable") } + /// The group ID + /// /// Sets the *group id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The group ID pub fn group_id(mut self, new_value: &str) -> ArchiveInsertCall<'a, C, A> { self._group_id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> ArchiveInsertCall<'a, C, A> { self._delegate = Some(new_value); self @@ -736,8 +739,8 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::AppGroupMigration`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. diff --git a/gen/groupssettings1-cli/Cargo.toml b/gen/groupssettings1-cli/Cargo.toml new file mode 100644 index 00000000000..c767e281529 --- /dev/null +++ b/gen/groupssettings1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-groupssettings1-cli" +version = "0.0.1+20140428" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with groupssettings (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/groupssettings1-cli" +homepage = "https://developers.google.com/google-apps/groups-settings/get_started" +documentation = "http://byron.github.io/google-apis-rs/google_groupssettings1_cli" +license = "MIT" +keywords = ["groupssettings", "google", "cli"] + +[[bin]] +name = "groupssettings1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-groupssettings1] +path = "../groupssettings1" diff --git a/gen/groupssettings1-cli/LICENSE.md b/gen/groupssettings1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/groupssettings1-cli/LICENSE.md @@ -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. diff --git a/gen/groupssettings1-cli/README.md b/gen/groupssettings1-cli/README.md new file mode 100644 index 00000000000..2583be4b69a --- /dev/null +++ b/gen/groupssettings1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO GROUPSSETTINGS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/groupssettings1-cli/mkdocs.yml b/gen/groupssettings1-cli/mkdocs.yml new file mode 100644 index 00000000000..5a01a4c8452 --- /dev/null +++ b/gen/groupssettings1-cli/mkdocs.yml @@ -0,0 +1,19 @@ +site_name: groupssettings v0.0.1+20140428 +site_url: http://byron.github.io/google-apis-rs/google-groupssettings1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/groupssettings1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['groups_get.md', 'Groups', 'Get'] +- ['groups_patch.md', 'Groups', 'Patch'] +- ['groups_update.md', 'Groups', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/groupssettings1-cli/src/cmn.rs b/gen/groupssettings1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/groupssettings1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/groupssettings1-cli/src/main.rs b/gen/groupssettings1-cli/src/main.rs new file mode 100644 index 00000000000..83b6b8ad3ac --- /dev/null +++ b/gen/groupssettings1-cli/src/main.rs @@ -0,0 +1,461 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_groupssettings1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + groupssettings1 [options] groups get <group-unique-id> [-p <v>]... [-o <out>] + groupssettings1 [options] groups patch <group-unique-id> -r <kv>... [-p <v>]... [-o <out>] + groupssettings1 [options] groups update <group-unique-id> -r <kv>... [-p <v>]... [-o <out>] + groupssettings1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Groupssettings<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _groups_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.groups().get(&self.opt.arg_group_unique_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Groups = Default::default(); + let mut call = self.hub.groups().patch(&request, &self.opt.arg_group_unique_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "allow-external-members" => { + request.allow_external_members = Some(value.unwrap_or("").to_string()); + }, + "who-can-post-message" => { + request.who_can_post_message = Some(value.unwrap_or("").to_string()); + }, + "primary-language" => { + request.primary_language = Some(value.unwrap_or("").to_string()); + }, + "who-can-view-membership" => { + request.who_can_view_membership = Some(value.unwrap_or("").to_string()); + }, + "default-message-deny-notification-text" => { + request.default_message_deny_notification_text = Some(value.unwrap_or("").to_string()); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(value.unwrap_or("").to_string()); + }, + "archive-only" => { + request.archive_only = Some(value.unwrap_or("").to_string()); + }, + "is-archived" => { + request.is_archived = Some(value.unwrap_or("").to_string()); + }, + "members-can-post-as-the-group" => { + request.members_can_post_as_the_group = Some(value.unwrap_or("").to_string()); + }, + "allow-web-posting" => { + request.allow_web_posting = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "message-moderation-level" => { + request.message_moderation_level = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "reply-to" => { + request.reply_to = Some(value.unwrap_or("").to_string()); + }, + "custom-reply-to" => { + request.custom_reply_to = Some(value.unwrap_or("").to_string()); + }, + "send-message-deny-notification" => { + request.send_message_deny_notification = Some(value.unwrap_or("").to_string()); + }, + "who-can-contact-owner" => { + request.who_can_contact_owner = Some(value.unwrap_or("").to_string()); + }, + "message-display-font" => { + request.message_display_font = Some(value.unwrap_or("").to_string()); + }, + "who-can-leave-group" => { + request.who_can_leave_group = Some(value.unwrap_or("").to_string()); + }, + "who-can-join" => { + request.who_can_join = Some(value.unwrap_or("").to_string()); + }, + "who-can-invite" => { + request.who_can_invite = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "spam-moderation-level" => { + request.spam_moderation_level = Some(value.unwrap_or("").to_string()); + }, + "who-can-view-group" => { + request.who_can_view_group = Some(value.unwrap_or("").to_string()); + }, + "show-in-group-directory" => { + request.show_in_group_directory = Some(value.unwrap_or("").to_string()); + }, + "max-message-bytes" => { + request.max_message_bytes = Some(arg_from_str(value.unwrap_or("-0"), err, "max-message-bytes", "integer")); + }, + "allow-google-communication" => { + request.allow_google_communication = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Groups = Default::default(); + let mut call = self.hub.groups().update(&request, &self.opt.arg_group_unique_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "allow-external-members" => { + request.allow_external_members = Some(value.unwrap_or("").to_string()); + }, + "who-can-post-message" => { + request.who_can_post_message = Some(value.unwrap_or("").to_string()); + }, + "primary-language" => { + request.primary_language = Some(value.unwrap_or("").to_string()); + }, + "who-can-view-membership" => { + request.who_can_view_membership = Some(value.unwrap_or("").to_string()); + }, + "default-message-deny-notification-text" => { + request.default_message_deny_notification_text = Some(value.unwrap_or("").to_string()); + }, + "include-in-global-address-list" => { + request.include_in_global_address_list = Some(value.unwrap_or("").to_string()); + }, + "archive-only" => { + request.archive_only = Some(value.unwrap_or("").to_string()); + }, + "is-archived" => { + request.is_archived = Some(value.unwrap_or("").to_string()); + }, + "members-can-post-as-the-group" => { + request.members_can_post_as_the_group = Some(value.unwrap_or("").to_string()); + }, + "allow-web-posting" => { + request.allow_web_posting = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "message-moderation-level" => { + request.message_moderation_level = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "reply-to" => { + request.reply_to = Some(value.unwrap_or("").to_string()); + }, + "custom-reply-to" => { + request.custom_reply_to = Some(value.unwrap_or("").to_string()); + }, + "send-message-deny-notification" => { + request.send_message_deny_notification = Some(value.unwrap_or("").to_string()); + }, + "who-can-contact-owner" => { + request.who_can_contact_owner = Some(value.unwrap_or("").to_string()); + }, + "message-display-font" => { + request.message_display_font = Some(value.unwrap_or("").to_string()); + }, + "who-can-leave-group" => { + request.who_can_leave_group = Some(value.unwrap_or("").to_string()); + }, + "who-can-join" => { + request.who_can_join = Some(value.unwrap_or("").to_string()); + }, + "who-can-invite" => { + request.who_can_invite = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "spam-moderation-level" => { + request.spam_moderation_level = Some(value.unwrap_or("").to_string()); + }, + "who-can-view-group" => { + request.who_can_view_group = Some(value.unwrap_or("").to_string()); + }, + "show-in-group-directory" => { + request.show_in_group_directory = Some(value.unwrap_or("").to_string()); + }, + "max-message-bytes" => { + request.max_message_bytes = Some(arg_from_str(value.unwrap_or("-0"), err, "max-message-bytes", "integer")); + }, + "allow-google-communication" => { + request.allow_google_communication = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_groups { + if self.opt.cmd_get { + call_result = self._groups_get(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._groups_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "groupssettings1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "groupssettings1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Groupssettings::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/Cargo.toml b/gen/identitytoolkit3-cli/Cargo.toml new file mode 100644 index 00000000000..0b441e59008 --- /dev/null +++ b/gen/identitytoolkit3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-identitytoolkit3-cli" +version = "0.0.1+20141009" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Identity Toolkit (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/identitytoolkit3-cli" +homepage = "https://developers.google.com/identity-toolkit/v3/" +documentation = "http://byron.github.io/google-apis-rs/google_identitytoolkit3_cli" +license = "MIT" +keywords = ["identitytoolkit", "google", "cli"] + +[[bin]] +name = "identitytoolkit3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-identitytoolkit3] +path = "../identitytoolkit3" diff --git a/gen/identitytoolkit3-cli/LICENSE.md b/gen/identitytoolkit3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/identitytoolkit3-cli/LICENSE.md @@ -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. diff --git a/gen/identitytoolkit3-cli/README.md b/gen/identitytoolkit3-cli/README.md new file mode 100644 index 00000000000..e5bc6ba8cad --- /dev/null +++ b/gen/identitytoolkit3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO IDENTITYTOOLKIT:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/mkdocs.yml b/gen/identitytoolkit3-cli/mkdocs.yml new file mode 100644 index 00000000000..afcfb7a7859 --- /dev/null +++ b/gen/identitytoolkit3-cli/mkdocs.yml @@ -0,0 +1,27 @@ +site_name: Identity Toolkit v0.0.1+20141009 +site_url: http://byron.github.io/google-apis-rs/google-identitytoolkit3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/identitytoolkit3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['relyingparty_create-auth-uri.md', 'Relyingparty', 'Create Auth Uri'] +- ['relyingparty_delete-account.md', 'Relyingparty', 'Delete Account'] +- ['relyingparty_download-account.md', 'Relyingparty', 'Download Account'] +- ['relyingparty_get-account-info.md', 'Relyingparty', 'Get Account Info'] +- ['relyingparty_get-oob-confirmation-code.md', 'Relyingparty', 'Get Oob Confirmation Code'] +- ['relyingparty_get-public-keys.md', 'Relyingparty', 'Get Public Keys'] +- ['relyingparty_reset-password.md', 'Relyingparty', 'Reset Password'] +- ['relyingparty_set-account-info.md', 'Relyingparty', 'Set Account Info'] +- ['relyingparty_upload-account.md', 'Relyingparty', 'Upload Account'] +- ['relyingparty_verify-assertion.md', 'Relyingparty', 'Verify Assertion'] +- ['relyingparty_verify-password.md', 'Relyingparty', 'Verify Password'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/identitytoolkit3-cli/src/cmn.rs b/gen/identitytoolkit3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/identitytoolkit3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/identitytoolkit3-cli/src/main.rs b/gen/identitytoolkit3-cli/src/main.rs new file mode 100644 index 00000000000..c9862194bbf --- /dev/null +++ b/gen/identitytoolkit3-cli/src/main.rs @@ -0,0 +1,928 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_identitytoolkit3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + identitytoolkit3 [options] relyingparty create-auth-uri -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty delete-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty download-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-account-info -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-oob-confirmation-code -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty get-public-keys [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty reset-password -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty set-account-info -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty upload-account -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty verify-assertion -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 [options] relyingparty verify-password -r <kv>... [-p <v>]... [-o <out>] + identitytoolkit3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::IdentityToolkit<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _relyingparty_create_auth_uri(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyCreateAuthUriRequest = Default::default(); + let mut call = self.hub.relyingparty().create_auth_uri(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "identifier" => { + request.identifier = Some(value.unwrap_or("").to_string()); + }, + "client-id" => { + request.client_id = Some(value.unwrap_or("").to_string()); + }, + "ota-app" => { + request.ota_app = Some(value.unwrap_or("").to_string()); + }, + "provider-id" => { + request.provider_id = Some(value.unwrap_or("").to_string()); + }, + "context" => { + request.context = Some(value.unwrap_or("").to_string()); + }, + "app-id" => { + request.app_id = Some(value.unwrap_or("").to_string()); + }, + "continue-uri" => { + request.continue_uri = Some(value.unwrap_or("").to_string()); + }, + "openid-realm" => { + request.openid_realm = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_delete_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyDeleteAccountRequest = Default::default(); + let mut call = self.hub.relyingparty().delete_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "local-id" => { + request.local_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_download_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyDownloadAccountRequest = Default::default(); + let mut call = self.hub.relyingparty().download_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "next-page-token" => { + request.next_page_token = Some(value.unwrap_or("").to_string()); + }, + "max-results" => { + request.max_results = Some(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_account_info(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyGetAccountInfoRequest = Default::default(); + let mut call = self.hub.relyingparty().get_account_info(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "email" => { + if request.email.is_none() { + request.email = Some(Default::default()); + } + request.email.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "local-id" => { + if request.local_id.is_none() { + request.local_id = Some(Default::default()); + } + request.local_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_oob_confirmation_code(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Relyingparty = Default::default(); + let mut call = self.hub.relyingparty().get_oob_confirmation_code(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "request-type" => { + request.request_type = Some(value.unwrap_or("").to_string()); + }, + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "challenge" => { + request.challenge = Some(value.unwrap_or("").to_string()); + }, + "new-email" => { + request.new_email = Some(value.unwrap_or("").to_string()); + }, + "user-ip" => { + request.user_ip = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "captcha-resp" => { + request.captcha_resp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_get_public_keys(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.relyingparty().get_public_keys(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_reset_password(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyResetPasswordRequest = Default::default(); + let mut call = self.hub.relyingparty().reset_password(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "new-password" => { + request.new_password = Some(value.unwrap_or("").to_string()); + }, + "old-password" => { + request.old_password = Some(value.unwrap_or("").to_string()); + }, + "oob-code" => { + request.oob_code = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_set_account_info(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartySetAccountInfoRequest = Default::default(); + let mut call = self.hub.relyingparty().set_account_info(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "local-id" => { + request.local_id = Some(value.unwrap_or("").to_string()); + }, + "upgrade-to-federated-login" => { + request.upgrade_to_federated_login = Some(arg_from_str(value.unwrap_or("false"), err, "upgrade-to-federated-login", "boolean")); + }, + "captcha-response" => { + request.captcha_response = Some(value.unwrap_or("").to_string()); + }, + "id-token" => { + request.id_token = Some(value.unwrap_or("").to_string()); + }, + "provider" => { + if request.provider.is_none() { + request.provider = Some(Default::default()); + } + request.provider.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "captcha-challenge" => { + request.captcha_challenge = Some(value.unwrap_or("").to_string()); + }, + "email-verified" => { + request.email_verified = Some(arg_from_str(value.unwrap_or("false"), err, "email-verified", "boolean")); + }, + "oob-code" => { + request.oob_code = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_upload_account(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyUploadAccountRequest = Default::default(); + let mut call = self.hub.relyingparty().upload_account(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "salt-separator" => { + request.salt_separator = Some(value.unwrap_or("").to_string()); + }, + "hash-algorithm" => { + request.hash_algorithm = Some(value.unwrap_or("").to_string()); + }, + "memory-cost" => { + request.memory_cost = Some(arg_from_str(value.unwrap_or("-0"), err, "memory-cost", "integer")); + }, + "signer-key" => { + request.signer_key = Some(value.unwrap_or("").to_string()); + }, + "rounds" => { + request.rounds = Some(arg_from_str(value.unwrap_or("-0"), err, "rounds", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_verify_assertion(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyVerifyAssertionRequest = Default::default(); + let mut call = self.hub.relyingparty().verify_assertion(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "request-uri" => { + request.request_uri = Some(value.unwrap_or("").to_string()); + }, + "post-body" => { + request.post_body = Some(value.unwrap_or("").to_string()); + }, + "pending-id-token" => { + request.pending_id_token = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _relyingparty_verify_password(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::IdentitytoolkitRelyingpartyVerifyPasswordRequest = Default::default(); + let mut call = self.hub.relyingparty().verify_password(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "captcha-response" => { + request.captcha_response = Some(value.unwrap_or("").to_string()); + }, + "captcha-challenge" => { + request.captcha_challenge = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "email" => { + request.email = Some(value.unwrap_or("").to_string()); + }, + "pending-id-token" => { + request.pending_id_token = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_relyingparty { + if self.opt.cmd_create_auth_uri { + call_result = self._relyingparty_create_auth_uri(dry_run, &mut err); + } else if self.opt.cmd_delete_account { + call_result = self._relyingparty_delete_account(dry_run, &mut err); + } else if self.opt.cmd_download_account { + call_result = self._relyingparty_download_account(dry_run, &mut err); + } else if self.opt.cmd_get_account_info { + call_result = self._relyingparty_get_account_info(dry_run, &mut err); + } else if self.opt.cmd_get_oob_confirmation_code { + call_result = self._relyingparty_get_oob_confirmation_code(dry_run, &mut err); + } else if self.opt.cmd_get_public_keys { + call_result = self._relyingparty_get_public_keys(dry_run, &mut err); + } else if self.opt.cmd_reset_password { + call_result = self._relyingparty_reset_password(dry_run, &mut err); + } else if self.opt.cmd_set_account_info { + call_result = self._relyingparty_set_account_info(dry_run, &mut err); + } else if self.opt.cmd_upload_account { + call_result = self._relyingparty_upload_account(dry_run, &mut err); + } else if self.opt.cmd_verify_assertion { + call_result = self._relyingparty_verify_assertion(dry_run, &mut err); + } else if self.opt.cmd_verify_password { + call_result = self._relyingparty_verify_password(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "identitytoolkit3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "identitytoolkit3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::IdentityToolkit::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/licensing1-cli/Cargo.toml b/gen/licensing1-cli/Cargo.toml new file mode 100644 index 00000000000..4534749bcb2 --- /dev/null +++ b/gen/licensing1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-licensing1-cli" +version = "0.0.1+20140122" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with licensing (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/licensing1-cli" +homepage = "https://developers.google.com/google-apps/licensing/" +documentation = "http://byron.github.io/google-apis-rs/google_licensing1_cli" +license = "MIT" +keywords = ["licensing", "google", "cli"] + +[[bin]] +name = "licensing1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-licensing1] +path = "../licensing1" diff --git a/gen/licensing1-cli/LICENSE.md b/gen/licensing1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/licensing1-cli/LICENSE.md @@ -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. diff --git a/gen/licensing1-cli/README.md b/gen/licensing1-cli/README.md new file mode 100644 index 00000000000..151f81a0446 --- /dev/null +++ b/gen/licensing1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO LICENSING:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/licensing1-cli/mkdocs.yml b/gen/licensing1-cli/mkdocs.yml new file mode 100644 index 00000000000..f8359a9795f --- /dev/null +++ b/gen/licensing1-cli/mkdocs.yml @@ -0,0 +1,23 @@ +site_name: licensing v0.0.1+20140122 +site_url: http://byron.github.io/google-apis-rs/google-licensing1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/licensing1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['license-assignments_delete.md', 'License Assignments', 'Delete'] +- ['license-assignments_get.md', 'License Assignments', 'Get'] +- ['license-assignments_insert.md', 'License Assignments', 'Insert'] +- ['license-assignments_list-for-product.md', 'License Assignments', 'List For Product'] +- ['license-assignments_list-for-product-and-sku.md', 'License Assignments', 'List For Product And Sku'] +- ['license-assignments_patch.md', 'License Assignments', 'Patch'] +- ['license-assignments_update.md', 'License Assignments', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/licensing1-cli/src/cmn.rs b/gen/licensing1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/licensing1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/licensing1-cli/src/main.rs b/gen/licensing1-cli/src/main.rs new file mode 100644 index 00000000000..f354884e32b --- /dev/null +++ b/gen/licensing1-cli/src/main.rs @@ -0,0 +1,543 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_licensing1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + licensing1 [options] license-assignments delete <product-id> <sku-id> <user-id> [-p <v>]... + licensing1 [options] license-assignments get <product-id> <sku-id> <user-id> [-p <v>]... [-o <out>] + licensing1 [options] license-assignments insert <product-id> <sku-id> -r <kv>... [-p <v>]... [-o <out>] + licensing1 [options] license-assignments list-for-product <product-id> <customer-id> [-p <v>]... [-o <out>] + licensing1 [options] license-assignments list-for-product-and-sku <product-id> <sku-id> <customer-id> [-p <v>]... [-o <out>] + licensing1 [options] license-assignments patch <product-id> <sku-id> <user-id> -r <kv>... [-p <v>]... [-o <out>] + licensing1 [options] license-assignments update <product-id> <sku-id> <user-id> -r <kv>... [-p <v>]... [-o <out>] + licensing1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Licensing<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _license_assignments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.license_assignments().delete(&self.opt.arg_product_id, &self.opt.arg_sku_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _license_assignments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.license_assignments().get(&self.opt.arg_product_id, &self.opt.arg_sku_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _license_assignments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LicenseAssignmentInsert = Default::default(); + let mut call = self.hub.license_assignments().insert(&request, &self.opt.arg_product_id, &self.opt.arg_sku_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "user-id" => { + request.user_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _license_assignments_list_for_product(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.license_assignments().list_for_product(&self.opt.arg_product_id, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _license_assignments_list_for_product_and_sku(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.license_assignments().list_for_product_and_sku(&self.opt.arg_product_id, &self.opt.arg_sku_id, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _license_assignments_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LicenseAssignment = Default::default(); + let mut call = self.hub.license_assignments().patch(&request, &self.opt.arg_product_id, &self.opt.arg_sku_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "sku-id" => { + request.sku_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "user-id" => { + request.user_id = Some(value.unwrap_or("").to_string()); + }, + "etags" => { + request.etags = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _license_assignments_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LicenseAssignment = Default::default(); + let mut call = self.hub.license_assignments().update(&request, &self.opt.arg_product_id, &self.opt.arg_sku_id, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "sku-id" => { + request.sku_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "user-id" => { + request.user_id = Some(value.unwrap_or("").to_string()); + }, + "etags" => { + request.etags = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "product-id" => { + request.product_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_license_assignments { + if self.opt.cmd_delete { + call_result = self._license_assignments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._license_assignments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._license_assignments_insert(dry_run, &mut err); + } else if self.opt.cmd_list_for_product { + call_result = self._license_assignments_list_for_product(dry_run, &mut err); + } else if self.opt.cmd_list_for_product_and_sku { + call_result = self._license_assignments_list_for_product_and_sku(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._license_assignments_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._license_assignments_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "licensing1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "licensing1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Licensing::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/logging1_beta3-cli/Cargo.toml b/gen/logging1_beta3-cli/Cargo.toml new file mode 100644 index 00000000000..3d5235bee45 --- /dev/null +++ b/gen/logging1_beta3-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-logging1_beta3-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with logging (protocol v1beta3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/logging1_beta3-cli" +documentation = "http://byron.github.io/google-apis-rs/google_logging1_beta3_cli" +license = "MIT" +keywords = ["logging", "google", "cli"] + +[[bin]] +name = "logging1-beta3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-logging1_beta3] +path = "../logging1_beta3" diff --git a/gen/logging1_beta3-cli/LICENSE.md b/gen/logging1_beta3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/logging1_beta3-cli/LICENSE.md @@ -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. diff --git a/gen/logging1_beta3-cli/README.md b/gen/logging1_beta3-cli/README.md new file mode 100644 index 00000000000..205b79138c1 --- /dev/null +++ b/gen/logging1_beta3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO LOGGING:V1BETA3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/logging1_beta3-cli/mkdocs.yml b/gen/logging1_beta3-cli/mkdocs.yml new file mode 100644 index 00000000000..942f91e6daf --- /dev/null +++ b/gen/logging1_beta3-cli/mkdocs.yml @@ -0,0 +1,31 @@ +site_name: logging v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-logging1_beta3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/logging1_beta3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['projects_log-services-indexes-list.md', 'Projects', 'Log Services Indexes List'] +- ['projects_log-services-list.md', 'Projects', 'Log Services List'] +- ['projects_log-services-sinks-create.md', 'Projects', 'Log Services Sinks Create'] +- ['projects_log-services-sinks-delete.md', 'Projects', 'Log Services Sinks Delete'] +- ['projects_log-services-sinks-get.md', 'Projects', 'Log Services Sinks Get'] +- ['projects_log-services-sinks-list.md', 'Projects', 'Log Services Sinks List'] +- ['projects_log-services-sinks-update.md', 'Projects', 'Log Services Sinks Update'] +- ['projects_logs-delete.md', 'Projects', 'Logs Delete'] +- ['projects_logs-entries-write.md', 'Projects', 'Logs Entries Write'] +- ['projects_logs-list.md', 'Projects', 'Logs List'] +- ['projects_logs-sinks-create.md', 'Projects', 'Logs Sinks Create'] +- ['projects_logs-sinks-delete.md', 'Projects', 'Logs Sinks Delete'] +- ['projects_logs-sinks-get.md', 'Projects', 'Logs Sinks Get'] +- ['projects_logs-sinks-list.md', 'Projects', 'Logs Sinks List'] +- ['projects_logs-sinks-update.md', 'Projects', 'Logs Sinks Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/logging1_beta3-cli/src/cmn.rs b/gen/logging1_beta3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/logging1_beta3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/logging1_beta3-cli/src/main.rs b/gen/logging1_beta3-cli/src/main.rs new file mode 100644 index 00000000000..9e01ffde138 --- /dev/null +++ b/gen/logging1_beta3-cli/src/main.rs @@ -0,0 +1,1052 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_logging1_beta3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + logging1-beta3 [options] projects log-services-indexes-list <projects-id> <log-services-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-list <projects-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-create <projects-id> <log-services-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-delete <projects-id> <log-services-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-get <projects-id> <log-services-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-list <projects-id> <log-services-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects log-services-sinks-update <projects-id> <log-services-id> <sinks-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-delete <projects-id> <logs-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-entries-write <projects-id> <logs-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-list <projects-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-create <projects-id> <logs-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-delete <projects-id> <logs-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-get <projects-id> <logs-id> <sinks-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-list <projects-id> <logs-id> [-p <v>]... [-o <out>] + logging1-beta3 [options] projects logs-sinks-update <projects-id> <logs-id> <sinks-id> -r <kv>... [-p <v>]... [-o <out>] + logging1-beta3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Logging<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _projects_log_services_indexes_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_indexes_list(&self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "log" => { + call = call.log(value.unwrap_or("")); + }, + "index-prefix" => { + call = call.index_prefix(value.unwrap_or("")); + }, + "depth" => { + call = call.depth(arg_from_str(value.unwrap_or("-0"), err, "depth", "integer")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_list(&self.opt.arg_projects_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "log" => { + call = call.log(value.unwrap_or("")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LogSink = Default::default(); + let mut call = self.hub.projects().log_services_sinks_create(&request, &self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_delete(&self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_get(&self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().log_services_sinks_list(&self.opt.arg_projects_id, &self.opt.arg_log_services_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_log_services_sinks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LogSink = Default::default(); + let mut call = self.hub.projects().log_services_sinks_update(&request, &self.opt.arg_projects_id, &self.opt.arg_log_services_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_delete(&self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_entries_write(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::WriteLogEntriesRequest = Default::default(); + let mut call = self.hub.projects().logs_entries_write(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "common-labels" => { + if request.common_labels.is_none() { + request.common_labels = Some(Default::default()); + } + request.common_labels.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_list(&self.opt.arg_projects_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "service-name" => { + call = call.service_name(value.unwrap_or("")); + }, + "service-index-prefix" => { + call = call.service_index_prefix(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LogSink = Default::default(); + let mut call = self.hub.projects().logs_sinks_create(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_delete(&self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_get(&self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().logs_sinks_list(&self.opt.arg_projects_id, &self.opt.arg_logs_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_logs_sinks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LogSink = Default::default(); + let mut call = self.hub.projects().logs_sinks_update(&request, &self.opt.arg_projects_id, &self.opt.arg_logs_id, &self.opt.arg_sinks_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "$-xgafv" + |"access-token" + |"alt" + |"bearer-token" + |"callback" + |"fields" + |"key" + |"oauth-token" + |"pp" + |"pretty-print" + |"quota-user" => { + let map = [ + ("$-xgafv", "$.xgafv"), + ("access-token", "access_token"), + ("bearer-token", "bearer_token"), + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "destination" => { + request.destination = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_projects { + if self.opt.cmd_log_services_indexes_list { + call_result = self._projects_log_services_indexes_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_list { + call_result = self._projects_log_services_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_create { + call_result = self._projects_log_services_sinks_create(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_delete { + call_result = self._projects_log_services_sinks_delete(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_get { + call_result = self._projects_log_services_sinks_get(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_list { + call_result = self._projects_log_services_sinks_list(dry_run, &mut err); + } else if self.opt.cmd_log_services_sinks_update { + call_result = self._projects_log_services_sinks_update(dry_run, &mut err); + } else if self.opt.cmd_logs_delete { + call_result = self._projects_logs_delete(dry_run, &mut err); + } else if self.opt.cmd_logs_entries_write { + call_result = self._projects_logs_entries_write(dry_run, &mut err); + } else if self.opt.cmd_logs_list { + call_result = self._projects_logs_list(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_create { + call_result = self._projects_logs_sinks_create(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_delete { + call_result = self._projects_logs_sinks_delete(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_get { + call_result = self._projects_logs_sinks_get(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_list { + call_result = self._projects_logs_sinks_list(dry_run, &mut err); + } else if self.opt.cmd_logs_sinks_update { + call_result = self._projects_logs_sinks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "logging1-beta3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "logging1-beta3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Logging::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/manager1_beta2-cli/Cargo.toml b/gen/manager1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..4c437523de4 --- /dev/null +++ b/gen/manager1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-manager1_beta2-cli" +version = "0.0.1+20140915" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with manager (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/manager1_beta2-cli" +homepage = "https://developers.google.com/deployment-manager/" +documentation = "http://byron.github.io/google-apis-rs/google_manager1_beta2_cli" +license = "MIT" +keywords = ["manager", "google", "cli"] + +[[bin]] +name = "manager1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-manager1_beta2] +path = "../manager1_beta2" diff --git a/gen/manager1_beta2-cli/LICENSE.md b/gen/manager1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/manager1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/manager1_beta2-cli/README.md b/gen/manager1_beta2-cli/README.md new file mode 100644 index 00000000000..25434a8dd84 --- /dev/null +++ b/gen/manager1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO MANAGER:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/manager1_beta2-cli/mkdocs.yml b/gen/manager1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..d58d25a950d --- /dev/null +++ b/gen/manager1_beta2-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: manager v0.0.1+20140915 +site_url: http://byron.github.io/google-apis-rs/google-manager1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/manager1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['deployments_delete.md', 'Deployments', 'Delete'] +- ['deployments_get.md', 'Deployments', 'Get'] +- ['deployments_insert.md', 'Deployments', 'Insert'] +- ['deployments_list.md', 'Deployments', 'List'] +- ['templates_delete.md', 'Templates', 'Delete'] +- ['templates_get.md', 'Templates', 'Get'] +- ['templates_insert.md', 'Templates', 'Insert'] +- ['templates_list.md', 'Templates', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/manager1_beta2-cli/src/cmn.rs b/gen/manager1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/manager1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/manager1_beta2-cli/src/main.rs b/gen/manager1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..3eb3c6412cf --- /dev/null +++ b/gen/manager1_beta2-cli/src/main.rs @@ -0,0 +1,576 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_manager1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + manager1-beta2 [options] deployments delete <project-id> <region> <deployment-name> [-p <v>]... + manager1-beta2 [options] deployments get <project-id> <region> <deployment-name> [-p <v>]... [-o <out>] + manager1-beta2 [options] deployments insert <project-id> <region> -r <kv>... [-p <v>]... [-o <out>] + manager1-beta2 [options] deployments list <project-id> <region> [-p <v>]... [-o <out>] + manager1-beta2 [options] templates delete <project-id> <template-name> [-p <v>]... + manager1-beta2 [options] templates get <project-id> <template-name> [-p <v>]... [-o <out>] + manager1-beta2 [options] templates insert <project-id> -r <kv>... [-p <v>]... [-o <out>] + manager1-beta2 [options] templates list <project-id> [-p <v>]... [-o <out>] + manager1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Manager<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _deployments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().delete(&self.opt.arg_project_id, &self.opt.arg_region, &self.opt.arg_deployment_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _deployments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().get(&self.opt.arg_project_id, &self.opt.arg_region, &self.opt.arg_deployment_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _deployments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Deployment = Default::default(); + let mut call = self.hub.deployments().insert(&request, &self.opt.arg_project_id, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_state_init(request: &mut api::Deployment) { + if request.state.is_none() { + request.state = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "state.status" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "state.details" => { + request_state_init(&mut request); + request.state.as_mut().unwrap().details = value.unwrap_or("").to_string(); + }, + "creation-date" => { + request_state_init(&mut request); + request.creation_date = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_state_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_state_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "template-name" => { + request_state_init(&mut request); + request.template_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _deployments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.deployments().list(&self.opt.arg_project_id, &self.opt.arg_region); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _templates_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.templates().delete(&self.opt.arg_project_id, &self.opt.arg_template_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _templates_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.templates().get(&self.opt.arg_project_id, &self.opt.arg_template_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _templates_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Template = Default::default(); + let mut call = self.hub.templates().insert(&request, &self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _templates_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.templates().list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_deployments { + if self.opt.cmd_delete { + call_result = self._deployments_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._deployments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._deployments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._deployments_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_templates { + if self.opt.cmd_delete { + call_result = self._templates_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._templates_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._templates_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._templates_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "manager1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "manager1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Manager::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/mapsengine1-cli/Cargo.toml b/gen/mapsengine1-cli/Cargo.toml new file mode 100644 index 00000000000..46e3138e43c --- /dev/null +++ b/gen/mapsengine1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-mapsengine1-cli" +version = "0.0.1+20150225" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Maps Engine (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/mapsengine1-cli" +homepage = "https://developers.google.com/maps-engine/" +documentation = "http://byron.github.io/google-apis-rs/google_mapsengine1_cli" +license = "MIT" +keywords = ["mapsengine", "google", "cli"] + +[[bin]] +name = "mapsengine1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-mapsengine1] +path = "../mapsengine1" diff --git a/gen/mapsengine1-cli/LICENSE.md b/gen/mapsengine1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/mapsengine1-cli/LICENSE.md @@ -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. diff --git a/gen/mapsengine1-cli/README.md b/gen/mapsengine1-cli/README.md new file mode 100644 index 00000000000..05db3349910 --- /dev/null +++ b/gen/mapsengine1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO MAPSENGINE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/mapsengine1-cli/mkdocs.yml b/gen/mapsengine1-cli/mkdocs.yml new file mode 100644 index 00000000000..206f5871f5f --- /dev/null +++ b/gen/mapsengine1-cli/mkdocs.yml @@ -0,0 +1,93 @@ +site_name: Maps Engine v0.0.1+20150225 +site_url: http://byron.github.io/google-apis-rs/google-mapsengine1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/mapsengine1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['assets_get.md', 'Assets', 'Get'] +- ['assets_list.md', 'Assets', 'List'] +- ['assets_parents-list.md', 'Assets', 'Parents List'] +- ['assets_permissions-list.md', 'Assets', 'Permissions List'] +- ['layers_cancel-processing.md', 'Layers', 'Cancel Processing'] +- ['layers_create.md', 'Layers', 'Create'] +- ['layers_delete.md', 'Layers', 'Delete'] +- ['layers_get.md', 'Layers', 'Get'] +- ['layers_get-published.md', 'Layers', 'Get Published'] +- ['layers_list.md', 'Layers', 'List'] +- ['layers_list-published.md', 'Layers', 'List Published'] +- ['layers_parents-list.md', 'Layers', 'Parents List'] +- ['layers_patch.md', 'Layers', 'Patch'] +- ['layers_permissions-batch-delete.md', 'Layers', 'Permissions Batch Delete'] +- ['layers_permissions-batch-update.md', 'Layers', 'Permissions Batch Update'] +- ['layers_permissions-list.md', 'Layers', 'Permissions List'] +- ['layers_process.md', 'Layers', 'Process'] +- ['layers_publish.md', 'Layers', 'Publish'] +- ['layers_unpublish.md', 'Layers', 'Unpublish'] +- ['maps_create.md', 'Maps', 'Create'] +- ['maps_delete.md', 'Maps', 'Delete'] +- ['maps_get.md', 'Maps', 'Get'] +- ['maps_get-published.md', 'Maps', 'Get Published'] +- ['maps_list.md', 'Maps', 'List'] +- ['maps_list-published.md', 'Maps', 'List Published'] +- ['maps_patch.md', 'Maps', 'Patch'] +- ['maps_permissions-batch-delete.md', 'Maps', 'Permissions Batch Delete'] +- ['maps_permissions-batch-update.md', 'Maps', 'Permissions Batch Update'] +- ['maps_permissions-list.md', 'Maps', 'Permissions List'] +- ['maps_publish.md', 'Maps', 'Publish'] +- ['maps_unpublish.md', 'Maps', 'Unpublish'] +- ['projects_icons-create.md', 'Projects', 'Icons Create'] +- ['projects_icons-get.md', 'Projects', 'Icons Get'] +- ['projects_icons-list.md', 'Projects', 'Icons List'] +- ['projects_list.md', 'Projects', 'List'] +- ['raster-collections_cancel-processing.md', 'Raster Collections', 'Cancel Processing'] +- ['raster-collections_create.md', 'Raster Collections', 'Create'] +- ['raster-collections_delete.md', 'Raster Collections', 'Delete'] +- ['raster-collections_get.md', 'Raster Collections', 'Get'] +- ['raster-collections_list.md', 'Raster Collections', 'List'] +- ['raster-collections_parents-list.md', 'Raster Collections', 'Parents List'] +- ['raster-collections_patch.md', 'Raster Collections', 'Patch'] +- ['raster-collections_permissions-batch-delete.md', 'Raster Collections', 'Permissions Batch Delete'] +- ['raster-collections_permissions-batch-update.md', 'Raster Collections', 'Permissions Batch Update'] +- ['raster-collections_permissions-list.md', 'Raster Collections', 'Permissions List'] +- ['raster-collections_process.md', 'Raster Collections', 'Process'] +- ['raster-collections_rasters-batch-delete.md', 'Raster Collections', 'Rasters Batch Delete'] +- ['raster-collections_rasters-batch-insert.md', 'Raster Collections', 'Rasters Batch Insert'] +- ['raster-collections_rasters-list.md', 'Raster Collections', 'Rasters List'] +- ['rasters_delete.md', 'Rasters', 'Delete'] +- ['rasters_files-insert.md', 'Rasters', 'Files Insert'] +- ['rasters_get.md', 'Rasters', 'Get'] +- ['rasters_list.md', 'Rasters', 'List'] +- ['rasters_parents-list.md', 'Rasters', 'Parents List'] +- ['rasters_patch.md', 'Rasters', 'Patch'] +- ['rasters_permissions-batch-delete.md', 'Rasters', 'Permissions Batch Delete'] +- ['rasters_permissions-batch-update.md', 'Rasters', 'Permissions Batch Update'] +- ['rasters_permissions-list.md', 'Rasters', 'Permissions List'] +- ['rasters_process.md', 'Rasters', 'Process'] +- ['rasters_upload.md', 'Rasters', 'Upload'] +- ['tables_create.md', 'Tables', 'Create'] +- ['tables_delete.md', 'Tables', 'Delete'] +- ['tables_features-batch-delete.md', 'Tables', 'Features Batch Delete'] +- ['tables_features-batch-insert.md', 'Tables', 'Features Batch Insert'] +- ['tables_features-batch-patch.md', 'Tables', 'Features Batch Patch'] +- ['tables_features-get.md', 'Tables', 'Features Get'] +- ['tables_features-list.md', 'Tables', 'Features List'] +- ['tables_files-insert.md', 'Tables', 'Files Insert'] +- ['tables_get.md', 'Tables', 'Get'] +- ['tables_list.md', 'Tables', 'List'] +- ['tables_parents-list.md', 'Tables', 'Parents List'] +- ['tables_patch.md', 'Tables', 'Patch'] +- ['tables_permissions-batch-delete.md', 'Tables', 'Permissions Batch Delete'] +- ['tables_permissions-batch-update.md', 'Tables', 'Permissions Batch Update'] +- ['tables_permissions-list.md', 'Tables', 'Permissions List'] +- ['tables_process.md', 'Tables', 'Process'] +- ['tables_upload.md', 'Tables', 'Upload'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/mapsengine1-cli/src/cmn.rs b/gen/mapsengine1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/mapsengine1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/mapsengine1-cli/src/main.rs b/gen/mapsengine1-cli/src/main.rs new file mode 100644 index 00000000000..882ff7e4b82 --- /dev/null +++ b/gen/mapsengine1-cli/src/main.rs @@ -0,0 +1,5347 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_mapsengine1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + mapsengine1 [options] assets get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] assets list [-p <v>]... [-o <out>] + mapsengine1 [options] assets parents-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] assets permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers cancel-processing <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers create -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] layers delete <id> [-p <v>]... + mapsengine1 [options] layers get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers get-published <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers list [-p <v>]... [-o <out>] + mapsengine1 [options] layers list-published [-p <v>]... [-o <out>] + mapsengine1 [options] layers parents-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] layers permissions-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] layers permissions-batch-update <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] layers permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers process <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers publish <id> [-p <v>]... [-o <out>] + mapsengine1 [options] layers unpublish <id> [-p <v>]... [-o <out>] + mapsengine1 [options] maps create -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] maps delete <id> [-p <v>]... + mapsengine1 [options] maps get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] maps get-published <id> [-p <v>]... [-o <out>] + mapsengine1 [options] maps list [-p <v>]... [-o <out>] + mapsengine1 [options] maps list-published [-p <v>]... [-o <out>] + mapsengine1 [options] maps patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] maps permissions-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] maps permissions-batch-update <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] maps permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] maps publish <id> [-p <v>]... [-o <out>] + mapsengine1 [options] maps unpublish <id> [-p <v>]... [-o <out>] + mapsengine1 [options] projects icons-create <project-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + mapsengine1 [options] projects icons-get <project-id> <id> [-p <v>]... [-o <out>] + mapsengine1 [options] projects icons-list <project-id> [-p <v>]... [-o <out>] + mapsengine1 [options] projects list [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections cancel-processing <id> [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections create -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections delete <id> [-p <v>]... + mapsengine1 [options] raster-collections get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections list [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections parents-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] raster-collections permissions-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections permissions-batch-update <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections process <id> [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections rasters-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections rasters-batch-insert <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] raster-collections rasters-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters delete <id> [-p <v>]... + mapsengine1 [options] rasters files-insert <id> <filename> -u (simple|resumable) <file> <mime> [-p <v>]... + mapsengine1 [options] rasters get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters list <project-id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters parents-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] rasters permissions-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] rasters permissions-batch-update <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] rasters permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters process <id> [-p <v>]... [-o <out>] + mapsengine1 [options] rasters upload -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] tables create -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] tables delete <id> [-p <v>]... + mapsengine1 [options] tables features-batch-delete <id> -r <kv>... [-p <v>]... + mapsengine1 [options] tables features-batch-insert <id> -r <kv>... [-p <v>]... + mapsengine1 [options] tables features-batch-patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] tables features-get <table-id> <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables features-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables files-insert <id> <filename> -u (simple|resumable) <file> <mime> [-p <v>]... + mapsengine1 [options] tables get <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables list [-p <v>]... [-o <out>] + mapsengine1 [options] tables parents-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables patch <id> -r <kv>... [-p <v>]... + mapsengine1 [options] tables permissions-batch-delete <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] tables permissions-batch-update <id> -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 [options] tables permissions-list <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables process <id> [-p <v>]... [-o <out>] + mapsengine1 [options] tables upload -r <kv>... [-p <v>]... [-o <out>] + mapsengine1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::MapsEngine<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _assets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.assets().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _assets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.assets().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _assets_parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.assets().parents_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _assets_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.assets().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_cancel_processing(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().cancel_processing(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Layer = Default::default(); + let mut call = self.hub.layers().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "process" => { + call = call.process(arg_from_str(value.unwrap_or("false"), err, "process", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_style_init(request: &mut api::Layer) { + if request.style.is_none() { + request.style = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "style.feature-info.content" => { + request_style_init(&mut request); + request.style.as_mut().unwrap().feature_info.content = value.unwrap_or("").to_string(); + }, + "style.type" => { + request_style_init(&mut request); + request.style.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "description" => { + request_style_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_style_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_style_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "datasource-type" => { + request_style_init(&mut request); + request.datasource_type = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_style_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "publishing-status" => { + request_style_init(&mut request); + request.publishing_status = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_style_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request_style_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_style_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_style_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "layer-type" => { + request_style_init(&mut request); + request.layer_type = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_style_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifier-email" => { + request_style_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_style_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request_style_init(&mut request); + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_style_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_style_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _layers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "version" => { + call = call.version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_get_published(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().get_published(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "processing-status" => { + call = call.processing_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_list_published(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().list_published(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().parents_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Layer = Default::default(); + let mut call = self.hub.layers().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_style_init(request: &mut api::Layer) { + if request.style.is_none() { + request.style = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "style.feature-info.content" => { + request_style_init(&mut request); + request.style.as_mut().unwrap().feature_info.content = value.unwrap_or("").to_string(); + }, + "style.type" => { + request_style_init(&mut request); + request.style.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "description" => { + request_style_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_style_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_style_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "datasource-type" => { + request_style_init(&mut request); + request.datasource_type = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_style_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "publishing-status" => { + request_style_init(&mut request); + request.publishing_status = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_style_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request_style_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_style_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_style_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "layer-type" => { + request_style_init(&mut request); + request.layer_type = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_style_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "last-modifier-email" => { + request_style_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_style_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request_style_init(&mut request); + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_style_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_style_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _layers_permissions_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchDeleteRequest = Default::default(); + let mut call = self.hub.layers().permissions_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_permissions_batch_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchUpdateRequest = Default::default(); + let mut call = self.hub.layers().permissions_batch_update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_process(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().process(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().publish(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "force" => { + call = call.force(arg_from_str(value.unwrap_or("false"), err, "force", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _layers_unpublish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.layers().unpublish(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Map = Default::default(); + let mut call = self.hub.maps().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "versions" => { + if request.versions.is_none() { + request.versions = Some(Default::default()); + } + request.versions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "publishing-status" => { + request.publishing_status = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _maps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "version" => { + call = call.version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_get_published(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().get_published(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "processing-status" => { + call = call.processing_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_list_published(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().list_published(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Map = Default::default(); + let mut call = self.hub.maps().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "versions" => { + if request.versions.is_none() { + request.versions = Some(Default::default()); + } + request.versions.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "publishing-status" => { + request.publishing_status = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _maps_permissions_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchDeleteRequest = Default::default(); + let mut call = self.hub.maps().permissions_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_permissions_batch_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchUpdateRequest = Default::default(); + let mut call = self.hub.maps().permissions_batch_update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().publish(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "force" => { + call = call.force(arg_from_str(value.unwrap_or("false"), err, "force", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _maps_unpublish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.maps().unpublish(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_icons_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Icon = Default::default(); + let mut call = self.hub.projects().icons_create(&request, &self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_icons_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.projects().icons_get(&self.opt.arg_project_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _projects_icons_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().icons_list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_cancel_processing(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().cancel_processing(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RasterCollection = Default::default(); + let mut call = self.hub.raster_collections().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "attribution" => { + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "raster-type" => { + request.raster_type = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "mosaic" => { + request.mosaic = Some(arg_from_str(value.unwrap_or("false"), err, "mosaic", "boolean")); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _raster_collections_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "processing-status" => { + call = call.processing_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().parents_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RasterCollection = Default::default(); + let mut call = self.hub.raster_collections().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "attribution" => { + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "raster-type" => { + request.raster_type = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "mosaic" => { + request.mosaic = Some(arg_from_str(value.unwrap_or("false"), err, "mosaic", "boolean")); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _raster_collections_permissions_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchDeleteRequest = Default::default(); + let mut call = self.hub.raster_collections().permissions_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_permissions_batch_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchUpdateRequest = Default::default(); + let mut call = self.hub.raster_collections().permissions_batch_update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_process(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().process(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_rasters_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RasterCollectionsRasterBatchDeleteRequest = Default::default(); + let mut call = self.hub.raster_collections().rasters_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_rasters_batch_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RasterCollectionsRastersBatchInsertRequest = Default::default(); + let mut call = self.hub.raster_collections().rasters_batch_insert(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _raster_collections_rasters_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.raster_collections().rasters_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rasters_files_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().files_insert(&self.opt.arg_id, &self.opt.arg_filename); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rasters_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().list(&self.opt.arg_project_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "processing-status" => { + call = call.processing_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().parents_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Raster = Default::default(); + let mut call = self.hub.rasters().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_acquisition_time_init(request: &mut api::Raster) { + if request.acquisition_time.is_none() { + request.acquisition_time = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "acquisition-time.start" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "acquisition-time.end" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "acquisition-time.precision" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().precision = value.unwrap_or("").to_string(); + }, + "attribution" => { + request_acquisition_time_init(&mut request); + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_acquisition_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_acquisition_time_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_acquisition_time_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_acquisition_time_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_acquisition_time_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_acquisition_time_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "mask-type" => { + request_acquisition_time_init(&mut request); + request.mask_type = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_acquisition_time_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_acquisition_time_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_acquisition_time_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request_acquisition_time_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_acquisition_time_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_acquisition_time_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "raster-type" => { + request_acquisition_time_init(&mut request); + request.raster_type = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_acquisition_time_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _rasters_permissions_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchDeleteRequest = Default::default(); + let mut call = self.hub.rasters().permissions_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_permissions_batch_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchUpdateRequest = Default::default(); + let mut call = self.hub.rasters().permissions_batch_update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_process(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rasters().process(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rasters_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Raster = Default::default(); + let mut call = self.hub.rasters().upload(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_acquisition_time_init(request: &mut api::Raster) { + if request.acquisition_time.is_none() { + request.acquisition_time = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "acquisition-time.start" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().start = value.unwrap_or("").to_string(); + }, + "acquisition-time.end" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().end = value.unwrap_or("").to_string(); + }, + "acquisition-time.precision" => { + request_acquisition_time_init(&mut request); + request.acquisition_time.as_mut().unwrap().precision = value.unwrap_or("").to_string(); + }, + "attribution" => { + request_acquisition_time_init(&mut request); + request.attribution = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request_acquisition_time_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_acquisition_time_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_acquisition_time_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_acquisition_time_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_acquisition_time_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_acquisition_time_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "mask-type" => { + request_acquisition_time_init(&mut request); + request.mask_type = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_acquisition_time_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_acquisition_time_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_acquisition_time_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request_acquisition_time_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_acquisition_time_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_acquisition_time_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "raster-type" => { + request_acquisition_time_init(&mut request); + request.raster_type = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_acquisition_time_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().create(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_schema_init(request: &mut api::Table) { + if request.schema.is_none() { + request.schema = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schema.primary-geometry" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_geometry = value.unwrap_or("").to_string(); + }, + "schema.primary-key" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_key = value.unwrap_or("").to_string(); + }, + "description" => { + request_schema_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_schema_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_schema_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_schema_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_schema_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "source-encoding" => { + request_schema_init(&mut request); + request.source_encoding = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_schema_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request_schema_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_schema_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_schema_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request_schema_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_schema_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request_schema_init(&mut request); + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_schema_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_schema_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_features_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FeaturesBatchDeleteRequest = Default::default(); + let mut call = self.hub.tables().features_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "gx-ids" => { + if request.gx_ids.is_none() { + request.gx_ids = Some(Default::default()); + } + request.gx_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "primary-keys" => { + if request.primary_keys.is_none() { + request.primary_keys = Some(Default::default()); + } + request.primary_keys.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_features_batch_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FeaturesBatchInsertRequest = Default::default(); + let mut call = self.hub.tables().features_batch_insert(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "normalize-geometries" => { + request.normalize_geometries = Some(arg_from_str(value.unwrap_or("false"), err, "normalize-geometries", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_features_batch_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::FeaturesBatchPatchRequest = Default::default(); + let mut call = self.hub.tables().features_batch_patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "normalize-geometries" => { + request.normalize_geometries = Some(arg_from_str(value.unwrap_or("false"), err, "normalize-geometries", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_features_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().features_get(&self.opt.arg_table_id, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "version" => { + call = call.version(value.unwrap_or("")); + }, + "select" => { + call = call.select(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_features_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().features_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "where" => { + call = call.where_(value.unwrap_or("")); + }, + "version" => { + call = call.version(value.unwrap_or("")); + }, + "select" => { + call = call.select(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "limit" => { + call = call.limit(arg_from_str(value.unwrap_or("-0"), err, "limit", "integer")); + }, + "intersects" => { + call = call.intersects(value.unwrap_or("")); + }, + "include" => { + call = call.include(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_files_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().files_insert(&self.opt.arg_id, &self.opt.arg_filename); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "version" => { + call = call.version(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tags" => { + call = call.tags(value.unwrap_or("")); + }, + "search" => { + call = call.search(value.unwrap_or("")); + }, + "role" => { + call = call.role(value.unwrap_or("")); + }, + "project-id" => { + call = call.project_id(value.unwrap_or("")); + }, + "processing-status" => { + call = call.processing_status(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "modified-before" => { + call = call.modified_before(value.unwrap_or("")); + }, + "modified-after" => { + call = call.modified_after(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "creator-email" => { + call = call.creator_email(value.unwrap_or("")); + }, + "created-before" => { + call = call.created_before(value.unwrap_or("")); + }, + "created-after" => { + call = call.created_after(value.unwrap_or("")); + }, + "bbox" => { + call = call.bbox(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_parents_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().parents_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_schema_init(request: &mut api::Table) { + if request.schema.is_none() { + request.schema = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schema.primary-geometry" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_geometry = value.unwrap_or("").to_string(); + }, + "schema.primary-key" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_key = value.unwrap_or("").to_string(); + }, + "description" => { + request_schema_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_schema_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_schema_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_schema_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_schema_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "source-encoding" => { + request_schema_init(&mut request); + request.source_encoding = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_schema_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request_schema_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_schema_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_schema_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request_schema_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_schema_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request_schema_init(&mut request); + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_schema_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_schema_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tables_permissions_batch_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchDeleteRequest = Default::default(); + let mut call = self.hub.tables().permissions_batch_delete(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ids" => { + if request.ids.is_none() { + request.ids = Some(Default::default()); + } + request.ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_permissions_batch_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PermissionsBatchUpdateRequest = Default::default(); + let mut call = self.hub.tables().permissions_batch_update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().permissions_list(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_process(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tables().process(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tables_upload(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Table = Default::default(); + let mut call = self.hub.tables().upload(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_schema_init(request: &mut api::Table) { + if request.schema.is_none() { + request.schema = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schema.primary-geometry" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_geometry = value.unwrap_or("").to_string(); + }, + "schema.primary-key" => { + request_schema_init(&mut request); + request.schema.as_mut().unwrap().primary_key = value.unwrap_or("").to_string(); + }, + "description" => { + request_schema_init(&mut request); + request.description = Some(value.unwrap_or("").to_string()); + }, + "processing-status" => { + request_schema_init(&mut request); + request.processing_status = Some(value.unwrap_or("").to_string()); + }, + "draft-access-list" => { + request_schema_init(&mut request); + request.draft_access_list = Some(value.unwrap_or("").to_string()); + }, + "project-id" => { + request_schema_init(&mut request); + request.project_id = Some(value.unwrap_or("").to_string()); + }, + "creation-time" => { + request_schema_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "source-encoding" => { + request_schema_init(&mut request); + request.source_encoding = Some(value.unwrap_or("").to_string()); + }, + "writers-can-edit-permissions" => { + request_schema_init(&mut request); + request.writers_can_edit_permissions = Some(arg_from_str(value.unwrap_or("false"), err, "writers-can-edit-permissions", "boolean")); + }, + "etag" => { + request_schema_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "creator-email" => { + request_schema_init(&mut request); + request.creator_email = Some(value.unwrap_or("").to_string()); + }, + "bbox" => { + request_schema_init(&mut request); + if request.bbox.is_none() { + request.bbox = Some(Default::default()); + } + request.bbox.as_mut().unwrap().push(arg_from_str(value.unwrap_or("0.0"), err, "bbox", "number")); + }, + "last-modifier-email" => { + request_schema_init(&mut request); + request.last_modifier_email = Some(value.unwrap_or("").to_string()); + }, + "last-modified-time" => { + request_schema_init(&mut request); + request.last_modified_time = Some(value.unwrap_or("").to_string()); + }, + "published-access-list" => { + request_schema_init(&mut request); + request.published_access_list = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_schema_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_schema_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_assets { + if self.opt.cmd_get { + call_result = self._assets_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._assets_list(dry_run, &mut err); + } else if self.opt.cmd_parents_list { + call_result = self._assets_parents_list(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._assets_permissions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_layers { + if self.opt.cmd_cancel_processing { + call_result = self._layers_cancel_processing(dry_run, &mut err); + } else if self.opt.cmd_create { + call_result = self._layers_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._layers_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._layers_get(dry_run, &mut err); + } else if self.opt.cmd_get_published { + call_result = self._layers_get_published(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._layers_list(dry_run, &mut err); + } else if self.opt.cmd_list_published { + call_result = self._layers_list_published(dry_run, &mut err); + } else if self.opt.cmd_parents_list { + call_result = self._layers_parents_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._layers_patch(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_delete { + call_result = self._layers_permissions_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_update { + call_result = self._layers_permissions_batch_update(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._layers_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_process { + call_result = self._layers_process(dry_run, &mut err); + } else if self.opt.cmd_publish { + call_result = self._layers_publish(dry_run, &mut err); + } else if self.opt.cmd_unpublish { + call_result = self._layers_unpublish(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_maps { + if self.opt.cmd_create { + call_result = self._maps_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._maps_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._maps_get(dry_run, &mut err); + } else if self.opt.cmd_get_published { + call_result = self._maps_get_published(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._maps_list(dry_run, &mut err); + } else if self.opt.cmd_list_published { + call_result = self._maps_list_published(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._maps_patch(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_delete { + call_result = self._maps_permissions_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_update { + call_result = self._maps_permissions_batch_update(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._maps_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_publish { + call_result = self._maps_publish(dry_run, &mut err); + } else if self.opt.cmd_unpublish { + call_result = self._maps_unpublish(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_projects { + if self.opt.cmd_icons_create { + call_result = self._projects_icons_create(dry_run, &mut err); + } else if self.opt.cmd_icons_get { + call_result = self._projects_icons_get(dry_run, &mut err); + } else if self.opt.cmd_icons_list { + call_result = self._projects_icons_list(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._projects_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_raster_collections { + if self.opt.cmd_cancel_processing { + call_result = self._raster_collections_cancel_processing(dry_run, &mut err); + } else if self.opt.cmd_create { + call_result = self._raster_collections_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._raster_collections_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._raster_collections_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._raster_collections_list(dry_run, &mut err); + } else if self.opt.cmd_parents_list { + call_result = self._raster_collections_parents_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._raster_collections_patch(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_delete { + call_result = self._raster_collections_permissions_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_update { + call_result = self._raster_collections_permissions_batch_update(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._raster_collections_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_process { + call_result = self._raster_collections_process(dry_run, &mut err); + } else if self.opt.cmd_rasters_batch_delete { + call_result = self._raster_collections_rasters_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_rasters_batch_insert { + call_result = self._raster_collections_rasters_batch_insert(dry_run, &mut err); + } else if self.opt.cmd_rasters_list { + call_result = self._raster_collections_rasters_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_rasters { + if self.opt.cmd_delete { + call_result = self._rasters_delete(dry_run, &mut err); + } else if self.opt.cmd_files_insert { + call_result = self._rasters_files_insert(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._rasters_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._rasters_list(dry_run, &mut err); + } else if self.opt.cmd_parents_list { + call_result = self._rasters_parents_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._rasters_patch(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_delete { + call_result = self._rasters_permissions_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_update { + call_result = self._rasters_permissions_batch_update(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._rasters_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_process { + call_result = self._rasters_process(dry_run, &mut err); + } else if self.opt.cmd_upload { + call_result = self._rasters_upload(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tables { + if self.opt.cmd_create { + call_result = self._tables_create(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._tables_delete(dry_run, &mut err); + } else if self.opt.cmd_features_batch_delete { + call_result = self._tables_features_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_features_batch_insert { + call_result = self._tables_features_batch_insert(dry_run, &mut err); + } else if self.opt.cmd_features_batch_patch { + call_result = self._tables_features_batch_patch(dry_run, &mut err); + } else if self.opt.cmd_features_get { + call_result = self._tables_features_get(dry_run, &mut err); + } else if self.opt.cmd_features_list { + call_result = self._tables_features_list(dry_run, &mut err); + } else if self.opt.cmd_files_insert { + call_result = self._tables_files_insert(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tables_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tables_list(dry_run, &mut err); + } else if self.opt.cmd_parents_list { + call_result = self._tables_parents_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tables_patch(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_delete { + call_result = self._tables_permissions_batch_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_batch_update { + call_result = self._tables_permissions_batch_update(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._tables_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_process { + call_result = self._tables_process(dry_run, &mut err); + } else if self.opt.cmd_upload { + call_result = self._tables_upload(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "mapsengine1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "mapsengine1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::MapsEngine::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/mapsengine1/README.md b/gen/mapsengine1/README.md index 41a6ca0f6c1..e0c014be147 100644 --- a/gen/mapsengine1/README.md +++ b/gen/mapsengine1/README.md @@ -148,16 +148,18 @@ let result = hub.tables().list() match result { Err(e) => match e { - Error::HttpError(err) => println!("HTTPERROR: {:?}", err), - Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), - Error::MissingToken => println!("OAuth2: Missing Token"), - Error::Cancelled => println!("Operation canceled by user"), - Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), - Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), - Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), - Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), + // The Error enum provides details about what exactly happened. + // You can also just use its `Debug`, `Display` or `Error` traits + Error::HttpError(_) + |Error::MissingAPIKey + |Error::MissingToken + |Error::Cancelled + |Error::UploadSizeLimitExceeded(_, _) + |Error::Failure(_) + |Error::FieldClash(_) + |Error::JsonDecodeError(_) => println!("{}", e), }, - Ok(_) => println!("Success (value doesn't print)"), + Ok(res) => println!("Success: {:?}", res), } ``` diff --git a/gen/mapsengine1/src/cmn.rs b/gen/mapsengine1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/mapsengine1/src/cmn.rs +++ b/gen/mapsengine1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/mapsengine1/src/lib.rs b/gen/mapsengine1/src/lib.rs index dd74f5dd9fc..8d921b8a90e 100644 --- a/gen/mapsengine1/src/lib.rs +++ b/gen/mapsengine1/src/lib.rs @@ -149,16 +149,18 @@ //! //! match result { //! Err(e) => match e { -//! Error::HttpError(err) => println!("HTTPERROR: {:?}", err), -//! Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), -//! Error::MissingToken => println!("OAuth2: Missing Token"), -//! Error::Cancelled => println!("Operation canceled by user"), -//! Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), -//! Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), -//! Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), -//! Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +//! // The Error enum provides details about what exactly happened. +//! // You can also just use its `Debug`, `Display` or `Error` traits +//! Error::HttpError(_) +//! |Error::MissingAPIKey +//! |Error::MissingToken +//! |Error::Cancelled +//! |Error::UploadSizeLimitExceeded(_, _) +//! |Error::Failure(_) +//! |Error::FieldClash(_) +//! |Error::JsonDecodeError(_) => println!("{}", e), //! }, -//! Ok(_) => println!("Success (value doesn't print)"), +//! Ok(res) => println!("Success: {:?}", res), //! } //! # } //! ``` @@ -333,16 +335,18 @@ impl Default for Scope { /// /// match result { /// Err(e) => match e { -/// Error::HttpError(err) => println!("HTTPERROR: {:?}", err), -/// Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), -/// Error::MissingToken => println!("OAuth2: Missing Token"), -/// Error::Cancelled => println!("Operation canceled by user"), -/// Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), -/// Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), -/// Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), -/// Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +/// // The Error enum provides details about what exactly happened. +/// // You can also just use its `Debug`, `Display` or `Error` traits +/// Error::HttpError(_) +/// |Error::MissingAPIKey +/// |Error::MissingToken +/// |Error::Cancelled +/// |Error::UploadSizeLimitExceeded(_, _) +/// |Error::Failure(_) +/// |Error::FieldClash(_) +/// |Error::JsonDecodeError(_) => println!("{}", e), /// }, -/// Ok(_) => println!("Success (value doesn't print)"), +/// Ok(res) => println!("Success: {:?}", res), /// } /// # } /// ``` @@ -406,7 +410,7 @@ impl<'a, C, A> MapsEngine<C, A> /// /// This type is not used in any activity, and only used as *part* of another schema. /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RasterCollectionsRaster { /// The description of this Raster, supplied by the author. pub description: String, @@ -515,7 +519,7 @@ impl RequestValue for RasterCollectionsRasterBatchDeleteRequest {} /// * [permissions list assets](struct.AssetPermissionListCall.html) (none) /// * [get assets](struct.AssetGetCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Asset { /// The URL to query to retrieve the asset's complete object. The assets endpoint only returns high-level information about a resource. pub resource: String, @@ -567,7 +571,7 @@ impl ResponseResult for Asset {} /// /// * [list raster collections](struct.RasterCollectionListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RasterCollectionsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -616,7 +620,7 @@ impl Part for GeoJsonMultiLineString {} /// /// This type is not used in any activity, and only used as *part* of another schema. /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Parent { /// The ID of this parent. pub id: String, @@ -634,7 +638,7 @@ impl Part for Parent {} /// /// * [rasters batch delete raster collections](struct.RasterCollectionRasterBatchDeleteCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RasterCollectionsRastersBatchDeleteResponse; impl ResponseResult for RasterCollectionsRastersBatchDeleteResponse {} @@ -665,7 +669,7 @@ impl Part for TableColumn {} /// /// * [list projects](struct.ProjectListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ProjectsListResponse { /// Projects returned. pub projects: Vec<Project>, @@ -683,7 +687,7 @@ impl ResponseResult for ProjectsListResponse {} /// /// * [features list tables](struct.TableFeatureListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct FeaturesListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -716,7 +720,7 @@ impl ResponseResult for FeaturesListResponse {} /// * [permissions batch update tables](struct.TablePermissionBatchUpdateCall.html) (response) /// * [permissions batch update maps](struct.MapPermissionBatchUpdateCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PermissionsBatchUpdateResponse; impl ResponseResult for PermissionsBatchUpdateResponse {} @@ -752,7 +756,7 @@ impl RequestValue for FeaturesBatchInsertRequest {} /// /// * [list rasters](struct.RasterListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RastersListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -940,7 +944,7 @@ impl Part for GeoJsonMultiPolygon {} /// * [permissions list maps](struct.MapPermissionListCall.html) (response) /// * [permissions list tables](struct.TablePermissionListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PermissionsListResponse { /// The set of permissions associated with this asset. pub permissions: Vec<Permission>, @@ -1173,7 +1177,7 @@ impl Part for GeoJsonPosition {} /// /// * [list layers](struct.LayerListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct LayersListResponse { /// Resources returned. pub layers: Vec<Layer>, @@ -1322,7 +1326,7 @@ impl ResponseResult for Layer {} /// * [parents list layers](struct.LayerParentListCall.html) (response) /// * [parents list tables](struct.TableParentListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ParentsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -1363,7 +1367,7 @@ impl Part for VectorStyle {} /// /// * [rasters list raster collections](struct.RasterCollectionRasterListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RasterCollectionsRastersListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -1387,7 +1391,7 @@ impl ResponseResult for RasterCollectionsRastersListResponse {} /// * [unpublish layers](struct.LayerUnpublishCall.html) (response) /// * [publish layers](struct.LayerPublishCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PublishResponse; impl ResponseResult for PublishResponse {} @@ -1402,7 +1406,7 @@ impl ResponseResult for PublishResponse {} /// /// * [list assets](struct.AssetListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct AssetsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -1427,7 +1431,7 @@ impl ResponseResult for AssetsListResponse {} /// * [permissions batch delete layers](struct.LayerPermissionBatchDeleteCall.html) (response) /// * [permissions batch delete maps](struct.MapPermissionBatchDeleteCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PermissionsBatchDeleteResponse; impl ResponseResult for PermissionsBatchDeleteResponse {} @@ -1466,7 +1470,7 @@ impl ResponseResult for Icon {} /// /// * [rasters batch insert raster collections](struct.RasterCollectionRasterBatchInsertCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct RasterCollectionsRastersBatchInsertResponse; impl ResponseResult for RasterCollectionsRastersBatchInsertResponse {} @@ -1532,7 +1536,7 @@ impl RequestValue for PermissionsBatchDeleteRequest {} /// * [cancel processing raster collections](struct.RasterCollectionCancelProcessingCall.html) (response) /// * [process layers](struct.LayerProcesCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ProcessResponse; impl ResponseResult for ProcessResponse {} @@ -1547,7 +1551,7 @@ impl ResponseResult for ProcessResponse {} /// /// * [get published maps](struct.MapGetPublishedCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PublishedMap { /// The description of this Map, supplied by the author. pub description: String, @@ -1577,7 +1581,7 @@ impl ResponseResult for PublishedMap {} /// /// * [get published layers](struct.LayerGetPublishedCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PublishedLayer { /// The ID of the project that this Layer is in. #[serde(rename="projectId")] @@ -1816,7 +1820,7 @@ impl Part for ZoomLevels {} /// /// * [icons list projects](struct.ProjectIconListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct IconsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -1956,7 +1960,7 @@ impl Part for SizeRange {} /// /// * [list tables](struct.TableListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct TablesListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -1998,7 +2002,7 @@ impl Part for LineStyleStroke {} /// * [icons create projects](struct.ProjectIconCreateCall.html) (none) /// * [icons get projects](struct.ProjectIconGetCall.html) (none) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Project { /// An ID used to refer to this Maps Engine project. pub id: Option<String>, @@ -2065,7 +2069,7 @@ impl Part for Border {} /// /// * [list published layers](struct.LayerListPublishedCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PublishedLayersListResponse { /// Resources returned. pub layers: Vec<PublishedLayer>, @@ -2183,7 +2187,7 @@ impl Part for File {} /// /// * [list published maps](struct.MapListPublishedCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct PublishedMapsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -2284,7 +2288,7 @@ impl ResponseResult for Table {} /// /// * [list maps](struct.MapListCall.html) (response) /// -#[derive(Default, Clone, Debug, Deserialize)] +#[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct MapsListResponse { /// Next page token. #[serde(rename="nextPageToken")] @@ -4256,23 +4260,22 @@ impl<'a, C, A> LayerUnpublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerUnpublishCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerUnpublishCall<'a, C, A> { self._delegate = Some(new_value); self @@ -4302,8 +4305,8 @@ impl<'a, C, A> LayerUnpublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -4492,31 +4495,29 @@ impl<'a, C, A> LayerPublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerPublishCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *force* query property to the given value. - /// - /// /// If set to true, the API will allow publication of the layer even if it's out of date. If not true, you'll need to reprocess any out-of-date layer before publishing. + /// + /// Sets the *force* query property to the given value. pub fn force(mut self, new_value: bool) -> LayerPublishCall<'a, C, A> { self._force = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerPublishCall<'a, C, A> { self._delegate = Some(new_value); self @@ -4546,8 +4547,8 @@ impl<'a, C, A> LayerPublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -4720,37 +4721,33 @@ impl<'a, C, A> LayerListPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> LayerListPublishedCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> LayerListPublishedCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> LayerListPublishedCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerListPublishedCall<'a, C, A> { self._delegate = Some(new_value); self @@ -4780,8 +4777,8 @@ impl<'a, C, A> LayerListPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -4959,30 +4956,28 @@ impl<'a, C, A> LayerCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Layer) -> LayerCreateCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *process* query property to the given value. - /// - /// /// Whether to queue the created layer for processing. + /// + /// Sets the *process* query property to the given value. pub fn process(mut self, new_value: bool) -> LayerCreateCall<'a, C, A> { self._process = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerCreateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -5012,8 +5007,8 @@ impl<'a, C, A> LayerCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -5197,23 +5192,22 @@ impl<'a, C, A> LayerGetPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client> } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerGetPublishedCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerGetPublishedCall<'a, C, A> { self._delegate = Some(new_value); self @@ -5243,8 +5237,8 @@ impl<'a, C, A> LayerGetPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client> /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -5417,23 +5411,22 @@ impl<'a, C, A> LayerDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// The ID of the layer. Only the layer creator or project owner are permitted to delete. If the layer is published, or included in a map, the request will fail. Unpublish the layer, and remove it from all maps prior to deleting. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. Only the layer creator or project owner are permitted to delete. If the layer is published, or included in a map, the request will fail. Unpublish the layer, and remove it from all maps prior to deleting. pub fn id(mut self, new_value: &str) -> LayerDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -5463,8 +5456,8 @@ impl<'a, C, A> LayerDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -5653,31 +5646,29 @@ impl<'a, C, A> LayerGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *version* query property to the given value. - /// - /// /// Deprecated: The version parameter indicates which version of the layer should be returned. When version is set to published, the published version of the layer will be returned. Please use the layers.getPublished endpoint instead. + /// + /// Sets the *version* query property to the given value. pub fn version(mut self, new_value: &str) -> LayerGetCall<'a, C, A> { self._version = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -5707,8 +5698,8 @@ impl<'a, C, A> LayerGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -5907,32 +5898,31 @@ impl<'a, C, A> LayerPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchDeleteRequest) -> LayerPermissionBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset from which permissions will be removed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset from which permissions will be removed. pub fn id(mut self, new_value: &str) -> LayerPermissionBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerPermissionBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -5962,8 +5952,8 @@ impl<'a, C, A> LayerPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -6164,32 +6154,31 @@ impl<'a, C, A> LayerPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchUpdateRequest) -> LayerPermissionBatchUpdateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset to which permissions will be added. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset to which permissions will be added. pub fn id(mut self, new_value: &str) -> LayerPermissionBatchUpdateCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerPermissionBatchUpdateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -6219,8 +6208,8 @@ impl<'a, C, A> LayerPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -6443,116 +6432,102 @@ impl<'a, C, A> LayerListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *processing status* query property to the given value. /// - /// + /// Sets the *processing status* query property to the given value. pub fn processing_status(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._processing_status = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> LayerListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> LayerListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -6582,8 +6557,8 @@ impl<'a, C, A> LayerListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -6777,39 +6752,36 @@ impl<'a, C, A> LayerParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the layer whose parents will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer whose parents will be listed. pub fn id(mut self, new_value: &str) -> LayerParentListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> LayerParentListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> LayerParentListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerParentListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -6839,8 +6811,8 @@ impl<'a, C, A> LayerParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -7024,23 +6996,22 @@ impl<'a, C, A> LayerCancelProcessingCall<'a, C, A> where C: BorrowMut<hyper::Cli } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerCancelProcessingCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerCancelProcessingCall<'a, C, A> { self._delegate = Some(new_value); self @@ -7070,8 +7041,8 @@ impl<'a, C, A> LayerCancelProcessingCall<'a, C, A> where C: BorrowMut<hyper::Cli /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -7259,32 +7230,31 @@ impl<'a, C, A> LayerPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Layer) -> LayerPatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerPatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerPatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -7314,8 +7284,8 @@ impl<'a, C, A> LayerPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -7499,23 +7469,22 @@ impl<'a, C, A> LayerPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> LayerPermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerPermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -7545,8 +7514,8 @@ impl<'a, C, A> LayerPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -7730,23 +7699,22 @@ impl<'a, C, A> LayerProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// The ID of the layer. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the layer. pub fn id(mut self, new_value: &str) -> LayerProcesCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> LayerProcesCall<'a, C, A> { self._delegate = Some(new_value); self @@ -7776,8 +7744,8 @@ impl<'a, C, A> LayerProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -7978,32 +7946,31 @@ impl<'a, C, A> RasterPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hype } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchUpdateRequest) -> RasterPermissionBatchUpdateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset to which permissions will be added. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset to which permissions will be added. pub fn id(mut self, new_value: &str) -> RasterPermissionBatchUpdateCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterPermissionBatchUpdateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -8033,8 +8000,8 @@ impl<'a, C, A> RasterPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hype /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -8222,32 +8189,31 @@ impl<'a, C, A> RasterPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Raster) -> RasterPatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the raster. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster. pub fn id(mut self, new_value: &str) -> RasterPatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterPatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -8277,8 +8243,8 @@ impl<'a, C, A> RasterPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -8462,23 +8428,22 @@ impl<'a, C, A> RasterPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clie } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> RasterPermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterPermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -8508,8 +8473,8 @@ impl<'a, C, A> RasterPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clie /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -8682,23 +8647,22 @@ impl<'a, C, A> RasterDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: } + /// The ID of the raster. Only the raster creator or project owner are permitted to delete. If the raster is included in a layer or mosaic, the request will fail. Remove it from all parents prior to deleting. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster. Only the raster creator or project owner are permitted to delete. If the raster is included in a layer or mosaic, the request will fail. Remove it from all parents prior to deleting. pub fn id(mut self, new_value: &str) -> RasterDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -8728,8 +8692,8 @@ impl<'a, C, A> RasterDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -8928,32 +8892,31 @@ impl<'a, C, A> RasterPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hype } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchDeleteRequest) -> RasterPermissionBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset from which permissions will be removed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset from which permissions will be removed. pub fn id(mut self, new_value: &str) -> RasterPermissionBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterPermissionBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -8983,8 +8946,8 @@ impl<'a, C, A> RasterPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hype /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -9269,33 +9232,32 @@ impl<'a, C, A> RasterFileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, self.doit(resumeable_stream, mime_type, "resumable") } + /// The ID of the raster asset. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster asset. pub fn id(mut self, new_value: &str) -> RasterFileInsertCall<'a, C, A> { self._id = new_value.to_string(); self } + /// The file name of this uploaded file. + /// /// Sets the *filename* query property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The file name of this uploaded file. pub fn filename(mut self, new_value: &str) -> RasterFileInsertCall<'a, C, A> { self._filename = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterFileInsertCall<'a, C, A> { self._delegate = Some(new_value); self @@ -9325,8 +9287,8 @@ impl<'a, C, A> RasterFileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -9510,23 +9472,22 @@ impl<'a, C, A> RasterProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: } + /// The ID of the raster. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster. pub fn id(mut self, new_value: &str) -> RasterProcesCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterProcesCall<'a, C, A> { self._delegate = Some(new_value); self @@ -9556,8 +9517,8 @@ impl<'a, C, A> RasterProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -9741,23 +9702,22 @@ impl<'a, C, A> RasterGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } + /// The ID of the raster. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster. pub fn id(mut self, new_value: &str) -> RasterGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -9787,8 +9747,8 @@ impl<'a, C, A> RasterGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -10008,118 +9968,105 @@ impl<'a, C, A> RasterListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa } + /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// /// Sets the *project id* query property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. pub fn project_id(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._project_id = new_value.to_string(); self } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *processing status* query property to the given value. /// - /// + /// Sets the *processing status* query property to the given value. pub fn processing_status(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._processing_status = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> RasterListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> RasterListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -10149,8 +10096,8 @@ impl<'a, C, A> RasterListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -10323,22 +10270,21 @@ impl<'a, C, A> RasterUploadCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Raster) -> RasterUploadCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterUploadCall<'a, C, A> { self._delegate = Some(new_value); self @@ -10368,8 +10314,8 @@ impl<'a, C, A> RasterUploadCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -10563,39 +10509,36 @@ impl<'a, C, A> RasterParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the rasters whose parents will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the rasters whose parents will be listed. pub fn id(mut self, new_value: &str) -> RasterParentListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> RasterParentListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> RasterParentListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterParentListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -10625,8 +10568,8 @@ impl<'a, C, A> RasterParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -10810,23 +10753,22 @@ impl<'a, C, A> AssetPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> AssetPermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> AssetPermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -10856,8 +10798,8 @@ impl<'a, C, A> AssetPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -11080,117 +11022,103 @@ impl<'a, C, A> AssetListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } - /// Sets the *type* query property to the given value. - /// - /// /// A comma separated list of asset types. Returned assets will have one of the types from the provided list. Supported values are 'map', 'layer', 'rasterCollection' and 'table'. + /// + /// Sets the *type* query property to the given value. pub fn type_(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._type_ = Some(new_value.to_string()); self } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> AssetListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> AssetListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> AssetListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -11220,8 +11148,8 @@ impl<'a, C, A> AssetListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -11405,23 +11333,22 @@ impl<'a, C, A> AssetGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut } + /// The ID of the asset. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset. pub fn id(mut self, new_value: &str) -> AssetGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> AssetGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -11451,8 +11378,8 @@ impl<'a, C, A> AssetGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -11646,39 +11573,36 @@ impl<'a, C, A> AssetParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the asset whose parents will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose parents will be listed. pub fn id(mut self, new_value: &str) -> AssetParentListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> AssetParentListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> AssetParentListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> AssetParentListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -11708,8 +11632,8 @@ impl<'a, C, A> AssetParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -11882,23 +11806,22 @@ impl<'a, C, A> TableDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// The ID of the table. Only the table creator or project owner are permitted to delete. If the table is included in a layer, the request will fail. Remove it from all layers prior to deleting. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table. Only the table creator or project owner are permitted to delete. If the table is included in a layer, the request will fail. Remove it from all layers prior to deleting. pub fn id(mut self, new_value: &str) -> TableDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -11928,8 +11851,8 @@ impl<'a, C, A> TableDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -12215,33 +12138,32 @@ impl<'a, C, A> TableFileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, self.doit(resumeable_stream, mime_type, "resumable") } + /// The ID of the table asset. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table asset. pub fn id(mut self, new_value: &str) -> TableFileInsertCall<'a, C, A> { self._id = new_value.to_string(); self } + /// The file name of this uploaded file. + /// /// Sets the *filename* query property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The file name of this uploaded file. pub fn filename(mut self, new_value: &str) -> TableFileInsertCall<'a, C, A> { self._filename = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFileInsertCall<'a, C, A> { self._delegate = Some(new_value); self @@ -12271,8 +12193,8 @@ impl<'a, C, A> TableFileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -12468,32 +12390,31 @@ impl<'a, C, A> TableFeatureBatchInsertCall<'a, C, A> where C: BorrowMut<hyper::C } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &FeaturesBatchInsertRequest) -> TableFeatureBatchInsertCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the table to append the features to. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table to append the features to. pub fn id(mut self, new_value: &str) -> TableFeatureBatchInsertCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFeatureBatchInsertCall<'a, C, A> { self._delegate = Some(new_value); self @@ -12523,8 +12444,8 @@ impl<'a, C, A> TableFeatureBatchInsertCall<'a, C, A> where C: BorrowMut<hyper::C /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -12747,116 +12668,102 @@ impl<'a, C, A> TableListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *processing status* query property to the given value. /// - /// + /// Sets the *processing status* query property to the given value. pub fn processing_status(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._processing_status = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> TableListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> TableListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -12886,8 +12793,8 @@ impl<'a, C, A> TableListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -13076,30 +12983,28 @@ impl<'a, C, A> TableGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut } + /// The ID of the table. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table. pub fn id(mut self, new_value: &str) -> TableGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *version* query property to the given value. /// - /// + /// Sets the *version* query property to the given value. pub fn version(mut self, new_value: &str) -> TableGetCall<'a, C, A> { self._version = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -13129,8 +13034,8 @@ impl<'a, C, A> TableGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -13318,32 +13223,31 @@ impl<'a, C, A> TableFeatureBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper::C } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &FeaturesBatchDeleteRequest) -> TableFeatureBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the table that contains the features to be deleted. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table that contains the features to be deleted. pub fn id(mut self, new_value: &str) -> TableFeatureBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFeatureBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -13373,8 +13277,8 @@ impl<'a, C, A> TableFeatureBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper::C /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -13603,95 +13507,85 @@ impl<'a, C, A> TableFeatureListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the table to which these features belong. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table to which these features belong. pub fn id(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *where* query property to the given value. - /// - /// /// An SQL-like predicate used to filter results. + /// + /// Sets the *where* query property to the given value. pub fn where_(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._where_ = Some(new_value.to_string()); self } - /// Sets the *version* query property to the given value. - /// - /// /// The table version to access. See Accessing Public Data for information. + /// + /// Sets the *version* query property to the given value. pub fn version(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._version = Some(new_value.to_string()); self } - /// Sets the *select* query property to the given value. - /// - /// /// A SQL-like projection clause used to specify returned properties. If this parameter is not included, all properties are returned. + /// + /// Sets the *select* query property to the given value. pub fn select(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._select = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *order by* query property to the given value. - /// - /// /// An SQL-like order by clause used to sort results. If this parameter is not included, the order of features is undefined. + /// + /// Sets the *order by* query property to the given value. pub fn order_by(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._order_by = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in the response, used for paging. The maximum supported value is 1000. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> TableFeatureListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *limit* query property to the given value. - /// - /// /// The total number of features to return from the query, irrespective of the number of pages. + /// + /// Sets the *limit* query property to the given value. pub fn limit(mut self, new_value: u32) -> TableFeatureListCall<'a, C, A> { self._limit = Some(new_value); self } - /// Sets the *intersects* query property to the given value. - /// - /// /// A geometry literal that specifies the spatial restriction of the query. + /// + /// Sets the *intersects* query property to the given value. pub fn intersects(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._intersects = Some(new_value.to_string()); self } - /// Sets the *include* query property to the given value. - /// - /// /// A comma separated list of optional data to include. Optional data available: schema. + /// + /// Sets the *include* query property to the given value. pub fn include(mut self, new_value: &str) -> TableFeatureListCall<'a, C, A> { self._include = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFeatureListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -13721,8 +13615,8 @@ impl<'a, C, A> TableFeatureListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -13906,23 +13800,22 @@ impl<'a, C, A> TableProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// The ID of the table. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table. pub fn id(mut self, new_value: &str) -> TableProcesCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableProcesCall<'a, C, A> { self._delegate = Some(new_value); self @@ -13952,8 +13845,8 @@ impl<'a, C, A> TableProcesCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -14147,39 +14040,36 @@ impl<'a, C, A> TableParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the table whose parents will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table whose parents will be listed. pub fn id(mut self, new_value: &str) -> TableParentListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> TableParentListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> TableParentListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableParentListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -14209,8 +14099,8 @@ impl<'a, C, A> TableParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -14411,32 +14301,31 @@ impl<'a, C, A> TablePermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchUpdateRequest) -> TablePermissionBatchUpdateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset to which permissions will be added. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset to which permissions will be added. pub fn id(mut self, new_value: &str) -> TablePermissionBatchUpdateCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TablePermissionBatchUpdateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -14466,8 +14355,8 @@ impl<'a, C, A> TablePermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -14642,22 +14531,21 @@ impl<'a, C, A> TableUploadCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Table) -> TableUploadCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableUploadCall<'a, C, A> { self._delegate = Some(new_value); self @@ -14687,8 +14575,8 @@ impl<'a, C, A> TableUploadCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -14890,32 +14778,31 @@ impl<'a, C, A> TableFeatureBatchPatchCall<'a, C, A> where C: BorrowMut<hyper::Cl } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &FeaturesBatchPatchRequest) -> TableFeatureBatchPatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the table containing the features to be patched. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table containing the features to be patched. pub fn id(mut self, new_value: &str) -> TableFeatureBatchPatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFeatureBatchPatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -14945,8 +14832,8 @@ impl<'a, C, A> TableFeatureBatchPatchCall<'a, C, A> where C: BorrowMut<hyper::Cl /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -15134,32 +15021,31 @@ impl<'a, C, A> TablePatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Table) -> TablePatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the table. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table. pub fn id(mut self, new_value: &str) -> TablePatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TablePatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -15189,8 +15075,8 @@ impl<'a, C, A> TablePatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -15389,32 +15275,31 @@ impl<'a, C, A> TablePermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchDeleteRequest) -> TablePermissionBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset from which permissions will be removed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset from which permissions will be removed. pub fn id(mut self, new_value: &str) -> TablePermissionBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TablePermissionBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -15444,8 +15329,8 @@ impl<'a, C, A> TablePermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -15618,22 +15503,21 @@ impl<'a, C, A> TableCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Table) -> TableCreateCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableCreateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -15663,8 +15547,8 @@ impl<'a, C, A> TableCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -15848,23 +15732,22 @@ impl<'a, C, A> TablePermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> TablePermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TablePermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -15894,8 +15777,8 @@ impl<'a, C, A> TablePermissionListCall<'a, C, A> where C: BorrowMut<hyper::Clien /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -16091,49 +15974,46 @@ impl<'a, C, A> TableFeatureGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the table. + /// /// Sets the *table id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the table. pub fn table_id(mut self, new_value: &str) -> TableFeatureGetCall<'a, C, A> { self._table_id = new_value.to_string(); self } + /// The ID of the feature to get. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the feature to get. pub fn id(mut self, new_value: &str) -> TableFeatureGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *version* query property to the given value. - /// - /// /// The table version to access. See Accessing Public Data for information. + /// + /// Sets the *version* query property to the given value. pub fn version(mut self, new_value: &str) -> TableFeatureGetCall<'a, C, A> { self._version = Some(new_value.to_string()); self } - /// Sets the *select* query property to the given value. - /// - /// /// A SQL-like projection clause used to specify returned properties. If this parameter is not included, all properties are returned. + /// + /// Sets the *select* query property to the given value. pub fn select(mut self, new_value: &str) -> TableFeatureGetCall<'a, C, A> { self._select = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> TableFeatureGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -16163,8 +16043,8 @@ impl<'a, C, A> TableFeatureGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -16387,116 +16267,102 @@ impl<'a, C, A> MapListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *processing status* query property to the given value. /// - /// + /// Sets the *processing status* query property to the given value. pub fn processing_status(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._processing_status = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> MapListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> MapListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -16526,8 +16392,8 @@ impl<'a, C, A> MapListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -16700,37 +16566,33 @@ impl<'a, C, A> MapListPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client>, } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> MapListPublishedCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> MapListPublishedCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> MapListPublishedCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapListPublishedCall<'a, C, A> { self._delegate = Some(new_value); self @@ -16760,8 +16622,8 @@ impl<'a, C, A> MapListPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -16949,32 +16811,31 @@ impl<'a, C, A> MapPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Map) -> MapPatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the map. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. pub fn id(mut self, new_value: &str) -> MapPatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapPatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -17004,8 +16865,8 @@ impl<'a, C, A> MapPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -17206,32 +17067,31 @@ impl<'a, C, A> MapPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper:: } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchUpdateRequest) -> MapPermissionBatchUpdateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset to which permissions will be added. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset to which permissions will be added. pub fn id(mut self, new_value: &str) -> MapPermissionBatchUpdateCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapPermissionBatchUpdateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -17261,8 +17121,8 @@ impl<'a, C, A> MapPermissionBatchUpdateCall<'a, C, A> where C: BorrowMut<hyper:: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -17435,23 +17295,22 @@ impl<'a, C, A> MapDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } + /// The ID of the map. Only the map creator or project owner are permitted to delete. If the map is published the request will fail. Unpublish the map prior to deleting. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. Only the map creator or project owner are permitted to delete. If the map is published the request will fail. Unpublish the map prior to deleting. pub fn id(mut self, new_value: &str) -> MapDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -17481,8 +17340,8 @@ impl<'a, C, A> MapDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -17666,23 +17525,22 @@ impl<'a, C, A> MapUnpublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: } + /// The ID of the map. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. pub fn id(mut self, new_value: &str) -> MapUnpublishCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapUnpublishCall<'a, C, A> { self._delegate = Some(new_value); self @@ -17712,8 +17570,8 @@ impl<'a, C, A> MapUnpublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -17902,31 +17760,29 @@ impl<'a, C, A> MapPublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa } + /// The ID of the map. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. pub fn id(mut self, new_value: &str) -> MapPublishCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *force* query property to the given value. - /// - /// /// If set to true, the API will allow publication of the map even if it's out of date. If false, the map must have a processingStatus of complete before publishing. + /// + /// Sets the *force* query property to the given value. pub fn force(mut self, new_value: bool) -> MapPublishCall<'a, C, A> { self._force = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapPublishCall<'a, C, A> { self._delegate = Some(new_value); self @@ -17956,8 +17812,8 @@ impl<'a, C, A> MapPublishCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -18141,23 +17997,22 @@ impl<'a, C, A> MapPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Client> } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> MapPermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapPermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -18187,8 +18042,8 @@ impl<'a, C, A> MapPermissionListCall<'a, C, A> where C: BorrowMut<hyper::Client> /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -18361,22 +18216,21 @@ impl<'a, C, A> MapCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Map) -> MapCreateCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapCreateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -18406,8 +18260,8 @@ impl<'a, C, A> MapCreateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -18591,23 +18445,22 @@ impl<'a, C, A> MapGetPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the map. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. pub fn id(mut self, new_value: &str) -> MapGetPublishedCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapGetPublishedCall<'a, C, A> { self._delegate = Some(new_value); self @@ -18637,8 +18490,8 @@ impl<'a, C, A> MapGetPublishedCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -18827,31 +18680,29 @@ impl<'a, C, A> MapGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2 } + /// The ID of the map. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the map. pub fn id(mut self, new_value: &str) -> MapGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *version* query property to the given value. - /// - /// /// Deprecated: The version parameter indicates which version of the map should be returned. When version is set to published, the published version of the map will be returned. Please use the maps.getPublished endpoint instead. + /// + /// Sets the *version* query property to the given value. pub fn version(mut self, new_value: &str) -> MapGetCall<'a, C, A> { self._version = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -18881,8 +18732,8 @@ impl<'a, C, A> MapGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2 /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -19081,32 +18932,31 @@ impl<'a, C, A> MapPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper:: } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchDeleteRequest) -> MapPermissionBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset from which permissions will be removed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset from which permissions will be removed. pub fn id(mut self, new_value: &str) -> MapPermissionBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> MapPermissionBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -19136,8 +18986,8 @@ impl<'a, C, A> MapPermissionBatchDeleteCall<'a, C, A> where C: BorrowMut<hyper:: /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -19310,22 +19160,21 @@ impl<'a, C, A> RasterCollectionCreateCall<'a, C, A> where C: BorrowMut<hyper::Cl } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &RasterCollection) -> RasterCollectionCreateCall<'a, C, A> { self._request = new_value.clone(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionCreateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -19355,8 +19204,8 @@ impl<'a, C, A> RasterCollectionCreateCall<'a, C, A> where C: BorrowMut<hyper::Cl /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -19555,32 +19404,31 @@ impl<'a, C, A> RasterCollectionPermissionBatchDeleteCall<'a, C, A> where C: Borr } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchDeleteRequest) -> RasterCollectionPermissionBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset from which permissions will be removed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset from which permissions will be removed. pub fn id(mut self, new_value: &str) -> RasterCollectionPermissionBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionPermissionBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -19610,8 +19458,8 @@ impl<'a, C, A> RasterCollectionPermissionBatchDeleteCall<'a, C, A> where C: Borr /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -19799,32 +19647,31 @@ impl<'a, C, A> RasterCollectionPatchCall<'a, C, A> where C: BorrowMut<hyper::Cli } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &RasterCollection) -> RasterCollectionPatchCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the raster collection. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection. pub fn id(mut self, new_value: &str) -> RasterCollectionPatchCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionPatchCall<'a, C, A> { self._delegate = Some(new_value); self @@ -19854,8 +19701,8 @@ impl<'a, C, A> RasterCollectionPatchCall<'a, C, A> where C: BorrowMut<hyper::Cli /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -20039,23 +19886,22 @@ impl<'a, C, A> RasterCollectionCancelProcessingCall<'a, C, A> where C: BorrowMut } + /// The ID of the raster collection. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection. pub fn id(mut self, new_value: &str) -> RasterCollectionCancelProcessingCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionCancelProcessingCall<'a, C, A> { self._delegate = Some(new_value); self @@ -20085,8 +19931,8 @@ impl<'a, C, A> RasterCollectionCancelProcessingCall<'a, C, A> where C: BorrowMut /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -20270,23 +20116,22 @@ impl<'a, C, A> RasterCollectionProcesCall<'a, C, A> where C: BorrowMut<hyper::Cl } + /// The ID of the raster collection. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection. pub fn id(mut self, new_value: &str) -> RasterCollectionProcesCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionProcesCall<'a, C, A> { self._delegate = Some(new_value); self @@ -20316,8 +20161,8 @@ impl<'a, C, A> RasterCollectionProcesCall<'a, C, A> where C: BorrowMut<hyper::Cl /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -20518,32 +20363,31 @@ impl<'a, C, A> RasterCollectionPermissionBatchUpdateCall<'a, C, A> where C: Borr } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &PermissionsBatchUpdateRequest) -> RasterCollectionPermissionBatchUpdateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the asset to which permissions will be added. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset to which permissions will be added. pub fn id(mut self, new_value: &str) -> RasterCollectionPermissionBatchUpdateCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionPermissionBatchUpdateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -20573,8 +20417,8 @@ impl<'a, C, A> RasterCollectionPermissionBatchUpdateCall<'a, C, A> where C: Borr /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -20747,23 +20591,22 @@ impl<'a, C, A> RasterCollectionDeleteCall<'a, C, A> where C: BorrowMut<hyper::Cl } + /// The ID of the raster collection. Only the raster collection creator or project owner are permitted to delete. If the rastor collection is included in a layer, the request will fail. Remove the raster collection from all layers prior to deleting. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection. Only the raster collection creator or project owner are permitted to delete. If the rastor collection is included in a layer, the request will fail. Remove the raster collection from all layers prior to deleting. pub fn id(mut self, new_value: &str) -> RasterCollectionDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -20793,8 +20636,8 @@ impl<'a, C, A> RasterCollectionDeleteCall<'a, C, A> where C: BorrowMut<hyper::Cl /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -20988,39 +20831,36 @@ impl<'a, C, A> RasterCollectionParentListCall<'a, C, A> where C: BorrowMut<hyper } + /// The ID of the raster collection whose parents will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection whose parents will be listed. pub fn id(mut self, new_value: &str) -> RasterCollectionParentListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> RasterCollectionParentListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> RasterCollectionParentListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionParentListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -21050,8 +20890,8 @@ impl<'a, C, A> RasterCollectionParentListCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -21274,116 +21114,102 @@ impl<'a, C, A> RasterCollectionListCall<'a, C, A> where C: BorrowMut<hyper::Clie } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *project id* query property to the given value. - /// - /// /// The ID of a Maps Engine project, used to filter the response. To list all available projects with their IDs, send a Projects: list request. You can also find your project ID as the value of the DashboardPlace:cid URL parameter when signed in to mapsengine.google.com. + /// + /// Sets the *project id* query property to the given value. pub fn project_id(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._project_id = Some(new_value.to_string()); self } - /// Sets the *processing status* query property to the given value. /// - /// + /// Sets the *processing status* query property to the given value. pub fn processing_status(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._processing_status = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> RasterCollectionListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> RasterCollectionListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -21413,8 +21239,8 @@ impl<'a, C, A> RasterCollectionListCall<'a, C, A> where C: BorrowMut<hyper::Clie /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -21615,32 +21441,31 @@ impl<'a, C, A> RasterCollectionRasterBatchInsertCall<'a, C, A> where C: BorrowMu } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &RasterCollectionsRastersBatchInsertRequest) -> RasterCollectionRasterBatchInsertCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the raster collection to which these rasters belong. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection to which these rasters belong. pub fn id(mut self, new_value: &str) -> RasterCollectionRasterBatchInsertCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionRasterBatchInsertCall<'a, C, A> { self._delegate = Some(new_value); self @@ -21670,8 +21495,8 @@ impl<'a, C, A> RasterCollectionRasterBatchInsertCall<'a, C, A> where C: BorrowMu /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -21872,32 +21697,31 @@ impl<'a, C, A> RasterCollectionRasterBatchDeleteCall<'a, C, A> where C: BorrowMu } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &RasterCollectionsRasterBatchDeleteRequest) -> RasterCollectionRasterBatchDeleteCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the raster collection to which these rasters belong. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection to which these rasters belong. pub fn id(mut self, new_value: &str) -> RasterCollectionRasterBatchDeleteCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionRasterBatchDeleteCall<'a, C, A> { self._delegate = Some(new_value); self @@ -21927,8 +21751,8 @@ impl<'a, C, A> RasterCollectionRasterBatchDeleteCall<'a, C, A> where C: BorrowMu /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -22112,23 +21936,22 @@ impl<'a, C, A> RasterCollectionPermissionListCall<'a, C, A> where C: BorrowMut<h } + /// The ID of the asset whose permissions will be listed. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the asset whose permissions will be listed. pub fn id(mut self, new_value: &str) -> RasterCollectionPermissionListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionPermissionListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -22158,8 +21981,8 @@ impl<'a, C, A> RasterCollectionPermissionListCall<'a, C, A> where C: BorrowMut<h /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -22343,23 +22166,22 @@ impl<'a, C, A> RasterCollectionGetCall<'a, C, A> where C: BorrowMut<hyper::Clien } + /// The ID of the raster collection. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection. pub fn id(mut self, new_value: &str) -> RasterCollectionGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -22389,8 +22211,8 @@ impl<'a, C, A> RasterCollectionGetCall<'a, C, A> where C: BorrowMut<hyper::Clien /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -22629,111 +22451,99 @@ impl<'a, C, A> RasterCollectionRasterListCall<'a, C, A> where C: BorrowMut<hyper } + /// The ID of the raster collection to which these rasters belong. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the raster collection to which these rasters belong. pub fn id(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *tags* query property to the given value. - /// - /// /// A comma separated list of tags. Returned assets will contain all the tags from the list. + /// + /// Sets the *tags* query property to the given value. pub fn tags(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._tags = Some(new_value.to_string()); self } - /// Sets the *search* query property to the given value. - /// - /// /// An unstructured search string used to filter the set of results based on asset metadata. + /// + /// Sets the *search* query property to the given value. pub fn search(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._search = Some(new_value.to_string()); self } - /// Sets the *role* query property to the given value. - /// - /// /// The role parameter indicates that the response should only contain assets where the current user has the specified level of access. + /// + /// Sets the *role* query property to the given value. pub fn role(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._role = Some(new_value.to_string()); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *modified before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or before this time. + /// + /// Sets the *modified before* query property to the given value. pub fn modified_before(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._modified_before = Some(new_value.to_string()); self } - /// Sets the *modified after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been modified at or after this time. + /// + /// Sets the *modified after* query property to the given value. pub fn modified_after(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._modified_after = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 100. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> RasterCollectionRasterListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *creator email* query property to the given value. - /// - /// /// An email address representing a user. Returned assets that have been created by the user associated with the provided email address. + /// + /// Sets the *creator email* query property to the given value. pub fn creator_email(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._creator_email = Some(new_value.to_string()); self } - /// Sets the *created before* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or before this time. + /// + /// Sets the *created before* query property to the given value. pub fn created_before(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._created_before = Some(new_value.to_string()); self } - /// Sets the *created after* query property to the given value. - /// - /// /// An RFC 3339 formatted date-time value (e.g. 1970-01-01T00:00:00Z). Returned assets will have been created at or after this time. + /// + /// Sets the *created after* query property to the given value. pub fn created_after(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._created_after = Some(new_value.to_string()); self } - /// Sets the *bbox* query property to the given value. - /// - /// /// A bounding box, expressed as "west,south,east,north". If set, only assets which intersect this bounding box will be returned. + /// + /// Sets the *bbox* query property to the given value. pub fn bbox(mut self, new_value: &str) -> RasterCollectionRasterListCall<'a, C, A> { self._bbox = Some(new_value.to_string()); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> RasterCollectionRasterListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -22763,8 +22573,8 @@ impl<'a, C, A> RasterCollectionRasterListCall<'a, C, A> where C: BorrowMut<hyper /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -22971,33 +22781,32 @@ impl<'a, C, A> ProjectIconGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A } + /// The ID of the project. + /// /// Sets the *project id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the project. pub fn project_id(mut self, new_value: &str) -> ProjectIconGetCall<'a, C, A> { self._project_id = new_value.to_string(); self } + /// The ID of the icon. + /// /// Sets the *id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the icon. pub fn id(mut self, new_value: &str) -> ProjectIconGetCall<'a, C, A> { self._id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> ProjectIconGetCall<'a, C, A> { self._delegate = Some(new_value); self @@ -23027,8 +22836,8 @@ impl<'a, C, A> ProjectIconGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -23342,32 +23151,31 @@ impl<'a, C, A> ProjectIconCreateCall<'a, C, A> where C: BorrowMut<hyper::Client> self.doit(resumeable_stream, mime_type, "resumable") } + /// /// Sets the *request* property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// pub fn request(mut self, new_value: &Icon) -> ProjectIconCreateCall<'a, C, A> { self._request = new_value.clone(); self } + /// The ID of the project. + /// /// Sets the *project id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the project. pub fn project_id(mut self, new_value: &str) -> ProjectIconCreateCall<'a, C, A> { self._project_id = new_value.to_string(); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> ProjectIconCreateCall<'a, C, A> { self._delegate = Some(new_value); self @@ -23397,8 +23205,8 @@ impl<'a, C, A> ProjectIconCreateCall<'a, C, A> where C: BorrowMut<hyper::Client> /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Full`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -23556,13 +23364,12 @@ impl<'a, C, A> ProjectListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> ProjectListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -23592,8 +23399,8 @@ impl<'a, C, A> ProjectListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. @@ -23787,39 +23594,36 @@ impl<'a, C, A> ProjectIconListCall<'a, C, A> where C: BorrowMut<hyper::Client>, } + /// The ID of the project. + /// /// Sets the *project id* path property to the given value. /// /// Even though the property as already been set when instantiating this call, /// we provide this method for API completeness. - /// - /// The ID of the project. pub fn project_id(mut self, new_value: &str) -> ProjectIconListCall<'a, C, A> { self._project_id = new_value.to_string(); self } - /// Sets the *page token* query property to the given value. - /// - /// /// The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of nextPageToken from the previous response. + /// + /// Sets the *page token* query property to the given value. pub fn page_token(mut self, new_value: &str) -> ProjectIconListCall<'a, C, A> { self._page_token = Some(new_value.to_string()); self } - /// Sets the *max results* query property to the given value. - /// - /// /// The maximum number of items to include in a single response page. The maximum supported value is 50. + /// + /// Sets the *max results* query property to the given value. pub fn max_results(mut self, new_value: u32) -> ProjectIconListCall<'a, C, A> { self._max_results = Some(new_value); self } - /// Sets the *delegate* property to the given value. - /// - /// /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong /// while executing the actual API request. /// /// It should be used to handle progress information, and to implement a certain level of resilience. + /// + /// Sets the *delegate* property to the given value. pub fn delegate(mut self, new_value: &'a mut Delegate) -> ProjectIconListCall<'a, C, A> { self._delegate = Some(new_value); self @@ -23849,8 +23653,8 @@ impl<'a, C, A> ProjectIconListCall<'a, C, A> where C: BorrowMut<hyper::Client>, /// Identifies the authorization scope for the method you are building. /// - /// Use this method to actively specify which scope should be used, instead of relying on the - /// automated algorithm which simply prefers read-only scopes over those who are not. + /// Use this method to actively specify which scope should be used, instead the default `Scope` variant + /// `Scope::Readonly`. /// /// The `scope` will be added to a set of scopes. This is important as one can maintain access /// tokens for more than one scope. diff --git a/gen/mirror1-cli/Cargo.toml b/gen/mirror1-cli/Cargo.toml new file mode 100644 index 00000000000..5c669fc8d98 --- /dev/null +++ b/gen/mirror1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-mirror1-cli" +version = "0.0.1+20150220" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with mirror (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/mirror1-cli" +homepage = "https://developers.google.com/glass" +documentation = "http://byron.github.io/google-apis-rs/google_mirror1_cli" +license = "MIT" +keywords = ["mirror", "google", "cli"] + +[[bin]] +name = "mirror1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-mirror1] +path = "../mirror1" diff --git a/gen/mirror1-cli/LICENSE.md b/gen/mirror1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/mirror1-cli/LICENSE.md @@ -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. diff --git a/gen/mirror1-cli/README.md b/gen/mirror1-cli/README.md new file mode 100644 index 00000000000..59c3764d200 --- /dev/null +++ b/gen/mirror1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO MIRROR:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/mirror1-cli/mkdocs.yml b/gen/mirror1-cli/mkdocs.yml new file mode 100644 index 00000000000..56f894e9867 --- /dev/null +++ b/gen/mirror1-cli/mkdocs.yml @@ -0,0 +1,40 @@ +site_name: mirror v0.0.1+20150220 +site_url: http://byron.github.io/google-apis-rs/google-mirror1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/mirror1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_insert.md', 'Accounts', 'Insert'] +- ['contacts_delete.md', 'Contacts', 'Delete'] +- ['contacts_get.md', 'Contacts', 'Get'] +- ['contacts_insert.md', 'Contacts', 'Insert'] +- ['contacts_list.md', 'Contacts', 'List'] +- ['contacts_patch.md', 'Contacts', 'Patch'] +- ['contacts_update.md', 'Contacts', 'Update'] +- ['locations_get.md', 'Locations', 'Get'] +- ['locations_list.md', 'Locations', 'List'] +- ['settings_get.md', 'Settings', 'Get'] +- ['subscriptions_delete.md', 'Subscriptions', 'Delete'] +- ['subscriptions_insert.md', 'Subscriptions', 'Insert'] +- ['subscriptions_list.md', 'Subscriptions', 'List'] +- ['subscriptions_update.md', 'Subscriptions', 'Update'] +- ['timeline_attachments-delete.md', 'Timeline', 'Attachments Delete'] +- ['timeline_attachments-get.md', 'Timeline', 'Attachments Get'] +- ['timeline_attachments-insert.md', 'Timeline', 'Attachments Insert'] +- ['timeline_attachments-list.md', 'Timeline', 'Attachments List'] +- ['timeline_delete.md', 'Timeline', 'Delete'] +- ['timeline_get.md', 'Timeline', 'Get'] +- ['timeline_insert.md', 'Timeline', 'Insert'] +- ['timeline_list.md', 'Timeline', 'List'] +- ['timeline_patch.md', 'Timeline', 'Patch'] +- ['timeline_update.md', 'Timeline', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/mirror1-cli/src/cmn.rs b/gen/mirror1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/mirror1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/mirror1-cli/src/main.rs b/gen/mirror1-cli/src/main.rs new file mode 100644 index 00000000000..a2efab9c965 --- /dev/null +++ b/gen/mirror1-cli/src/main.rs @@ -0,0 +1,2267 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_mirror1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + mirror1 [options] accounts insert <user-token> <account-type> <account-name> -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] contacts delete <id> [-p <v>]... + mirror1 [options] contacts get <id> [-p <v>]... [-o <out>] + mirror1 [options] contacts insert -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] contacts list [-p <v>]... [-o <out>] + mirror1 [options] contacts patch <id> -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] contacts update <id> -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] locations get <id> [-p <v>]... [-o <out>] + mirror1 [options] locations list [-p <v>]... [-o <out>] + mirror1 [options] settings get <id> [-p <v>]... [-o <out>] + mirror1 [options] subscriptions delete <id> [-p <v>]... + mirror1 [options] subscriptions insert -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] subscriptions list [-p <v>]... [-o <out>] + mirror1 [options] subscriptions update <id> -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] timeline attachments-delete <item-id> <attachment-id> [-p <v>]... + mirror1 [options] timeline attachments-get <item-id> <attachment-id> [-p <v>]... [-o <out>] + mirror1 [options] timeline attachments-insert <item-id> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + mirror1 [options] timeline attachments-list <item-id> [-p <v>]... [-o <out>] + mirror1 [options] timeline delete <id> [-p <v>]... + mirror1 [options] timeline get <id> [-p <v>]... [-o <out>] + mirror1 [options] timeline insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + mirror1 [options] timeline list [-p <v>]... [-o <out>] + mirror1 [options] timeline patch <id> -r <kv>... [-p <v>]... [-o <out>] + mirror1 [options] timeline update <id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + mirror1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Mirror<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _accounts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().insert(&request, &self.opt.arg_user_token, &self.opt.arg_account_type, &self.opt.arg_account_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + "features" => { + if request.features.is_none() { + request.features = Some(Default::default()); + } + request.features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _contacts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.contacts().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _contacts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.contacts().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _contacts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Contact = Default::default(); + let mut call = self.hub.contacts().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "accept-types" => { + if request.accept_types.is_none() { + request.accept_types = Some(Default::default()); + } + request.accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-urls" => { + if request.image_urls.is_none() { + request.image_urls = Some(Default::default()); + } + request.image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "priority" => { + request.priority = Some(arg_from_str(value.unwrap_or("-0"), err, "priority", "integer")); + }, + "source" => { + request.source = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "sharing-features" => { + if request.sharing_features.is_none() { + request.sharing_features = Some(Default::default()); + } + request.sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "speakable-name" => { + request.speakable_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _contacts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.contacts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _contacts_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Contact = Default::default(); + let mut call = self.hub.contacts().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "accept-types" => { + if request.accept_types.is_none() { + request.accept_types = Some(Default::default()); + } + request.accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-urls" => { + if request.image_urls.is_none() { + request.image_urls = Some(Default::default()); + } + request.image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "priority" => { + request.priority = Some(arg_from_str(value.unwrap_or("-0"), err, "priority", "integer")); + }, + "source" => { + request.source = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "sharing-features" => { + if request.sharing_features.is_none() { + request.sharing_features = Some(Default::default()); + } + request.sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "speakable-name" => { + request.speakable_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _contacts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Contact = Default::default(); + let mut call = self.hub.contacts().update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "accept-types" => { + if request.accept_types.is_none() { + request.accept_types = Some(Default::default()); + } + request.accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "image-urls" => { + if request.image_urls.is_none() { + request.image_urls = Some(Default::default()); + } + request.image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "priority" => { + request.priority = Some(arg_from_str(value.unwrap_or("-0"), err, "priority", "integer")); + }, + "source" => { + request.source = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "sharing-features" => { + if request.sharing_features.is_none() { + request.sharing_features = Some(Default::default()); + } + request.sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "speakable-name" => { + request.speakable_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _locations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.locations().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _locations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.locations().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _settings_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.settings().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _subscriptions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subscription = Default::default(); + let mut call = self.hub.subscriptions().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_notification_init(request: &mut api::Subscription) { + if request.notification.is_none() { + request.notification = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notification.item-id" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().item_id = value.unwrap_or("").to_string(); + }, + "notification.user-token" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().user_token = value.unwrap_or("").to_string(); + }, + "notification.operation" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().operation = value.unwrap_or("").to_string(); + }, + "notification.verify-token" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().verify_token = value.unwrap_or("").to_string(); + }, + "notification.collection" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().collection = value.unwrap_or("").to_string(); + }, + "updated" => { + request_notification_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "collection" => { + request_notification_init(&mut request); + request.collection = Some(value.unwrap_or("").to_string()); + }, + "verify-token" => { + request_notification_init(&mut request); + request.verify_token = Some(value.unwrap_or("").to_string()); + }, + "user-token" => { + request_notification_init(&mut request); + request.user_token = Some(value.unwrap_or("").to_string()); + }, + "operation" => { + request_notification_init(&mut request); + if request.operation.is_none() { + request.operation = Some(Default::default()); + } + request.operation.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_notification_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "callback-url" => { + request_notification_init(&mut request); + request.callback_url = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subscription = Default::default(); + let mut call = self.hub.subscriptions().update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_notification_init(request: &mut api::Subscription) { + if request.notification.is_none() { + request.notification = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "notification.item-id" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().item_id = value.unwrap_or("").to_string(); + }, + "notification.user-token" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().user_token = value.unwrap_or("").to_string(); + }, + "notification.operation" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().operation = value.unwrap_or("").to_string(); + }, + "notification.verify-token" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().verify_token = value.unwrap_or("").to_string(); + }, + "notification.collection" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().collection = value.unwrap_or("").to_string(); + }, + "updated" => { + request_notification_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "collection" => { + request_notification_init(&mut request); + request.collection = Some(value.unwrap_or("").to_string()); + }, + "verify-token" => { + request_notification_init(&mut request); + request.verify_token = Some(value.unwrap_or("").to_string()); + }, + "user-token" => { + request_notification_init(&mut request); + request.user_token = Some(value.unwrap_or("").to_string()); + }, + "operation" => { + request_notification_init(&mut request); + if request.operation.is_none() { + request.operation = Some(Default::default()); + } + request.operation.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request_notification_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "callback-url" => { + request_notification_init(&mut request); + request.callback_url = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_attachments_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().attachments_delete(&self.opt.arg_item_id, &self.opt.arg_attachment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _timeline_attachments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.timeline().attachments_get(&self.opt.arg_item_id, &self.opt.arg_attachment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _timeline_attachments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().attachments_insert(&self.opt.arg_item_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_attachments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().attachments_list(&self.opt.arg_item_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _timeline_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TimelineItem = Default::default(); + let mut call = self.hub.timeline().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::TimelineItem) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::TimelineItem) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_notification_init(request: &mut api::TimelineItem) { + if request.notification.is_none() { + request.notification = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "display-time" => { + request.display_time = Some(value.unwrap_or("").to_string()); + }, + "creator.kind" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "creator.accept-types" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().accept_types.is_none() { + request.creator.as_mut().unwrap().accept_types = Some(Default::default()); + } + request.creator.as_mut().unwrap().accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.image-urls" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().image_urls.is_none() { + request.creator.as_mut().unwrap().image_urls = Some(Default::default()); + } + request.creator.as_mut().unwrap().image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.priority" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().priority = Some(arg_from_str(value.unwrap_or("-0"), err, "creator.priority", "integer")); + }, + "creator.source" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().source = Some(value.unwrap_or("").to_string()); + }, + "creator.phone-number" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().phone_number = Some(value.unwrap_or("").to_string()); + }, + "creator.sharing-features" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().sharing_features.is_none() { + request.creator.as_mut().unwrap().sharing_features = Some(Default::default()); + } + request.creator.as_mut().unwrap().sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.type" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creator.speakable-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().speakable_name = Some(value.unwrap_or("").to_string()); + }, + "text" => { + request_creator_init(&mut request); + request.text = Some(value.unwrap_or("").to_string()); + }, + "is-bundle-cover" => { + request_creator_init(&mut request); + request.is_bundle_cover = Some(arg_from_str(value.unwrap_or("false"), err, "is-bundle-cover", "boolean")); + }, + "etag" => { + request_creator_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_creator_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "is-deleted" => { + request_creator_init(&mut request); + request.is_deleted = Some(arg_from_str(value.unwrap_or("false"), err, "is-deleted", "boolean")); + }, + "bundle-id" => { + request_creator_init(&mut request); + request.bundle_id = Some(value.unwrap_or("").to_string()); + }, + "is-pinned" => { + request_creator_init(&mut request); + request.is_pinned = Some(arg_from_str(value.unwrap_or("false"), err, "is-pinned", "boolean")); + }, + "title" => { + request_creator_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "pin-score" => { + request_creator_init(&mut request); + request.pin_score = Some(arg_from_str(value.unwrap_or("-0"), err, "pin-score", "integer")); + }, + "speakable-text" => { + request_creator_init(&mut request); + request.speakable_text = Some(value.unwrap_or("").to_string()); + }, + "html" => { + request_creator_init(&mut request); + request.html = Some(value.unwrap_or("").to_string()); + }, + "location.kind" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "location.display-name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "location.timestamp" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().timestamp = value.unwrap_or("").to_string(); + }, + "location.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.longitude", "number"); + }, + "location.address" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().address = value.unwrap_or("").to_string(); + }, + "location.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.latitude", "number"); + }, + "location.id" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "location.accuracy" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().accuracy = arg_from_str(value.unwrap_or("0.0"), err, "location.accuracy", "number"); + }, + "source-item-id" => { + request_location_init(&mut request); + request.source_item_id = Some(value.unwrap_or("").to_string()); + }, + "in-reply-to" => { + request_location_init(&mut request); + request.in_reply_to = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_location_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "canonical-url" => { + request_location_init(&mut request); + request.canonical_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_location_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_location_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "notification.level" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().level = value.unwrap_or("").to_string(); + }, + "notification.delivery-time" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().delivery_time = value.unwrap_or("").to_string(); + }, + "speakable-type" => { + request_notification_init(&mut request); + request.speakable_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_notification_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.timeline().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source-item-id" => { + call = call.source_item_id(value.unwrap_or("")); + }, + "pinned-only" => { + call = call.pinned_only(arg_from_str(value.unwrap_or("false"), err, "pinned-only", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "include-deleted" => { + call = call.include_deleted(arg_from_str(value.unwrap_or("false"), err, "include-deleted", "boolean")); + }, + "bundle-id" => { + call = call.bundle_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TimelineItem = Default::default(); + let mut call = self.hub.timeline().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::TimelineItem) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::TimelineItem) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_notification_init(request: &mut api::TimelineItem) { + if request.notification.is_none() { + request.notification = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "display-time" => { + request.display_time = Some(value.unwrap_or("").to_string()); + }, + "creator.kind" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "creator.accept-types" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().accept_types.is_none() { + request.creator.as_mut().unwrap().accept_types = Some(Default::default()); + } + request.creator.as_mut().unwrap().accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.image-urls" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().image_urls.is_none() { + request.creator.as_mut().unwrap().image_urls = Some(Default::default()); + } + request.creator.as_mut().unwrap().image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.priority" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().priority = Some(arg_from_str(value.unwrap_or("-0"), err, "creator.priority", "integer")); + }, + "creator.source" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().source = Some(value.unwrap_or("").to_string()); + }, + "creator.phone-number" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().phone_number = Some(value.unwrap_or("").to_string()); + }, + "creator.sharing-features" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().sharing_features.is_none() { + request.creator.as_mut().unwrap().sharing_features = Some(Default::default()); + } + request.creator.as_mut().unwrap().sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.type" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creator.speakable-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().speakable_name = Some(value.unwrap_or("").to_string()); + }, + "text" => { + request_creator_init(&mut request); + request.text = Some(value.unwrap_or("").to_string()); + }, + "is-bundle-cover" => { + request_creator_init(&mut request); + request.is_bundle_cover = Some(arg_from_str(value.unwrap_or("false"), err, "is-bundle-cover", "boolean")); + }, + "etag" => { + request_creator_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_creator_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "is-deleted" => { + request_creator_init(&mut request); + request.is_deleted = Some(arg_from_str(value.unwrap_or("false"), err, "is-deleted", "boolean")); + }, + "bundle-id" => { + request_creator_init(&mut request); + request.bundle_id = Some(value.unwrap_or("").to_string()); + }, + "is-pinned" => { + request_creator_init(&mut request); + request.is_pinned = Some(arg_from_str(value.unwrap_or("false"), err, "is-pinned", "boolean")); + }, + "title" => { + request_creator_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "pin-score" => { + request_creator_init(&mut request); + request.pin_score = Some(arg_from_str(value.unwrap_or("-0"), err, "pin-score", "integer")); + }, + "speakable-text" => { + request_creator_init(&mut request); + request.speakable_text = Some(value.unwrap_or("").to_string()); + }, + "html" => { + request_creator_init(&mut request); + request.html = Some(value.unwrap_or("").to_string()); + }, + "location.kind" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "location.display-name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "location.timestamp" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().timestamp = value.unwrap_or("").to_string(); + }, + "location.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.longitude", "number"); + }, + "location.address" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().address = value.unwrap_or("").to_string(); + }, + "location.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.latitude", "number"); + }, + "location.id" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "location.accuracy" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().accuracy = arg_from_str(value.unwrap_or("0.0"), err, "location.accuracy", "number"); + }, + "source-item-id" => { + request_location_init(&mut request); + request.source_item_id = Some(value.unwrap_or("").to_string()); + }, + "in-reply-to" => { + request_location_init(&mut request); + request.in_reply_to = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_location_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "canonical-url" => { + request_location_init(&mut request); + request.canonical_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_location_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_location_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "notification.level" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().level = value.unwrap_or("").to_string(); + }, + "notification.delivery-time" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().delivery_time = value.unwrap_or("").to_string(); + }, + "speakable-type" => { + request_notification_init(&mut request); + request.speakable_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_notification_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _timeline_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TimelineItem = Default::default(); + let mut call = self.hub.timeline().update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_creator_init(request: &mut api::TimelineItem) { + if request.creator.is_none() { + request.creator = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::TimelineItem) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_notification_init(request: &mut api::TimelineItem) { + if request.notification.is_none() { + request.notification = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "display-time" => { + request.display_time = Some(value.unwrap_or("").to_string()); + }, + "creator.kind" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "creator.display-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().display_name = Some(value.unwrap_or("").to_string()); + }, + "creator.accept-types" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().accept_types.is_none() { + request.creator.as_mut().unwrap().accept_types = Some(Default::default()); + } + request.creator.as_mut().unwrap().accept_types.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.image-urls" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().image_urls.is_none() { + request.creator.as_mut().unwrap().image_urls = Some(Default::default()); + } + request.creator.as_mut().unwrap().image_urls.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.priority" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().priority = Some(arg_from_str(value.unwrap_or("-0"), err, "creator.priority", "integer")); + }, + "creator.source" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().source = Some(value.unwrap_or("").to_string()); + }, + "creator.phone-number" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().phone_number = Some(value.unwrap_or("").to_string()); + }, + "creator.sharing-features" => { + request_creator_init(&mut request); + if request.creator.as_mut().unwrap().sharing_features.is_none() { + request.creator.as_mut().unwrap().sharing_features = Some(Default::default()); + } + request.creator.as_mut().unwrap().sharing_features.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "creator.type" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().type_ = Some(value.unwrap_or("").to_string()); + }, + "creator.id" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "creator.speakable-name" => { + request_creator_init(&mut request); + request.creator.as_mut().unwrap().speakable_name = Some(value.unwrap_or("").to_string()); + }, + "text" => { + request_creator_init(&mut request); + request.text = Some(value.unwrap_or("").to_string()); + }, + "is-bundle-cover" => { + request_creator_init(&mut request); + request.is_bundle_cover = Some(arg_from_str(value.unwrap_or("false"), err, "is-bundle-cover", "boolean")); + }, + "etag" => { + request_creator_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_creator_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "is-deleted" => { + request_creator_init(&mut request); + request.is_deleted = Some(arg_from_str(value.unwrap_or("false"), err, "is-deleted", "boolean")); + }, + "bundle-id" => { + request_creator_init(&mut request); + request.bundle_id = Some(value.unwrap_or("").to_string()); + }, + "is-pinned" => { + request_creator_init(&mut request); + request.is_pinned = Some(arg_from_str(value.unwrap_or("false"), err, "is-pinned", "boolean")); + }, + "title" => { + request_creator_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "pin-score" => { + request_creator_init(&mut request); + request.pin_score = Some(arg_from_str(value.unwrap_or("-0"), err, "pin-score", "integer")); + }, + "speakable-text" => { + request_creator_init(&mut request); + request.speakable_text = Some(value.unwrap_or("").to_string()); + }, + "html" => { + request_creator_init(&mut request); + request.html = Some(value.unwrap_or("").to_string()); + }, + "location.kind" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "location.display-name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "location.timestamp" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().timestamp = value.unwrap_or("").to_string(); + }, + "location.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.longitude", "number"); + }, + "location.address" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().address = value.unwrap_or("").to_string(); + }, + "location.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.latitude", "number"); + }, + "location.id" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "location.accuracy" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().accuracy = arg_from_str(value.unwrap_or("0.0"), err, "location.accuracy", "number"); + }, + "source-item-id" => { + request_location_init(&mut request); + request.source_item_id = Some(value.unwrap_or("").to_string()); + }, + "in-reply-to" => { + request_location_init(&mut request); + request.in_reply_to = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request_location_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "canonical-url" => { + request_location_init(&mut request); + request.canonical_url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_location_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request_location_init(&mut request); + request.created = Some(value.unwrap_or("").to_string()); + }, + "notification.level" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().level = value.unwrap_or("").to_string(); + }, + "notification.delivery-time" => { + request_notification_init(&mut request); + request.notification.as_mut().unwrap().delivery_time = value.unwrap_or("").to_string(); + }, + "speakable-type" => { + request_notification_init(&mut request); + request.speakable_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_notification_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_insert { + call_result = self._accounts_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_contacts { + if self.opt.cmd_delete { + call_result = self._contacts_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._contacts_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._contacts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._contacts_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._contacts_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._contacts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_locations { + if self.opt.cmd_get { + call_result = self._locations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._locations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_settings { + if self.opt.cmd_get { + call_result = self._settings_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_subscriptions { + if self.opt.cmd_delete { + call_result = self._subscriptions_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._subscriptions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._subscriptions_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._subscriptions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_timeline { + if self.opt.cmd_attachments_delete { + call_result = self._timeline_attachments_delete(dry_run, &mut err); + } else if self.opt.cmd_attachments_get { + call_result = self._timeline_attachments_get(dry_run, &mut err); + } else if self.opt.cmd_attachments_insert { + call_result = self._timeline_attachments_insert(dry_run, &mut err); + } else if self.opt.cmd_attachments_list { + call_result = self._timeline_attachments_list(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._timeline_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._timeline_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._timeline_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._timeline_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._timeline_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._timeline_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "mirror1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "mirror1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Mirror::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/oauth2_v2-cli/Cargo.toml b/gen/oauth2_v2-cli/Cargo.toml new file mode 100644 index 00000000000..508cb065170 --- /dev/null +++ b/gen/oauth2_v2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-oauth2_v2-cli" +version = "0.0.1+20150319" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with oauth2 (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/oauth2_v2-cli" +homepage = "https://developers.google.com/accounts/docs/OAuth2" +documentation = "http://byron.github.io/google-apis-rs/google_oauth2_v2_cli" +license = "MIT" +keywords = ["oauth2", "google", "cli"] + +[[bin]] +name = "oauth2-v2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-oauth2_v2] +path = "../oauth2_v2" diff --git a/gen/oauth2_v2-cli/LICENSE.md b/gen/oauth2_v2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/oauth2_v2-cli/LICENSE.md @@ -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. diff --git a/gen/oauth2_v2-cli/README.md b/gen/oauth2_v2-cli/README.md new file mode 100644 index 00000000000..06c3dae8b89 --- /dev/null +++ b/gen/oauth2_v2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO OAUTH2:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/oauth2_v2-cli/mkdocs.yml b/gen/oauth2_v2-cli/mkdocs.yml new file mode 100644 index 00000000000..dd47211a698 --- /dev/null +++ b/gen/oauth2_v2-cli/mkdocs.yml @@ -0,0 +1,20 @@ +site_name: oauth2 v0.0.1+20150319 +site_url: http://byron.github.io/google-apis-rs/google-oauth2_v2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/oauth2_v2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['methods_get-cert-for-open-id-connect.md', 'Methods', 'Get Cert For Open Id Connect'] +- ['methods_tokeninfo.md', 'Methods', 'Tokeninfo'] +- ['userinfo_get.md', 'Userinfo', 'Get'] +- ['userinfo_v2-me-get.md', 'Userinfo', 'V2 Me Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/oauth2_v2-cli/src/cmn.rs b/gen/oauth2_v2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/oauth2_v2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/oauth2_v2-cli/src/main.rs b/gen/oauth2_v2-cli/src/main.rs new file mode 100644 index 00000000000..884051a7d7d --- /dev/null +++ b/gen/oauth2_v2-cli/src/main.rs @@ -0,0 +1,327 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_oauth2_v2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + oauth2-v2 [options] methods get-cert-for-open-id-connect [-p <v>]... [-o <out>] + oauth2-v2 [options] methods tokeninfo [-p <v>]... [-o <out>] + oauth2-v2 [options] userinfo get [-p <v>]... [-o <out>] + oauth2-v2 [options] userinfo v2-me-get [-p <v>]... [-o <out>] + oauth2-v2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Oauth2<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _methods_get_cert_for_open_id_connect(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.methods().get_cert_for_open_id_connect(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _methods_tokeninfo(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.methods().tokeninfo(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "token-handle" => { + call = call.token_handle(value.unwrap_or("")); + }, + "id-token" => { + call = call.id_token(value.unwrap_or("")); + }, + "access-token" => { + call = call.access_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _userinfo_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.userinfo().get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _userinfo_v2_me_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.userinfo().v2_me_get(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_methods { + if self.opt.cmd_get_cert_for_open_id_connect { + call_result = self._methods_get_cert_for_open_id_connect(dry_run, &mut err); + } else if self.opt.cmd_tokeninfo { + call_result = self._methods_tokeninfo(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_userinfo { + if self.opt.cmd_get { + call_result = self._userinfo_get(dry_run, &mut err); + } else if self.opt.cmd_v2_me_get { + call_result = self._userinfo_v2_me_get(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "oauth2-v2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "oauth2-v2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Oauth2::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/pagespeedonline2-cli/Cargo.toml b/gen/pagespeedonline2-cli/Cargo.toml new file mode 100644 index 00000000000..466a6104b4b --- /dev/null +++ b/gen/pagespeedonline2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-pagespeedonline2-cli" +version = "0.0.1+20150317" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with pagespeedonline (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/pagespeedonline2-cli" +homepage = "https://developers.google.com/speed/docs/insights/v2/getting-started" +documentation = "http://byron.github.io/google-apis-rs/google_pagespeedonline2_cli" +license = "MIT" +keywords = ["pagespeedonline", "google", "cli"] + +[[bin]] +name = "pagespeedonline2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-pagespeedonline2] +path = "../pagespeedonline2" diff --git a/gen/pagespeedonline2-cli/LICENSE.md b/gen/pagespeedonline2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/pagespeedonline2-cli/LICENSE.md @@ -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. diff --git a/gen/pagespeedonline2-cli/README.md b/gen/pagespeedonline2-cli/README.md new file mode 100644 index 00000000000..01f2986fac4 --- /dev/null +++ b/gen/pagespeedonline2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO PAGESPEEDONLINE:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/pagespeedonline2-cli/mkdocs.yml b/gen/pagespeedonline2-cli/mkdocs.yml new file mode 100644 index 00000000000..e680d831db4 --- /dev/null +++ b/gen/pagespeedonline2-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: pagespeedonline v0.0.1+20150317 +site_url: http://byron.github.io/google-apis-rs/google-pagespeedonline2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/pagespeedonline2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['pagespeedapi_runpagespeed.md', 'Pagespeedapi', 'Runpagespeed'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/pagespeedonline2-cli/src/cmn.rs b/gen/pagespeedonline2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/pagespeedonline2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/pagespeedonline2-cli/src/main.rs b/gen/pagespeedonline2-cli/src/main.rs new file mode 100644 index 00000000000..22f591c66c2 --- /dev/null +++ b/gen/pagespeedonline2-cli/src/main.rs @@ -0,0 +1,184 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_pagespeedonline2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + pagespeedonline2 [options] pagespeedapi runpagespeed <url> [-p <v>]... [-o <out>] + pagespeedonline2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Pagespeedonline<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _pagespeedapi_runpagespeed(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.pagespeedapi().runpagespeed(&self.opt.arg_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "strategy" => { + call = call.strategy(value.unwrap_or("")); + }, + "screenshot" => { + call = call.screenshot(arg_from_str(value.unwrap_or("false"), err, "screenshot", "boolean")); + }, + "rule" => { + call = call.add_rule(value.unwrap_or("")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "filter-third-party-resources" => { + call = call.filter_third_party_resources(arg_from_str(value.unwrap_or("false"), err, "filter-third-party-resources", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_pagespeedapi { + if self.opt.cmd_runpagespeed { + call_result = self._pagespeedapi_runpagespeed(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "pagespeedonline2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "pagespeedonline2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Pagespeedonline::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/plus1-cli/Cargo.toml b/gen/plus1-cli/Cargo.toml new file mode 100644 index 00000000000..10dd5a516a6 --- /dev/null +++ b/gen/plus1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-plus1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with plus (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/plus1-cli" +homepage = "https://developers.google.com/+/api/" +documentation = "http://byron.github.io/google-apis-rs/google_plus1_cli" +license = "MIT" +keywords = ["plus", "google", "cli"] + +[[bin]] +name = "plus1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-plus1] +path = "../plus1" diff --git a/gen/plus1-cli/LICENSE.md b/gen/plus1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/plus1-cli/LICENSE.md @@ -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. diff --git a/gen/plus1-cli/README.md b/gen/plus1-cli/README.md new file mode 100644 index 00000000000..befbebc1fb3 --- /dev/null +++ b/gen/plus1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO PLUS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/plus1-cli/mkdocs.yml b/gen/plus1-cli/mkdocs.yml new file mode 100644 index 00000000000..690f0173cbd --- /dev/null +++ b/gen/plus1-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: plus v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-plus1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/plus1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_get.md', 'Activities', 'Get'] +- ['activities_list.md', 'Activities', 'List'] +- ['activities_search.md', 'Activities', 'Search'] +- ['comments_get.md', 'Comments', 'Get'] +- ['comments_list.md', 'Comments', 'List'] +- ['moments_insert.md', 'Moments', 'Insert'] +- ['moments_list.md', 'Moments', 'List'] +- ['moments_remove.md', 'Moments', 'Remove'] +- ['people_get.md', 'People', 'Get'] +- ['people_list.md', 'People', 'List'] +- ['people_list-by-activity.md', 'People', 'List By Activity'] +- ['people_search.md', 'People', 'Search'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/plus1-cli/src/cmn.rs b/gen/plus1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/plus1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/plus1-cli/src/main.rs b/gen/plus1-cli/src/main.rs new file mode 100644 index 00000000000..8f58c62b6a4 --- /dev/null +++ b/gen/plus1-cli/src/main.rs @@ -0,0 +1,1291 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_plus1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + plus1 [options] activities get <activity-id> [-p <v>]... [-o <out>] + plus1 [options] activities list <user-id> <collection> [-p <v>]... [-o <out>] + plus1 [options] activities search <query> [-p <v>]... [-o <out>] + plus1 [options] comments get <comment-id> [-p <v>]... [-o <out>] + plus1 [options] comments list <activity-id> [-p <v>]... [-o <out>] + plus1 [options] moments insert <user-id> <collection> -r <kv>... [-p <v>]... [-o <out>] + plus1 [options] moments list <user-id> <collection> [-p <v>]... [-o <out>] + plus1 [options] moments remove <id> [-p <v>]... + plus1 [options] people get <user-id> [-p <v>]... [-o <out>] + plus1 [options] people list <user-id> <collection> [-p <v>]... [-o <out>] + plus1 [options] people list-by-activity <activity-id> <collection> [-p <v>]... [-o <out>] + plus1 [options] people search <query> [-p <v>]... [-o <out>] + plus1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Plus<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _activities_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().get(&self.opt.arg_activity_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().list(&self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().search(&self.opt.arg_query); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().get(&self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().list(&self.opt.arg_activity_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _moments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Moment = Default::default(); + let mut call = self.hub.moments().insert(&request, &self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "debug" => { + call = call.debug(arg_from_str(value.unwrap_or("false"), err, "debug", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_object_init(request: &mut api::Moment) { + if request.object.is_none() { + request.object = Some(Default::default()); + } + } + + fn request_result_init(request: &mut api::Moment) { + if request.result.is_none() { + request.result = Some(Default::default()); + } + } + + fn request_target_init(request: &mut api::Moment) { + if request.target.is_none() { + request.target = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "start-date" => { + request.start_date = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "target.start-date" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "target.end-date" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "target.text" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "target.image" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "target.birth-date" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().birth_date = value.unwrap_or("").to_string(); + }, + "target.date-published" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().date_published = value.unwrap_or("").to_string(); + }, + "target.address-locality" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().address_locality = value.unwrap_or("").to_string(); + }, + "target.additional-name" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().additional_name.push(value.unwrap_or("").to_string()); + }, + "target.worst-rating" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().worst_rating = value.unwrap_or("").to_string(); + }, + "target.duration" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().duration = value.unwrap_or("").to_string(); + }, + "target.thumbnail-url" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().thumbnail_url = value.unwrap_or("").to_string(); + }, + "target.id" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "target.post-office-box-number" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().post_office_box_number = value.unwrap_or("").to_string(); + }, + "target.caption" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().caption = value.unwrap_or("").to_string(); + }, + "target.best-rating" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().best_rating = value.unwrap_or("").to_string(); + }, + "target.address-country" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().address_country = arg_from_str(value.unwrap_or("-0"), err, "target.address-country", "int64"); + }, + "target.width" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().width = value.unwrap_or("").to_string(); + }, + "target.street-address" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().street_address = value.unwrap_or("").to_string(); + }, + "target.latitude" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "target.latitude", "number"); + }, + "target.embed-url" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().embed_url = value.unwrap_or("").to_string(); + }, + "target.type" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "target.date-modified" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().date_modified = value.unwrap_or("").to_string(); + }, + "target.content-size" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().content_size = value.unwrap_or("").to_string(); + }, + "target.content-url" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().content_url = value.unwrap_or("").to_string(); + }, + "target.description" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "target.family-name" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "target.date-created" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().date_created = value.unwrap_or("").to_string(); + }, + "target.postal-code" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "target.attendee-count" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().attendee_count = arg_from_str(value.unwrap_or("-0"), err, "target.attendee-count", "integer"); + }, + "target.height" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().height = value.unwrap_or("").to_string(); + }, + "target.ticker-symbol" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().ticker_symbol = value.unwrap_or("").to_string(); + }, + "target.player-type" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().player_type = value.unwrap_or("").to_string(); + }, + "target.kind" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "target.name" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "target.url" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "target.gender" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().gender = value.unwrap_or("").to_string(); + }, + "target.longitude" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "target.longitude", "number"); + }, + "target.address-region" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().address_region = value.unwrap_or("").to_string(); + }, + "target.rating-value" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().rating_value = value.unwrap_or("").to_string(); + }, + "target.given-name" => { + request_target_init(&mut request); + request.target.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "object.start-date" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "object.end-date" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "object.text" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "object.image" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "object.birth-date" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().birth_date = value.unwrap_or("").to_string(); + }, + "object.date-published" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().date_published = value.unwrap_or("").to_string(); + }, + "object.address-locality" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().address_locality = value.unwrap_or("").to_string(); + }, + "object.additional-name" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().additional_name.push(value.unwrap_or("").to_string()); + }, + "object.worst-rating" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().worst_rating = value.unwrap_or("").to_string(); + }, + "object.duration" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().duration = value.unwrap_or("").to_string(); + }, + "object.thumbnail-url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().thumbnail_url = value.unwrap_or("").to_string(); + }, + "object.id" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "object.post-office-box-number" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().post_office_box_number = value.unwrap_or("").to_string(); + }, + "object.caption" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().caption = value.unwrap_or("").to_string(); + }, + "object.best-rating" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().best_rating = value.unwrap_or("").to_string(); + }, + "object.address-country" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().address_country = arg_from_str(value.unwrap_or("-0"), err, "object.address-country", "int64"); + }, + "object.width" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().width = value.unwrap_or("").to_string(); + }, + "object.street-address" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().street_address = value.unwrap_or("").to_string(); + }, + "object.latitude" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "object.latitude", "number"); + }, + "object.embed-url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().embed_url = value.unwrap_or("").to_string(); + }, + "object.type" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "object.date-modified" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().date_modified = value.unwrap_or("").to_string(); + }, + "object.content-size" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().content_size = value.unwrap_or("").to_string(); + }, + "object.content-url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().content_url = value.unwrap_or("").to_string(); + }, + "object.description" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "object.family-name" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "object.date-created" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().date_created = value.unwrap_or("").to_string(); + }, + "object.postal-code" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "object.attendee-count" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().attendee_count = arg_from_str(value.unwrap_or("-0"), err, "object.attendee-count", "integer"); + }, + "object.height" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().height = value.unwrap_or("").to_string(); + }, + "object.ticker-symbol" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().ticker_symbol = value.unwrap_or("").to_string(); + }, + "object.player-type" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().player_type = value.unwrap_or("").to_string(); + }, + "object.kind" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "object.name" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "object.url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "object.gender" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().gender = value.unwrap_or("").to_string(); + }, + "object.longitude" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "object.longitude", "number"); + }, + "object.address-region" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().address_region = value.unwrap_or("").to_string(); + }, + "object.rating-value" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().rating_value = value.unwrap_or("").to_string(); + }, + "object.given-name" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "result.start-date" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().start_date = value.unwrap_or("").to_string(); + }, + "result.end-date" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().end_date = value.unwrap_or("").to_string(); + }, + "result.text" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().text = value.unwrap_or("").to_string(); + }, + "result.image" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().image = value.unwrap_or("").to_string(); + }, + "result.birth-date" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().birth_date = value.unwrap_or("").to_string(); + }, + "result.date-published" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().date_published = value.unwrap_or("").to_string(); + }, + "result.address-locality" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().address_locality = value.unwrap_or("").to_string(); + }, + "result.additional-name" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().additional_name.push(value.unwrap_or("").to_string()); + }, + "result.worst-rating" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().worst_rating = value.unwrap_or("").to_string(); + }, + "result.duration" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().duration = value.unwrap_or("").to_string(); + }, + "result.thumbnail-url" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().thumbnail_url = value.unwrap_or("").to_string(); + }, + "result.id" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "result.post-office-box-number" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().post_office_box_number = value.unwrap_or("").to_string(); + }, + "result.caption" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().caption = value.unwrap_or("").to_string(); + }, + "result.best-rating" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().best_rating = value.unwrap_or("").to_string(); + }, + "result.address-country" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().address_country = arg_from_str(value.unwrap_or("-0"), err, "result.address-country", "int64"); + }, + "result.width" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().width = value.unwrap_or("").to_string(); + }, + "result.street-address" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().street_address = value.unwrap_or("").to_string(); + }, + "result.latitude" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().latitude = arg_from_str(value.unwrap_or("0.0"), err, "result.latitude", "number"); + }, + "result.embed-url" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().embed_url = value.unwrap_or("").to_string(); + }, + "result.type" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "result.date-modified" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().date_modified = value.unwrap_or("").to_string(); + }, + "result.content-size" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().content_size = value.unwrap_or("").to_string(); + }, + "result.content-url" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().content_url = value.unwrap_or("").to_string(); + }, + "result.description" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "result.family-name" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().family_name = value.unwrap_or("").to_string(); + }, + "result.date-created" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().date_created = value.unwrap_or("").to_string(); + }, + "result.postal-code" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "result.attendee-count" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().attendee_count = arg_from_str(value.unwrap_or("-0"), err, "result.attendee-count", "integer"); + }, + "result.height" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().height = value.unwrap_or("").to_string(); + }, + "result.ticker-symbol" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().ticker_symbol = value.unwrap_or("").to_string(); + }, + "result.player-type" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().player_type = value.unwrap_or("").to_string(); + }, + "result.kind" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "result.name" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "result.url" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "result.gender" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().gender = value.unwrap_or("").to_string(); + }, + "result.longitude" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().longitude = arg_from_str(value.unwrap_or("0.0"), err, "result.longitude", "number"); + }, + "result.address-region" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().address_region = value.unwrap_or("").to_string(); + }, + "result.rating-value" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().rating_value = value.unwrap_or("").to_string(); + }, + "result.given-name" => { + request_result_init(&mut request); + request.result.as_mut().unwrap().given_name = value.unwrap_or("").to_string(); + }, + "type" => { + request_result_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_result_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _moments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.moments().list(&self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "target-url" => { + call = call.target_url(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _moments_remove(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.moments().remove(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _people_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().get(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().list(&self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_list_by_activity(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().list_by_activity(&self.opt.arg_activity_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().search(&self.opt.arg_query); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "language" => { + call = call.language(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_activities { + if self.opt.cmd_get { + call_result = self._activities_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._activities_search(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_comments { + if self.opt.cmd_get { + call_result = self._comments_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._comments_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_moments { + if self.opt.cmd_insert { + call_result = self._moments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._moments_list(dry_run, &mut err); + } else if self.opt.cmd_remove { + call_result = self._moments_remove(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_people { + if self.opt.cmd_get { + call_result = self._people_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._people_list(dry_run, &mut err); + } else if self.opt.cmd_list_by_activity { + call_result = self._people_list_by_activity(dry_run, &mut err); + } else if self.opt.cmd_search { + call_result = self._people_search(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "plus1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "plus1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Plus::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/plusdomains1-cli/Cargo.toml b/gen/plusdomains1-cli/Cargo.toml new file mode 100644 index 00000000000..f50b745d3e4 --- /dev/null +++ b/gen/plusdomains1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-plusdomains1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with plusDomains (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/plusdomains1-cli" +homepage = "https://developers.google.com/+/domains/" +documentation = "http://byron.github.io/google-apis-rs/google_plusdomains1_cli" +license = "MIT" +keywords = ["plusDomains", "google", "cli"] + +[[bin]] +name = "plusdomains1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-plusdomains1] +path = "../plusdomains1" diff --git a/gen/plusdomains1-cli/LICENSE.md b/gen/plusdomains1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/plusdomains1-cli/LICENSE.md @@ -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. diff --git a/gen/plusdomains1-cli/README.md b/gen/plusdomains1-cli/README.md new file mode 100644 index 00000000000..6567d52c4e7 --- /dev/null +++ b/gen/plusdomains1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO PLUSDOMAINS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/plusdomains1-cli/mkdocs.yml b/gen/plusdomains1-cli/mkdocs.yml new file mode 100644 index 00000000000..a811f45280d --- /dev/null +++ b/gen/plusdomains1-cli/mkdocs.yml @@ -0,0 +1,36 @@ +site_name: plusDomains v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-plusdomains1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/plusdomains1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_get.md', 'Activities', 'Get'] +- ['activities_insert.md', 'Activities', 'Insert'] +- ['activities_list.md', 'Activities', 'List'] +- ['audiences_list.md', 'Audiences', 'List'] +- ['circles_add-people.md', 'Circles', 'Add People'] +- ['circles_get.md', 'Circles', 'Get'] +- ['circles_insert.md', 'Circles', 'Insert'] +- ['circles_list.md', 'Circles', 'List'] +- ['circles_patch.md', 'Circles', 'Patch'] +- ['circles_remove.md', 'Circles', 'Remove'] +- ['circles_remove-people.md', 'Circles', 'Remove People'] +- ['circles_update.md', 'Circles', 'Update'] +- ['comments_get.md', 'Comments', 'Get'] +- ['comments_insert.md', 'Comments', 'Insert'] +- ['comments_list.md', 'Comments', 'List'] +- ['media_insert.md', 'Media', 'Insert'] +- ['people_get.md', 'People', 'Get'] +- ['people_list.md', 'People', 'List'] +- ['people_list-by-activity.md', 'People', 'List By Activity'] +- ['people_list-by-circle.md', 'People', 'List By Circle'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/plusdomains1-cli/src/cmn.rs b/gen/plusdomains1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/plusdomains1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/plusdomains1-cli/src/main.rs b/gen/plusdomains1-cli/src/main.rs new file mode 100644 index 00000000000..0547bf7c54e --- /dev/null +++ b/gen/plusdomains1-cli/src/main.rs @@ -0,0 +1,1725 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_plusdomains1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + plusdomains1 [options] activities get <activity-id> [-p <v>]... [-o <out>] + plusdomains1 [options] activities insert <user-id> -r <kv>... [-p <v>]... [-o <out>] + plusdomains1 [options] activities list <user-id> <collection> [-p <v>]... [-o <out>] + plusdomains1 [options] audiences list <user-id> [-p <v>]... [-o <out>] + plusdomains1 [options] circles add-people <circle-id> [-p <v>]... [-o <out>] + plusdomains1 [options] circles get <circle-id> [-p <v>]... [-o <out>] + plusdomains1 [options] circles insert <user-id> -r <kv>... [-p <v>]... [-o <out>] + plusdomains1 [options] circles list <user-id> [-p <v>]... [-o <out>] + plusdomains1 [options] circles patch <circle-id> -r <kv>... [-p <v>]... [-o <out>] + plusdomains1 [options] circles remove <circle-id> [-p <v>]... + plusdomains1 [options] circles remove-people <circle-id> [-p <v>]... + plusdomains1 [options] circles update <circle-id> -r <kv>... [-p <v>]... [-o <out>] + plusdomains1 [options] comments get <comment-id> [-p <v>]... [-o <out>] + plusdomains1 [options] comments insert <activity-id> -r <kv>... [-p <v>]... [-o <out>] + plusdomains1 [options] comments list <activity-id> [-p <v>]... [-o <out>] + plusdomains1 [options] media insert <user-id> <collection> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + plusdomains1 [options] people get <user-id> [-p <v>]... [-o <out>] + plusdomains1 [options] people list <user-id> <collection> [-p <v>]... [-o <out>] + plusdomains1 [options] people list-by-activity <activity-id> <collection> [-p <v>]... [-o <out>] + plusdomains1 [options] people list-by-circle <circle-id> [-p <v>]... [-o <out>] + plusdomains1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::PlusDomains<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _activities_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().get(&self.opt.arg_activity_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Activity = Default::default(); + let mut call = self.hub.activities().insert(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "preview" => { + call = call.preview(arg_from_str(value.unwrap_or("false"), err, "preview", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_access_init(request: &mut api::Activity) { + if request.access.is_none() { + request.access = Some(Default::default()); + } + } + + fn request_actor_init(request: &mut api::Activity) { + if request.actor.is_none() { + request.actor = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::Activity) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_object_init(request: &mut api::Activity) { + if request.object.is_none() { + request.object = Some(Default::default()); + } + } + + fn request_provider_init(request: &mut api::Activity) { + if request.provider.is_none() { + request.provider = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "place-name" => { + request.place_name = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "provider.title" => { + request_provider_init(&mut request); + request.provider.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "title" => { + request_provider_init(&mut request); + request.title = Some(value.unwrap_or("").to_string()); + }, + "url" => { + request_provider_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "geocode" => { + request_provider_init(&mut request); + request.geocode = Some(value.unwrap_or("").to_string()); + }, + "object.resharers.total-items" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().resharers.total_items = arg_from_str(value.unwrap_or("-0"), err, "object.resharers.total-items", "integer"); + }, + "object.resharers.self-link" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().resharers.self_link = value.unwrap_or("").to_string(); + }, + "object.original-content" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().original_content = value.unwrap_or("").to_string(); + }, + "object.plusoners.total-items" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().plusoners.total_items = arg_from_str(value.unwrap_or("-0"), err, "object.plusoners.total-items", "integer"); + }, + "object.plusoners.self-link" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().plusoners.self_link = value.unwrap_or("").to_string(); + }, + "object.actor.url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().actor.url = value.unwrap_or("").to_string(); + }, + "object.actor.image.url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().actor.image.url = value.unwrap_or("").to_string(); + }, + "object.actor.display-name" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().actor.display_name = value.unwrap_or("").to_string(); + }, + "object.actor.id" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().actor.id = value.unwrap_or("").to_string(); + }, + "object.content" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().content = value.unwrap_or("").to_string(); + }, + "object.url" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "object.status-for-viewer.can-plusone" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().status_for_viewer.can_plusone = arg_from_str(value.unwrap_or("false"), err, "object.status-for-viewer.can-plusone", "boolean"); + }, + "object.status-for-viewer.can-update" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().status_for_viewer.can_update = arg_from_str(value.unwrap_or("false"), err, "object.status-for-viewer.can-update", "boolean"); + }, + "object.status-for-viewer.is-plus-oned" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().status_for_viewer.is_plus_oned = arg_from_str(value.unwrap_or("false"), err, "object.status-for-viewer.is-plus-oned", "boolean"); + }, + "object.status-for-viewer.resharing-disabled" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().status_for_viewer.resharing_disabled = arg_from_str(value.unwrap_or("false"), err, "object.status-for-viewer.resharing-disabled", "boolean"); + }, + "object.status-for-viewer.can-comment" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().status_for_viewer.can_comment = arg_from_str(value.unwrap_or("false"), err, "object.status-for-viewer.can-comment", "boolean"); + }, + "object.replies.total-items" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().replies.total_items = arg_from_str(value.unwrap_or("-0"), err, "object.replies.total-items", "integer"); + }, + "object.replies.self-link" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().replies.self_link = value.unwrap_or("").to_string(); + }, + "object.id" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "object.object-type" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().object_type = value.unwrap_or("").to_string(); + }, + "kind" => { + request_object_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "actor.url" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "actor.image.url" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "actor.display-name" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "actor.id" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "actor.name.given-name" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().name.given_name = value.unwrap_or("").to_string(); + }, + "actor.name.family-name" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().name.family_name = value.unwrap_or("").to_string(); + }, + "place-id" => { + request_actor_init(&mut request); + request.place_id = Some(value.unwrap_or("").to_string()); + }, + "access.kind" => { + request_access_init(&mut request); + request.access.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "access.description" => { + request_access_init(&mut request); + request.access.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "access.domain-restricted" => { + request_access_init(&mut request); + request.access.as_mut().unwrap().domain_restricted = arg_from_str(value.unwrap_or("false"), err, "access.domain-restricted", "boolean"); + }, + "etag" => { + request_access_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "radius" => { + request_access_init(&mut request); + request.radius = Some(value.unwrap_or("").to_string()); + }, + "location.position.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().position.latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.position.latitude", "number"); + }, + "location.position.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().position.longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.position.longitude", "number"); + }, + "location.kind" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "location.display-name" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "location.id" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "location.address.formatted" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().address.formatted = value.unwrap_or("").to_string(); + }, + "verb" => { + request_location_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_location_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "crosspost-source" => { + request_location_init(&mut request); + request.crosspost_source = Some(value.unwrap_or("").to_string()); + }, + "annotation" => { + request_location_init(&mut request); + request.annotation = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request_location_init(&mut request); + request.address = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_location_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().list(&self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _audiences_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.audiences().list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_add_people(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.circles().add_people(&self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-id" => { + call = call.add_user_id(value.unwrap_or("")); + }, + "email" => { + call = call.add_email(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.circles().get(&self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Circle = Default::default(); + let mut call = self.hub.circles().insert(&request, &self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_people_init(request: &mut api::Circle) { + if request.people.is_none() { + request.people = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "people.total-items" => { + request_people_init(&mut request); + request.people.as_mut().unwrap().total_items = arg_from_str(value.unwrap_or("-0"), err, "people.total-items", "integer"); + }, + "etag" => { + request_people_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_people_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_people_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.circles().list(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Circle = Default::default(); + let mut call = self.hub.circles().patch(&request, &self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_people_init(request: &mut api::Circle) { + if request.people.is_none() { + request.people = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "people.total-items" => { + request_people_init(&mut request); + request.people.as_mut().unwrap().total_items = arg_from_str(value.unwrap_or("-0"), err, "people.total-items", "integer"); + }, + "etag" => { + request_people_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_people_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_people_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _circles_remove(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.circles().remove(&self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _circles_remove_people(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.circles().remove_people(&self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "user-id" => { + call = call.add_user_id(value.unwrap_or("")); + }, + "email" => { + call = call.add_email(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _circles_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Circle = Default::default(); + let mut call = self.hub.circles().update(&request, &self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_people_init(request: &mut api::Circle) { + if request.people.is_none() { + request.people = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "people.total-items" => { + request_people_init(&mut request); + request.people.as_mut().unwrap().total_items = arg_from_str(value.unwrap_or("-0"), err, "people.total-items", "integer"); + }, + "etag" => { + request_people_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_people_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_people_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().get(&self.opt.arg_comment_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Comment = Default::default(); + let mut call = self.hub.comments().insert(&request, &self.opt.arg_activity_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_actor_init(request: &mut api::Comment) { + if request.actor.is_none() { + request.actor = Some(Default::default()); + } + } + + fn request_object_init(request: &mut api::Comment) { + if request.object.is_none() { + request.object = Some(Default::default()); + } + } + + fn request_plusoners_init(request: &mut api::Comment) { + if request.plusoners.is_none() { + request.plusoners = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "plusoners.total-items" => { + request_plusoners_init(&mut request); + request.plusoners.as_mut().unwrap().total_items = arg_from_str(value.unwrap_or("-0"), err, "plusoners.total-items", "integer"); + }, + "object.content" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().content = value.unwrap_or("").to_string(); + }, + "object.original-content" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().original_content = value.unwrap_or("").to_string(); + }, + "object.object-type" => { + request_object_init(&mut request); + request.object.as_mut().unwrap().object_type = value.unwrap_or("").to_string(); + }, + "updated" => { + request_object_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "actor.url" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "actor.image.url" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "actor.display-name" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "actor.id" => { + request_actor_init(&mut request); + request.actor.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "verb" => { + request_actor_init(&mut request); + request.verb = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_actor_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_actor_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_actor_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_actor_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _comments_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.comments().list(&self.opt.arg_activity_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort-order" => { + call = call.sort_order(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _media_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Media = Default::default(); + let mut call = self.hub.media().insert(&request, &self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_author_init(request: &mut api::Media) { + if request.author.is_none() { + request.author = Some(Default::default()); + } + } + + fn request_exif_init(request: &mut api::Media) { + if request.exif.is_none() { + request.exif = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "display-name" => { + request.display_name = Some(value.unwrap_or("").to_string()); + }, + "exif.time" => { + request_exif_init(&mut request); + request.exif.as_mut().unwrap().time = value.unwrap_or("").to_string(); + }, + "author.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().url = value.unwrap_or("").to_string(); + }, + "author.image.url" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().image.url = value.unwrap_or("").to_string(); + }, + "author.display-name" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().display_name = value.unwrap_or("").to_string(); + }, + "author.id" => { + request_author_init(&mut request); + request.author.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "url" => { + request_author_init(&mut request); + request.url = Some(value.unwrap_or("").to_string()); + }, + "media-url" => { + request_author_init(&mut request); + request.media_url = Some(value.unwrap_or("").to_string()); + }, + "video-status" => { + request_author_init(&mut request); + request.video_status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_author_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "height" => { + request_author_init(&mut request); + request.height = Some(arg_from_str(value.unwrap_or("-0"), err, "height", "integer")); + }, + "video-duration" => { + request_author_init(&mut request); + request.video_duration = Some(value.unwrap_or("").to_string()); + }, + "size-bytes" => { + request_author_init(&mut request); + request.size_bytes = Some(value.unwrap_or("").to_string()); + }, + "width" => { + request_author_init(&mut request); + request.width = Some(arg_from_str(value.unwrap_or("-0"), err, "width", "integer")); + }, + "summary" => { + request_author_init(&mut request); + request.summary = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_author_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "published" => { + request_author_init(&mut request); + request.published = Some(value.unwrap_or("").to_string()); + }, + "media-created-time" => { + request_author_init(&mut request); + request.media_created_time = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_author_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().get(&self.opt.arg_user_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().list(&self.opt.arg_user_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order-by" => { + call = call.order_by(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_list_by_activity(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().list_by_activity(&self.opt.arg_activity_id, &self.opt.arg_collection); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _people_list_by_circle(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.people().list_by_circle(&self.opt.arg_circle_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_activities { + if self.opt.cmd_get { + call_result = self._activities_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._activities_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_audiences { + if self.opt.cmd_list { + call_result = self._audiences_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_circles { + if self.opt.cmd_add_people { + call_result = self._circles_add_people(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._circles_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._circles_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._circles_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._circles_patch(dry_run, &mut err); + } else if self.opt.cmd_remove { + call_result = self._circles_remove(dry_run, &mut err); + } else if self.opt.cmd_remove_people { + call_result = self._circles_remove_people(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._circles_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_comments { + if self.opt.cmd_get { + call_result = self._comments_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._comments_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._comments_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_media { + if self.opt.cmd_insert { + call_result = self._media_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_people { + if self.opt.cmd_get { + call_result = self._people_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._people_list(dry_run, &mut err); + } else if self.opt.cmd_list_by_activity { + call_result = self._people_list_by_activity(dry_run, &mut err); + } else if self.opt.cmd_list_by_circle { + call_result = self._people_list_by_circle(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "plusdomains1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "plusdomains1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::PlusDomains::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/prediction1d6-cli/Cargo.toml b/gen/prediction1d6-cli/Cargo.toml new file mode 100644 index 00000000000..b3c84fd7155 --- /dev/null +++ b/gen/prediction1d6-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-prediction1d6-cli" +version = "0.0.1+20140522" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with prediction (protocol v1.6)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/prediction1d6-cli" +homepage = "https://developers.google.com/prediction/docs/developer-guide" +documentation = "http://byron.github.io/google-apis-rs/google_prediction1d6_cli" +license = "MIT" +keywords = ["prediction", "google", "cli"] + +[[bin]] +name = "prediction1d6" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-prediction1d6] +path = "../prediction1d6" diff --git a/gen/prediction1d6-cli/LICENSE.md b/gen/prediction1d6-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/prediction1d6-cli/LICENSE.md @@ -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. diff --git a/gen/prediction1d6-cli/README.md b/gen/prediction1d6-cli/README.md new file mode 100644 index 00000000000..77a70ce2d2c --- /dev/null +++ b/gen/prediction1d6-cli/README.md @@ -0,0 +1,4 @@ +# HELLO PREDICTION:V1.6 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/prediction1d6-cli/mkdocs.yml b/gen/prediction1d6-cli/mkdocs.yml new file mode 100644 index 00000000000..61cb4baff05 --- /dev/null +++ b/gen/prediction1d6-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: prediction v0.0.1+20140522 +site_url: http://byron.github.io/google-apis-rs/google-prediction1d6-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/prediction1d6-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['hostedmodels_predict.md', 'Hostedmodels', 'Predict'] +- ['trainedmodels_analyze.md', 'Trainedmodels', 'Analyze'] +- ['trainedmodels_delete.md', 'Trainedmodels', 'Delete'] +- ['trainedmodels_get.md', 'Trainedmodels', 'Get'] +- ['trainedmodels_insert.md', 'Trainedmodels', 'Insert'] +- ['trainedmodels_list.md', 'Trainedmodels', 'List'] +- ['trainedmodels_predict.md', 'Trainedmodels', 'Predict'] +- ['trainedmodels_update.md', 'Trainedmodels', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/prediction1d6-cli/src/cmn.rs b/gen/prediction1d6-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/prediction1d6-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/prediction1d6-cli/src/main.rs b/gen/prediction1d6-cli/src/main.rs new file mode 100644 index 00000000000..fc7f7a1f4d7 --- /dev/null +++ b/gen/prediction1d6-cli/src/main.rs @@ -0,0 +1,583 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_prediction1d6 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + prediction1d6 [options] hostedmodels predict <project> <hosted-model-name> -r <kv>... [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels analyze <project> <id> [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels delete <project> <id> [-p <v>]... + prediction1d6 [options] trainedmodels get <project> <id> [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels insert <project> -r <kv>... [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels list <project> [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels predict <project> <id> -r <kv>... [-p <v>]... [-o <out>] + prediction1d6 [options] trainedmodels update <project> <id> -r <kv>... [-p <v>]... [-o <out>] + prediction1d6 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Prediction<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _hostedmodels_predict(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Input = Default::default(); + let mut call = self.hub.hostedmodels().predict(&request, &self.opt.arg_project, &self.opt.arg_hosted_model_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_analyze(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.trainedmodels().analyze(&self.opt.arg_project, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.trainedmodels().delete(&self.opt.arg_project, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _trainedmodels_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.trainedmodels().get(&self.opt.arg_project, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Insert = Default::default(); + let mut call = self.hub.trainedmodels().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "storage-data-location" => { + request.storage_data_location = Some(value.unwrap_or("").to_string()); + }, + "model-type" => { + request.model_type = Some(value.unwrap_or("").to_string()); + }, + "storage-pmml-model-location" => { + request.storage_pmml_model_location = Some(value.unwrap_or("").to_string()); + }, + "source-model" => { + request.source_model = Some(value.unwrap_or("").to_string()); + }, + "storage-pmml-location" => { + request.storage_pmml_location = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.trainedmodels().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_predict(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Input = Default::default(); + let mut call = self.hub.trainedmodels().predict(&request, &self.opt.arg_project, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _trainedmodels_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Update = Default::default(); + let mut call = self.hub.trainedmodels().update(&request, &self.opt.arg_project, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "output" => { + request.output = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_hostedmodels { + if self.opt.cmd_predict { + call_result = self._hostedmodels_predict(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_trainedmodels { + if self.opt.cmd_analyze { + call_result = self._trainedmodels_analyze(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._trainedmodels_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._trainedmodels_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._trainedmodels_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._trainedmodels_list(dry_run, &mut err); + } else if self.opt.cmd_predict { + call_result = self._trainedmodels_predict(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._trainedmodels_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "prediction1d6-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "prediction1d6", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Prediction::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/pubsub1_beta2-cli/Cargo.toml b/gen/pubsub1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..366ccbd5a2b --- /dev/null +++ b/gen/pubsub1_beta2-cli/Cargo.toml @@ -0,0 +1,29 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-pubsub1_beta2-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with pubsub (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/pubsub1_beta2-cli" +documentation = "http://byron.github.io/google-apis-rs/google_pubsub1_beta2_cli" +license = "MIT" +keywords = ["pubsub", "google", "cli"] + +[[bin]] +name = "pubsub1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-pubsub1_beta2] +path = "../pubsub1_beta2" diff --git a/gen/pubsub1_beta2-cli/LICENSE.md b/gen/pubsub1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/pubsub1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/pubsub1_beta2-cli/README.md b/gen/pubsub1_beta2-cli/README.md new file mode 100644 index 00000000000..ec8932c2fd3 --- /dev/null +++ b/gen/pubsub1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO PUBSUB:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/pubsub1_beta2-cli/mkdocs.yml b/gen/pubsub1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..f92e8ae4a19 --- /dev/null +++ b/gen/pubsub1_beta2-cli/mkdocs.yml @@ -0,0 +1,30 @@ +site_name: pubsub v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-pubsub1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/pubsub1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['projects_subscriptions-acknowledge.md', 'Projects', 'Subscriptions Acknowledge'] +- ['projects_subscriptions-create.md', 'Projects', 'Subscriptions Create'] +- ['projects_subscriptions-delete.md', 'Projects', 'Subscriptions Delete'] +- ['projects_subscriptions-get.md', 'Projects', 'Subscriptions Get'] +- ['projects_subscriptions-list.md', 'Projects', 'Subscriptions List'] +- ['projects_subscriptions-modify-ack-deadline.md', 'Projects', 'Subscriptions Modify Ack Deadline'] +- ['projects_subscriptions-modify-push-config.md', 'Projects', 'Subscriptions Modify Push Config'] +- ['projects_subscriptions-pull.md', 'Projects', 'Subscriptions Pull'] +- ['projects_topics-create.md', 'Projects', 'Topics Create'] +- ['projects_topics-delete.md', 'Projects', 'Topics Delete'] +- ['projects_topics-get.md', 'Projects', 'Topics Get'] +- ['projects_topics-list.md', 'Projects', 'Topics List'] +- ['projects_topics-publish.md', 'Projects', 'Topics Publish'] +- ['projects_topics-subscriptions-list.md', 'Projects', 'Topics Subscriptions List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/pubsub1_beta2-cli/src/cmn.rs b/gen/pubsub1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/pubsub1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/pubsub1_beta2-cli/src/main.rs b/gen/pubsub1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..94dda153fe7 --- /dev/null +++ b/gen/pubsub1_beta2-cli/src/main.rs @@ -0,0 +1,952 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_pubsub1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + pubsub1-beta2 [options] projects subscriptions-acknowledge <subscription> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-create <name> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-delete <subscription> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-get <subscription> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-list <project> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-modify-ack-deadline <subscription> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-modify-push-config <subscription> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects subscriptions-pull <subscription> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-create <name> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-delete <topic> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-get <topic> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-list <project> [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-publish <topic> -r <kv>... [-p <v>]... [-o <out>] + pubsub1-beta2 [options] projects topics-subscriptions-list <topic> [-p <v>]... [-o <out>] + pubsub1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Pubsub<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _projects_subscriptions_acknowledge(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::AcknowledgeRequest = Default::default(); + let mut call = self.hub.projects().subscriptions_acknowledge(&request, &self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ack-ids" => { + if request.ack_ids.is_none() { + request.ack_ids = Some(Default::default()); + } + request.ack_ids.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subscription = Default::default(); + let mut call = self.hub.projects().subscriptions_create(&request, &self.opt.arg_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_push_config_init(request: &mut api::Subscription) { + if request.push_config.is_none() { + request.push_config = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "ack-deadline-seconds" => { + request.ack_deadline_seconds = Some(arg_from_str(value.unwrap_or("-0"), err, "ack-deadline-seconds", "integer")); + }, + "topic" => { + request.topic = Some(value.unwrap_or("").to_string()); + }, + "push-config.attributes" => { + request_push_config_init(&mut request); + request.push_config.as_mut().unwrap().attributes.push(value.unwrap_or("").to_string()); + }, + "push-config.push-endpoint" => { + request_push_config_init(&mut request); + request.push_config.as_mut().unwrap().push_endpoint = value.unwrap_or("").to_string(); + }, + "name" => { + request_push_config_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().subscriptions_delete(&self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().subscriptions_get(&self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().subscriptions_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_modify_ack_deadline(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ModifyAckDeadlineRequest = Default::default(); + let mut call = self.hub.projects().subscriptions_modify_ack_deadline(&request, &self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "ack-deadline-seconds" => { + request.ack_deadline_seconds = Some(arg_from_str(value.unwrap_or("-0"), err, "ack-deadline-seconds", "integer")); + }, + "ack-id" => { + request.ack_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_modify_push_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ModifyPushConfigRequest = Default::default(); + let mut call = self.hub.projects().subscriptions_modify_push_config(&request, &self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_push_config_init(request: &mut api::ModifyPushConfigRequest) { + if request.push_config.is_none() { + request.push_config = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "push-config.attributes" => { + request_push_config_init(&mut request); + request.push_config.as_mut().unwrap().attributes.push(value.unwrap_or("").to_string()); + }, + "push-config.push-endpoint" => { + request_push_config_init(&mut request); + request.push_config.as_mut().unwrap().push_endpoint = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_subscriptions_pull(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PullRequest = Default::default(); + let mut call = self.hub.projects().subscriptions_pull(&request, &self.opt.arg_subscription); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "return-immediately" => { + request.return_immediately = Some(arg_from_str(value.unwrap_or("false"), err, "return-immediately", "boolean")); + }, + "max-messages" => { + request.max_messages = Some(arg_from_str(value.unwrap_or("-0"), err, "max-messages", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Topic = Default::default(); + let mut call = self.hub.projects().topics_create(&request, &self.opt.arg_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().topics_delete(&self.opt.arg_topic); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().topics_get(&self.opt.arg_topic); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().topics_list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PublishRequest = Default::default(); + let mut call = self.hub.projects().topics_publish(&request, &self.opt.arg_topic); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _projects_topics_subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.projects().topics_subscriptions_list(&self.opt.arg_topic); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "page-size" => { + call = call.page_size(arg_from_str(value.unwrap_or("-0"), err, "page-size", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_projects { + if self.opt.cmd_subscriptions_acknowledge { + call_result = self._projects_subscriptions_acknowledge(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_create { + call_result = self._projects_subscriptions_create(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_delete { + call_result = self._projects_subscriptions_delete(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_get { + call_result = self._projects_subscriptions_get(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_list { + call_result = self._projects_subscriptions_list(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_modify_ack_deadline { + call_result = self._projects_subscriptions_modify_ack_deadline(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_modify_push_config { + call_result = self._projects_subscriptions_modify_push_config(dry_run, &mut err); + } else if self.opt.cmd_subscriptions_pull { + call_result = self._projects_subscriptions_pull(dry_run, &mut err); + } else if self.opt.cmd_topics_create { + call_result = self._projects_topics_create(dry_run, &mut err); + } else if self.opt.cmd_topics_delete { + call_result = self._projects_topics_delete(dry_run, &mut err); + } else if self.opt.cmd_topics_get { + call_result = self._projects_topics_get(dry_run, &mut err); + } else if self.opt.cmd_topics_list { + call_result = self._projects_topics_list(dry_run, &mut err); + } else if self.opt.cmd_topics_publish { + call_result = self._projects_topics_publish(dry_run, &mut err); + } else if self.opt.cmd_topics_subscriptions_list { + call_result = self._projects_topics_subscriptions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "pubsub1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "pubsub1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Pubsub::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/qpxexpress1-cli/Cargo.toml b/gen/qpxexpress1-cli/Cargo.toml new file mode 100644 index 00000000000..e93d7bc05e0 --- /dev/null +++ b/gen/qpxexpress1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-qpxexpress1-cli" +version = "0.0.1+20140321" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with QPX Express (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/qpxexpress1-cli" +homepage = "http://developers.google.com/qpx-express" +documentation = "http://byron.github.io/google-apis-rs/google_qpxexpress1_cli" +license = "MIT" +keywords = ["qpxExpress", "google", "cli"] + +[[bin]] +name = "qpxexpress1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-qpxexpress1] +path = "../qpxexpress1" diff --git a/gen/qpxexpress1-cli/LICENSE.md b/gen/qpxexpress1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/qpxexpress1-cli/LICENSE.md @@ -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. diff --git a/gen/qpxexpress1-cli/README.md b/gen/qpxexpress1-cli/README.md new file mode 100644 index 00000000000..698d1daecdd --- /dev/null +++ b/gen/qpxexpress1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO QPXEXPRESS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/qpxexpress1-cli/mkdocs.yml b/gen/qpxexpress1-cli/mkdocs.yml new file mode 100644 index 00000000000..8b40ea9235e --- /dev/null +++ b/gen/qpxexpress1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: QPX Express v0.0.1+20140321 +site_url: http://byron.github.io/google-apis-rs/google-qpxexpress1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/qpxexpress1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['trips_search.md', 'Trips', 'Search'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/qpxexpress1-cli/src/cmn.rs b/gen/qpxexpress1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/qpxexpress1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/qpxexpress1-cli/src/main.rs b/gen/qpxexpress1-cli/src/main.rs new file mode 100644 index 00000000000..2059eb0e871 --- /dev/null +++ b/gen/qpxexpress1-cli/src/main.rs @@ -0,0 +1,228 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_qpxexpress1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + qpxexpress1 [options] trips search -r <kv>... [-p <v>]... [-o <out>] + qpxexpress1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::QPXExpress<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _trips_search(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TripsSearchRequest = Default::default(); + let mut call = self.hub.trips().search(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_request_init(request: &mut api::TripsSearchRequest) { + if request.request.is_none() { + request.request = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "request.refundable" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().refundable = arg_from_str(value.unwrap_or("false"), err, "request.refundable", "boolean"); + }, + "request.passengers.kind" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.kind = value.unwrap_or("").to_string(); + }, + "request.passengers.infant-in-lap-count" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.infant_in_lap_count = arg_from_str(value.unwrap_or("-0"), err, "request.passengers.infant-in-lap-count", "integer"); + }, + "request.passengers.senior-count" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.senior_count = arg_from_str(value.unwrap_or("-0"), err, "request.passengers.senior-count", "integer"); + }, + "request.passengers.infant-in-seat-count" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.infant_in_seat_count = arg_from_str(value.unwrap_or("-0"), err, "request.passengers.infant-in-seat-count", "integer"); + }, + "request.passengers.child-count" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.child_count = arg_from_str(value.unwrap_or("-0"), err, "request.passengers.child-count", "integer"); + }, + "request.passengers.adult-count" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().passengers.adult_count = arg_from_str(value.unwrap_or("-0"), err, "request.passengers.adult-count", "integer"); + }, + "request.sale-country" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().sale_country = arg_from_str(value.unwrap_or("-0"), err, "request.sale-country", "int64"); + }, + "request.solutions" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().solutions = arg_from_str(value.unwrap_or("-0"), err, "request.solutions", "integer"); + }, + "request.max-price" => { + request_request_init(&mut request); + request.request.as_mut().unwrap().max_price = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_trips { + if self.opt.cmd_search { + call_result = self._trips_search(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "qpxexpress1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "qpxexpress1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::QPXExpress::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/replicapool1_beta2-cli/Cargo.toml b/gen/replicapool1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..3111e9e30dc --- /dev/null +++ b/gen/replicapool1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-replicapool1_beta2-cli" +version = "0.0.1+20150223" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with replicapool (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/replicapool1_beta2-cli" +homepage = "https://developers.google.com/compute/docs/instance-groups/manager/v1beta2" +documentation = "http://byron.github.io/google-apis-rs/google_replicapool1_beta2_cli" +license = "MIT" +keywords = ["replicapool", "google", "cli"] + +[[bin]] +name = "replicapool1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-replicapool1_beta2] +path = "../replicapool1_beta2" diff --git a/gen/replicapool1_beta2-cli/LICENSE.md b/gen/replicapool1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/replicapool1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/replicapool1_beta2-cli/README.md b/gen/replicapool1_beta2-cli/README.md new file mode 100644 index 00000000000..9030acbc393 --- /dev/null +++ b/gen/replicapool1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO REPLICAPOOL:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/replicapool1_beta2-cli/mkdocs.yml b/gen/replicapool1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..63d8c2642bc --- /dev/null +++ b/gen/replicapool1_beta2-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: replicapool v0.0.1+20150223 +site_url: http://byron.github.io/google-apis-rs/google-replicapool1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/replicapool1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['instance-group-managers_abandon-instances.md', 'Instance Group Managers', 'Abandon Instances'] +- ['instance-group-managers_delete.md', 'Instance Group Managers', 'Delete'] +- ['instance-group-managers_delete-instances.md', 'Instance Group Managers', 'Delete Instances'] +- ['instance-group-managers_get.md', 'Instance Group Managers', 'Get'] +- ['instance-group-managers_insert.md', 'Instance Group Managers', 'Insert'] +- ['instance-group-managers_list.md', 'Instance Group Managers', 'List'] +- ['instance-group-managers_recreate-instances.md', 'Instance Group Managers', 'Recreate Instances'] +- ['instance-group-managers_resize.md', 'Instance Group Managers', 'Resize'] +- ['instance-group-managers_set-instance-template.md', 'Instance Group Managers', 'Set Instance Template'] +- ['instance-group-managers_set-target-pools.md', 'Instance Group Managers', 'Set Target Pools'] +- ['zone-operations_get.md', 'Zone Operations', 'Get'] +- ['zone-operations_list.md', 'Zone Operations', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/replicapool1_beta2-cli/src/cmn.rs b/gen/replicapool1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/replicapool1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/replicapool1_beta2-cli/src/main.rs b/gen/replicapool1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..c445b479000 --- /dev/null +++ b/gen/replicapool1_beta2-cli/src/main.rs @@ -0,0 +1,864 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_replicapool1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + replicapool1-beta2 [options] instance-group-managers abandon-instances <project> <zone> <instance-group-manager> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers delete <project> <zone> <instance-group-manager> [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers delete-instances <project> <zone> <instance-group-manager> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers get <project> <zone> <instance-group-manager> [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers insert <project> <zone> <size> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers list <project> <zone> [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers recreate-instances <project> <zone> <instance-group-manager> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers resize <project> <zone> <instance-group-manager> <size> [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers set-instance-template <project> <zone> <instance-group-manager> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] instance-group-managers set-target-pools <project> <zone> <instance-group-manager> -r <kv>... [-p <v>]... [-o <out>] + replicapool1-beta2 [options] zone-operations get <project> <zone> <operation> [-p <v>]... [-o <out>] + replicapool1-beta2 [options] zone-operations list <project> <zone> [-p <v>]... [-o <out>] + replicapool1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Replicapool<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _instance_group_managers_abandon_instances(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManagersAbandonInstancesRequest = Default::default(); + let mut call = self.hub.instance_group_managers().abandon_instances(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "instances" => { + if request.instances.is_none() { + request.instances = Some(Default::default()); + } + request.instances.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instance_group_managers().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_delete_instances(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManagersDeleteInstancesRequest = Default::default(); + let mut call = self.hub.instance_group_managers().delete_instances(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "instances" => { + if request.instances.is_none() { + request.instances = Some(Default::default()); + } + request.instances.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instance_group_managers().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManager = Default::default(); + let size: i32 = arg_from_str(&self.opt.arg_size, err, "<size>", "integer"); + let mut call = self.hub.instance_group_managers().insert(&request, &self.opt.arg_project, &self.opt.arg_zone, size); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target-size" => { + request.target_size = Some(arg_from_str(value.unwrap_or("-0"), err, "target-size", "integer")); + }, + "group" => { + request.group = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "target-pools" => { + if request.target_pools.is_none() { + request.target_pools = Some(Default::default()); + } + request.target_pools.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "base-instance-name" => { + request.base_instance_name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "instance-template" => { + request.instance_template = Some(value.unwrap_or("").to_string()); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "current-size" => { + request.current_size = Some(arg_from_str(value.unwrap_or("-0"), err, "current-size", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instance_group_managers().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_recreate_instances(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManagersRecreateInstancesRequest = Default::default(); + let mut call = self.hub.instance_group_managers().recreate_instances(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "instances" => { + if request.instances.is_none() { + request.instances = Some(Default::default()); + } + request.instances.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_resize(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let size: i32 = arg_from_str(&self.opt.arg_size, err, "<size>", "integer"); + let mut call = self.hub.instance_group_managers().resize(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager, size); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_set_instance_template(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManagersSetInstanceTemplateRequest = Default::default(); + let mut call = self.hub.instance_group_managers().set_instance_template(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "instance-template" => { + request.instance_template = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instance_group_managers_set_target_pools(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstanceGroupManagersSetTargetPoolsRequest = Default::default(); + let mut call = self.hub.instance_group_managers().set_target_pools(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_instance_group_manager); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "target-pools" => { + if request.target_pools.is_none() { + request.target_pools = Some(Default::default()); + } + request.target_pools.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_operations().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_operations().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_instance_group_managers { + if self.opt.cmd_abandon_instances { + call_result = self._instance_group_managers_abandon_instances(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._instance_group_managers_delete(dry_run, &mut err); + } else if self.opt.cmd_delete_instances { + call_result = self._instance_group_managers_delete_instances(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._instance_group_managers_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._instance_group_managers_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._instance_group_managers_list(dry_run, &mut err); + } else if self.opt.cmd_recreate_instances { + call_result = self._instance_group_managers_recreate_instances(dry_run, &mut err); + } else if self.opt.cmd_resize { + call_result = self._instance_group_managers_resize(dry_run, &mut err); + } else if self.opt.cmd_set_instance_template { + call_result = self._instance_group_managers_set_instance_template(dry_run, &mut err); + } else if self.opt.cmd_set_target_pools { + call_result = self._instance_group_managers_set_target_pools(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zone_operations { + if self.opt.cmd_get { + call_result = self._zone_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zone_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "replicapool1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "replicapool1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Replicapool::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/replicapoolupdater1_beta1-cli/Cargo.toml b/gen/replicapoolupdater1_beta1-cli/Cargo.toml new file mode 100644 index 00000000000..3f2f414f4e6 --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-replicapoolupdater1_beta1-cli" +version = "0.0.1+20150129" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with replicapoolupdater (protocol v1beta1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/replicapoolupdater1_beta1-cli" +homepage = "https://cloud.google.com/compute/docs/instance-groups/manager/#applying_rolling_updates_using_the_updater_service" +documentation = "http://byron.github.io/google-apis-rs/google_replicapoolupdater1_beta1_cli" +license = "MIT" +keywords = ["replicapoolupdater", "google", "cli"] + +[[bin]] +name = "replicapoolupdater1-beta1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-replicapoolupdater1_beta1] +path = "../replicapoolupdater1_beta1" diff --git a/gen/replicapoolupdater1_beta1-cli/LICENSE.md b/gen/replicapoolupdater1_beta1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/LICENSE.md @@ -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. diff --git a/gen/replicapoolupdater1_beta1-cli/README.md b/gen/replicapoolupdater1_beta1-cli/README.md new file mode 100644 index 00000000000..30e5466b020 --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO REPLICAPOOLUPDATER:V1BETA1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/replicapoolupdater1_beta1-cli/mkdocs.yml b/gen/replicapoolupdater1_beta1-cli/mkdocs.yml new file mode 100644 index 00000000000..97567745479 --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/mkdocs.yml @@ -0,0 +1,25 @@ +site_name: replicapoolupdater v0.0.1+20150129 +site_url: http://byron.github.io/google-apis-rs/google-replicapoolupdater1_beta1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/replicapoolupdater1_beta1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['rolling-updates_cancel.md', 'Rolling Updates', 'Cancel'] +- ['rolling-updates_get.md', 'Rolling Updates', 'Get'] +- ['rolling-updates_insert.md', 'Rolling Updates', 'Insert'] +- ['rolling-updates_list.md', 'Rolling Updates', 'List'] +- ['rolling-updates_list-instance-updates.md', 'Rolling Updates', 'List Instance Updates'] +- ['rolling-updates_pause.md', 'Rolling Updates', 'Pause'] +- ['rolling-updates_resume.md', 'Rolling Updates', 'Resume'] +- ['rolling-updates_rollback.md', 'Rolling Updates', 'Rollback'] +- ['zone-operations_get.md', 'Zone Operations', 'Get'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/replicapoolupdater1_beta1-cli/src/cmn.rs b/gen/replicapoolupdater1_beta1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/replicapoolupdater1_beta1-cli/src/main.rs b/gen/replicapoolupdater1_beta1-cli/src/main.rs new file mode 100644 index 00000000000..34bd00f5462 --- /dev/null +++ b/gen/replicapoolupdater1_beta1-cli/src/main.rs @@ -0,0 +1,666 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_replicapoolupdater1_beta1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + replicapoolupdater1-beta1 [options] rolling-updates cancel <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates get <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates insert <project> <zone> -r <kv>... [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates list <project> <zone> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates list-instance-updates <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates pause <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates resume <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] rolling-updates rollback <project> <zone> <rolling-update> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 [options] zone-operations get <project> <zone> <operation> [-p <v>]... [-o <out>] + replicapoolupdater1-beta1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Replicapoolupdater<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _rolling_updates_cancel(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().cancel(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RollingUpdate = Default::default(); + let mut call = self.hub.rolling_updates().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_policy_init(request: &mut api::RollingUpdate) { + if request.policy.is_none() { + request.policy = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "status-message" => { + request.status_message = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "instance-group" => { + request.instance_group = Some(value.unwrap_or("").to_string()); + }, + "instances" => { + if request.instances.is_none() { + request.instances = Some(Default::default()); + } + request.instances.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "instance-template" => { + request.instance_template = Some(value.unwrap_or("").to_string()); + }, + "action-type" => { + request.action_type = Some(value.unwrap_or("").to_string()); + }, + "user" => { + request.user = Some(value.unwrap_or("").to_string()); + }, + "instance-group-manager" => { + request.instance_group_manager = Some(value.unwrap_or("").to_string()); + }, + "policy.instance-startup-timeout-sec" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().instance_startup_timeout_sec = arg_from_str(value.unwrap_or("-0"), err, "policy.instance-startup-timeout-sec", "integer"); + }, + "policy.max-num-concurrent-instances" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().max_num_concurrent_instances = arg_from_str(value.unwrap_or("-0"), err, "policy.max-num-concurrent-instances", "integer"); + }, + "policy.min-instance-update-time-sec" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().min_instance_update_time_sec = arg_from_str(value.unwrap_or("-0"), err, "policy.min-instance-update-time-sec", "integer"); + }, + "policy.sleep-after-instance-restart-sec" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().sleep_after_instance_restart_sec = arg_from_str(value.unwrap_or("-0"), err, "policy.sleep-after-instance-restart-sec", "integer"); + }, + "policy.max-num-failed-instances" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().max_num_failed_instances = arg_from_str(value.unwrap_or("-0"), err, "policy.max-num-failed-instances", "integer"); + }, + "policy.auto-pause-after-instances" => { + request_policy_init(&mut request); + request.policy.as_mut().unwrap().auto_pause_after_instances = arg_from_str(value.unwrap_or("-0"), err, "policy.auto-pause-after-instances", "integer"); + }, + "progress" => { + request_policy_init(&mut request); + request.progress = Some(arg_from_str(value.unwrap_or("-0"), err, "progress", "integer")); + }, + "creation-timestamp" => { + request_policy_init(&mut request); + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_policy_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_policy_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "instance-group-manager" => { + call = call.instance_group_manager(value.unwrap_or("")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_list_instance_updates(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().list_instance_updates(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_pause(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().pause(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_resume(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().resume(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _rolling_updates_rollback(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.rolling_updates().rollback(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_rolling_update); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_operations().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_rolling_updates { + if self.opt.cmd_cancel { + call_result = self._rolling_updates_cancel(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._rolling_updates_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._rolling_updates_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._rolling_updates_list(dry_run, &mut err); + } else if self.opt.cmd_list_instance_updates { + call_result = self._rolling_updates_list_instance_updates(dry_run, &mut err); + } else if self.opt.cmd_pause { + call_result = self._rolling_updates_pause(dry_run, &mut err); + } else if self.opt.cmd_resume { + call_result = self._rolling_updates_resume(dry_run, &mut err); + } else if self.opt.cmd_rollback { + call_result = self._rolling_updates_rollback(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zone_operations { + if self.opt.cmd_get { + call_result = self._zone_operations_get(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "replicapoolupdater1-beta1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "replicapoolupdater1-beta1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Replicapoolupdater::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/Cargo.toml b/gen/reseller1_sandbox-cli/Cargo.toml new file mode 100644 index 00000000000..fe8ca1ef330 --- /dev/null +++ b/gen/reseller1_sandbox-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-reseller1_sandbox-cli" +version = "0.0.1+20141112" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with reseller (protocol v1sandbox)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/reseller1_sandbox-cli" +homepage = "https://developers.google.com/google-apps/reseller/" +documentation = "http://byron.github.io/google-apis-rs/google_reseller1_sandbox_cli" +license = "MIT" +keywords = ["reseller", "google", "cli"] + +[[bin]] +name = "reseller1-sandbox" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-reseller1_sandbox] +path = "../reseller1_sandbox" diff --git a/gen/reseller1_sandbox-cli/LICENSE.md b/gen/reseller1_sandbox-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/reseller1_sandbox-cli/LICENSE.md @@ -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. diff --git a/gen/reseller1_sandbox-cli/README.md b/gen/reseller1_sandbox-cli/README.md new file mode 100644 index 00000000000..9039e1ee497 --- /dev/null +++ b/gen/reseller1_sandbox-cli/README.md @@ -0,0 +1,4 @@ +# HELLO RESELLER:V1SANDBOX + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/mkdocs.yml b/gen/reseller1_sandbox-cli/mkdocs.yml new file mode 100644 index 00000000000..a19e710f660 --- /dev/null +++ b/gen/reseller1_sandbox-cli/mkdocs.yml @@ -0,0 +1,30 @@ +site_name: reseller v0.0.1+20141112 +site_url: http://byron.github.io/google-apis-rs/google-reseller1_sandbox-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/reseller1_sandbox-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['customers_get.md', 'Customers', 'Get'] +- ['customers_insert.md', 'Customers', 'Insert'] +- ['customers_patch.md', 'Customers', 'Patch'] +- ['customers_update.md', 'Customers', 'Update'] +- ['subscriptions_activate.md', 'Subscriptions', 'Activate'] +- ['subscriptions_change-plan.md', 'Subscriptions', 'Change Plan'] +- ['subscriptions_change-renewal-settings.md', 'Subscriptions', 'Change Renewal Settings'] +- ['subscriptions_change-seats.md', 'Subscriptions', 'Change Seats'] +- ['subscriptions_delete.md', 'Subscriptions', 'Delete'] +- ['subscriptions_get.md', 'Subscriptions', 'Get'] +- ['subscriptions_insert.md', 'Subscriptions', 'Insert'] +- ['subscriptions_list.md', 'Subscriptions', 'List'] +- ['subscriptions_start-paid-service.md', 'Subscriptions', 'Start Paid Service'] +- ['subscriptions_suspend.md', 'Subscriptions', 'Suspend'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/reseller1_sandbox-cli/src/cmn.rs b/gen/reseller1_sandbox-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/reseller1_sandbox-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/reseller1_sandbox-cli/src/main.rs b/gen/reseller1_sandbox-cli/src/main.rs new file mode 100644 index 00000000000..d02ba364a44 --- /dev/null +++ b/gen/reseller1_sandbox-cli/src/main.rs @@ -0,0 +1,1265 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_reseller1_sandbox as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + reseller1-sandbox [options] customers get <customer-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers insert -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers patch <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] customers update <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions activate <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-plan <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-renewal-settings <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions change-seats <customer-id> <subscription-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions delete <customer-id> <subscription-id> <deletion-type> [-p <v>]... + reseller1-sandbox [options] subscriptions get <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions insert <customer-id> -r <kv>... [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions list [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions start-paid-service <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox [options] subscriptions suspend <customer-id> <subscription-id> [-p <v>]... [-o <out>] + reseller1-sandbox --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Reseller<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _customers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.customers().get(&self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Customer = Default::default(); + let mut call = self.hub.customers().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = value.unwrap_or("").to_string(); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = value.unwrap_or("").to_string(); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = value.unwrap_or("").to_string(); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = value.unwrap_or("").to_string(); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = value.unwrap_or("").to_string(); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = value.unwrap_or("").to_string(); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = value.unwrap_or("").to_string(); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = value.unwrap_or("").to_string(); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Customer = Default::default(); + let mut call = self.hub.customers().patch(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = value.unwrap_or("").to_string(); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = value.unwrap_or("").to_string(); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = value.unwrap_or("").to_string(); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = value.unwrap_or("").to_string(); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = value.unwrap_or("").to_string(); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = value.unwrap_or("").to_string(); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = value.unwrap_or("").to_string(); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = value.unwrap_or("").to_string(); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _customers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Customer = Default::default(); + let mut call = self.hub.customers().update(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_postal_address_init(request: &mut api::Customer) { + if request.postal_address.is_none() { + request.postal_address = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "customer-domain" => { + request.customer_domain = Some(value.unwrap_or("").to_string()); + }, + "alternate-email" => { + request.alternate_email = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-ui-url" => { + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "phone-number" => { + request.phone_number = Some(value.unwrap_or("").to_string()); + }, + "postal-address.kind" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "postal-address.organization-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().organization_name = value.unwrap_or("").to_string(); + }, + "postal-address.country-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().country_code = value.unwrap_or("").to_string(); + }, + "postal-address.locality" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().locality = value.unwrap_or("").to_string(); + }, + "postal-address.region" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().region = value.unwrap_or("").to_string(); + }, + "postal-address.address-line2" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line2 = value.unwrap_or("").to_string(); + }, + "postal-address.address-line3" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line3 = value.unwrap_or("").to_string(); + }, + "postal-address.contact-name" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().contact_name = value.unwrap_or("").to_string(); + }, + "postal-address.address-line1" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().address_line1 = value.unwrap_or("").to_string(); + }, + "postal-address.postal-code" => { + request_postal_address_init(&mut request); + request.postal_address.as_mut().unwrap().postal_code = value.unwrap_or("").to_string(); + }, + "customer-id" => { + request_postal_address_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_activate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().activate(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_plan(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ChangePlanRequest = Default::default(); + let mut call = self.hub.subscriptions().change_plan(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_seats_init(request: &mut api::ChangePlanRequest) { + if request.seats.is_none() { + request.seats = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "plan-name" => { + request.plan_name = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "seats.kind" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "seats.number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.number-of-seats", "integer")); + }, + "seats.maximum-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.maximum-number-of-seats", "integer")); + }, + "seats.licensed-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.licensed-number-of-seats", "integer")); + }, + "purchase-order-id" => { + request_seats_init(&mut request); + request.purchase_order_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_renewal_settings(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::RenewalSettings = Default::default(); + let mut call = self.hub.subscriptions().change_renewal_settings(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "renewal-type" => { + request.renewal_type = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_change_seats(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Seats = Default::default(); + let mut call = self.hub.subscriptions().change_seats(&request, &self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "number-of-seats" => { + request.number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "number-of-seats", "integer")); + }, + "maximum-number-of-seats" => { + request.maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "maximum-number-of-seats", "integer")); + }, + "licensed-number-of-seats" => { + request.licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "licensed-number-of-seats", "integer")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().delete(&self.opt.arg_customer_id, &self.opt.arg_subscription_id, &self.opt.arg_deletion_type); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _subscriptions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().get(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subscription = Default::default(); + let mut call = self.hub.subscriptions().insert(&request, &self.opt.arg_customer_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_plan_init(request: &mut api::Subscription) { + if request.plan.is_none() { + request.plan = Some(Default::default()); + } + } + + fn request_renewal_settings_init(request: &mut api::Subscription) { + if request.renewal_settings.is_none() { + request.renewal_settings = Some(Default::default()); + } + } + + fn request_seats_init(request: &mut api::Subscription) { + if request.seats.is_none() { + request.seats = Some(Default::default()); + } + } + + fn request_transfer_info_init(request: &mut api::Subscription) { + if request.transfer_info.is_none() { + request.transfer_info = Some(Default::default()); + } + } + + fn request_trial_settings_init(request: &mut api::Subscription) { + if request.trial_settings.is_none() { + request.trial_settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "renewal-settings.kind" => { + request_renewal_settings_init(&mut request); + request.renewal_settings.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "renewal-settings.renewal-type" => { + request_renewal_settings_init(&mut request); + request.renewal_settings.as_mut().unwrap().renewal_type = Some(value.unwrap_or("").to_string()); + }, + "sku-id" => { + request_renewal_settings_init(&mut request); + request.sku_id = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_renewal_settings_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "trial-settings.trial-end-time" => { + request_trial_settings_init(&mut request); + request.trial_settings.as_mut().unwrap().trial_end_time = value.unwrap_or("").to_string(); + }, + "trial-settings.is-in-trial" => { + request_trial_settings_init(&mut request); + request.trial_settings.as_mut().unwrap().is_in_trial = arg_from_str(value.unwrap_or("false"), err, "trial-settings.is-in-trial", "boolean"); + }, + "transfer-info.transferability-expiration-time" => { + request_transfer_info_init(&mut request); + request.transfer_info.as_mut().unwrap().transferability_expiration_time = value.unwrap_or("").to_string(); + }, + "transfer-info.minimum-transferable-seats" => { + request_transfer_info_init(&mut request); + request.transfer_info.as_mut().unwrap().minimum_transferable_seats = arg_from_str(value.unwrap_or("-0"), err, "transfer-info.minimum-transferable-seats", "integer"); + }, + "resource-ui-url" => { + request_transfer_info_init(&mut request); + request.resource_ui_url = Some(value.unwrap_or("").to_string()); + }, + "seats.kind" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "seats.number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.number-of-seats", "integer")); + }, + "seats.maximum-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().maximum_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.maximum-number-of-seats", "integer")); + }, + "seats.licensed-number-of-seats" => { + request_seats_init(&mut request); + request.seats.as_mut().unwrap().licensed_number_of_seats = Some(arg_from_str(value.unwrap_or("-0"), err, "seats.licensed-number-of-seats", "integer")); + }, + "creation-time" => { + request_seats_init(&mut request); + request.creation_time = Some(value.unwrap_or("").to_string()); + }, + "status" => { + request_seats_init(&mut request); + request.status = Some(value.unwrap_or("").to_string()); + }, + "plan.plan-name" => { + request_plan_init(&mut request); + request.plan.as_mut().unwrap().plan_name = value.unwrap_or("").to_string(); + }, + "plan.commitment-interval.end-time" => { + request_plan_init(&mut request); + request.plan.as_mut().unwrap().commitment_interval.end_time = value.unwrap_or("").to_string(); + }, + "plan.commitment-interval.start-time" => { + request_plan_init(&mut request); + request.plan.as_mut().unwrap().commitment_interval.start_time = value.unwrap_or("").to_string(); + }, + "plan.is-commitment-plan" => { + request_plan_init(&mut request); + request.plan.as_mut().unwrap().is_commitment_plan = arg_from_str(value.unwrap_or("false"), err, "plan.is-commitment-plan", "boolean"); + }, + "purchase-order-id" => { + request_plan_init(&mut request); + request.purchase_order_id = Some(value.unwrap_or("").to_string()); + }, + "subscription-id" => { + request_plan_init(&mut request); + request.subscription_id = Some(value.unwrap_or("").to_string()); + }, + "billing-method" => { + request_plan_init(&mut request); + request.billing_method = Some(value.unwrap_or("").to_string()); + }, + "customer-id" => { + request_plan_init(&mut request); + request.customer_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "customer-name-prefix" => { + call = call.customer_name_prefix(value.unwrap_or("")); + }, + "customer-id" => { + call = call.customer_id(value.unwrap_or("")); + }, + "customer-auth-token" => { + call = call.customer_auth_token(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_start_paid_service(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().start_paid_service(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_suspend(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().suspend(&self.opt.arg_customer_id, &self.opt.arg_subscription_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_customers { + if self.opt.cmd_get { + call_result = self._customers_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._customers_insert(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._customers_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._customers_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_subscriptions { + if self.opt.cmd_activate { + call_result = self._subscriptions_activate(dry_run, &mut err); + } else if self.opt.cmd_change_plan { + call_result = self._subscriptions_change_plan(dry_run, &mut err); + } else if self.opt.cmd_change_renewal_settings { + call_result = self._subscriptions_change_renewal_settings(dry_run, &mut err); + } else if self.opt.cmd_change_seats { + call_result = self._subscriptions_change_seats(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._subscriptions_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._subscriptions_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._subscriptions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._subscriptions_list(dry_run, &mut err); + } else if self.opt.cmd_start_paid_service { + call_result = self._subscriptions_start_paid_service(dry_run, &mut err); + } else if self.opt.cmd_suspend { + call_result = self._subscriptions_suspend(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "reseller1-sandbox-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "reseller1-sandbox", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Reseller::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/resourceviews1_beta2-cli/Cargo.toml b/gen/resourceviews1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..8a8960a68ff --- /dev/null +++ b/gen/resourceviews1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-resourceviews1_beta2-cli" +version = "0.0.1+20150302" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with resourceviews (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/resourceviews1_beta2-cli" +homepage = "https://developers.google.com/compute/" +documentation = "http://byron.github.io/google-apis-rs/google_resourceviews1_beta2_cli" +license = "MIT" +keywords = ["resourceviews", "google", "cli"] + +[[bin]] +name = "resourceviews1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-resourceviews1_beta2] +path = "../resourceviews1_beta2" diff --git a/gen/resourceviews1_beta2-cli/LICENSE.md b/gen/resourceviews1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/resourceviews1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/resourceviews1_beta2-cli/README.md b/gen/resourceviews1_beta2-cli/README.md new file mode 100644 index 00000000000..cfe961743ae --- /dev/null +++ b/gen/resourceviews1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO RESOURCEVIEWS:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/resourceviews1_beta2-cli/mkdocs.yml b/gen/resourceviews1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..774bb738d8f --- /dev/null +++ b/gen/resourceviews1_beta2-cli/mkdocs.yml @@ -0,0 +1,27 @@ +site_name: resourceviews v0.0.1+20150302 +site_url: http://byron.github.io/google-apis-rs/google-resourceviews1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/resourceviews1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['zone-operations_get.md', 'Zone Operations', 'Get'] +- ['zone-operations_list.md', 'Zone Operations', 'List'] +- ['zone-views_add-resources.md', 'Zone Views', 'Add Resources'] +- ['zone-views_delete.md', 'Zone Views', 'Delete'] +- ['zone-views_get.md', 'Zone Views', 'Get'] +- ['zone-views_get-service.md', 'Zone Views', 'Get Service'] +- ['zone-views_insert.md', 'Zone Views', 'Insert'] +- ['zone-views_list.md', 'Zone Views', 'List'] +- ['zone-views_list-resources.md', 'Zone Views', 'List Resources'] +- ['zone-views_remove-resources.md', 'Zone Views', 'Remove Resources'] +- ['zone-views_set-service.md', 'Zone Views', 'Set Service'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/resourceviews1_beta2-cli/src/cmn.rs b/gen/resourceviews1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/resourceviews1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/resourceviews1_beta2-cli/src/main.rs b/gen/resourceviews1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..e28a309d1a5 --- /dev/null +++ b/gen/resourceviews1_beta2-cli/src/main.rs @@ -0,0 +1,783 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_resourceviews1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + resourceviews1-beta2 [options] zone-operations get <project> <zone> <operation> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-operations list <project> <zone> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views add-resources <project> <zone> <resource-view> -r <kv>... [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views delete <project> <zone> <resource-view> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views get <project> <zone> <resource-view> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views get-service <project> <zone> <resource-view> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views insert <project> <zone> -r <kv>... [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views list <project> <zone> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views list-resources <project> <zone> <resource-view> [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views remove-resources <project> <zone> <resource-view> -r <kv>... [-p <v>]... [-o <out>] + resourceviews1-beta2 [options] zone-views set-service <project> <zone> <resource-view> -r <kv>... [-p <v>]... [-o <out>] + resourceviews1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Resourceviews<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _zone_operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_operations().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_operations().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filter" => { + call = call.filter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_add_resources(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ZoneViewsAddResourcesRequest = Default::default(); + let mut call = self.hub.zone_views().add_resources(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resources" => { + if request.resources.is_none() { + request.resources = Some(Default::default()); + } + request.resources.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_views().delete(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_views().get(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_get_service(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_views().get_service(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "resource-name" => { + call = call.resource_name(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ResourceView = Default::default(); + let mut call = self.hub.zone_views().insert(&request, &self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "network" => { + request.network = Some(value.unwrap_or("").to_string()); + }, + "description" => { + request.description = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "size" => { + request.size = Some(arg_from_str(value.unwrap_or("-0"), err, "size", "integer")); + }, + "creation-timestamp" => { + request.creation_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "resources" => { + if request.resources.is_none() { + request.resources = Some(Default::default()); + } + request.resources.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_views().list(&self.opt.arg_project, &self.opt.arg_zone); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_list_resources(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.zone_views().list_resources(&self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "service-name" => { + call = call.service_name(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "list-state" => { + call = call.list_state(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_remove_resources(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ZoneViewsRemoveResourcesRequest = Default::default(); + let mut call = self.hub.zone_views().remove_resources(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resources" => { + if request.resources.is_none() { + request.resources = Some(Default::default()); + } + request.resources.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _zone_views_set_service(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ZoneViewsSetServiceRequest = Default::default(); + let mut call = self.hub.zone_views().set_service(&request, &self.opt.arg_project, &self.opt.arg_zone, &self.opt.arg_resource_view); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-name" => { + request.resource_name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_zone_operations { + if self.opt.cmd_get { + call_result = self._zone_operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zone_operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_zone_views { + if self.opt.cmd_add_resources { + call_result = self._zone_views_add_resources(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._zone_views_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._zone_views_get(dry_run, &mut err); + } else if self.opt.cmd_get_service { + call_result = self._zone_views_get_service(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._zone_views_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._zone_views_list(dry_run, &mut err); + } else if self.opt.cmd_list_resources { + call_result = self._zone_views_list_resources(dry_run, &mut err); + } else if self.opt.cmd_remove_resources { + call_result = self._zone_views_remove_resources(dry_run, &mut err); + } else if self.opt.cmd_set_service { + call_result = self._zone_views_set_service(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "resourceviews1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "resourceviews1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Resourceviews::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/siteverification1-cli/Cargo.toml b/gen/siteverification1-cli/Cargo.toml new file mode 100644 index 00000000000..477a734c68f --- /dev/null +++ b/gen/siteverification1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-siteverification1-cli" +version = "0.0.1+20131007" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with siteVerification (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/siteverification1-cli" +homepage = "https://developers.google.com/site-verification/" +documentation = "http://byron.github.io/google-apis-rs/google_siteverification1_cli" +license = "MIT" +keywords = ["siteVerification", "google", "cli"] + +[[bin]] +name = "siteverification1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-siteverification1] +path = "../siteverification1" diff --git a/gen/siteverification1-cli/LICENSE.md b/gen/siteverification1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/siteverification1-cli/LICENSE.md @@ -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. diff --git a/gen/siteverification1-cli/README.md b/gen/siteverification1-cli/README.md new file mode 100644 index 00000000000..69ad885699b --- /dev/null +++ b/gen/siteverification1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO SITEVERIFICATION:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/siteverification1-cli/mkdocs.yml b/gen/siteverification1-cli/mkdocs.yml new file mode 100644 index 00000000000..0f293c49727 --- /dev/null +++ b/gen/siteverification1-cli/mkdocs.yml @@ -0,0 +1,23 @@ +site_name: siteVerification v0.0.1+20131007 +site_url: http://byron.github.io/google-apis-rs/google-siteverification1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/siteverification1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['web-resource_delete.md', 'Web Resource', 'Delete'] +- ['web-resource_get.md', 'Web Resource', 'Get'] +- ['web-resource_get-token.md', 'Web Resource', 'Get Token'] +- ['web-resource_insert.md', 'Web Resource', 'Insert'] +- ['web-resource_list.md', 'Web Resource', 'List'] +- ['web-resource_patch.md', 'Web Resource', 'Patch'] +- ['web-resource_update.md', 'Web Resource', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/siteverification1-cli/src/cmn.rs b/gen/siteverification1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/siteverification1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/siteverification1-cli/src/main.rs b/gen/siteverification1-cli/src/main.rs new file mode 100644 index 00000000000..144164985af --- /dev/null +++ b/gen/siteverification1-cli/src/main.rs @@ -0,0 +1,591 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_siteverification1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + siteverification1 [options] web-resource delete <id> [-p <v>]... + siteverification1 [options] web-resource get <id> [-p <v>]... [-o <out>] + siteverification1 [options] web-resource get-token -r <kv>... [-p <v>]... [-o <out>] + siteverification1 [options] web-resource insert <verification-method> -r <kv>... [-p <v>]... [-o <out>] + siteverification1 [options] web-resource list [-p <v>]... [-o <out>] + siteverification1 [options] web-resource patch <id> -r <kv>... [-p <v>]... [-o <out>] + siteverification1 [options] web-resource update <id> -r <kv>... [-p <v>]... [-o <out>] + siteverification1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::SiteVerification<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _web_resource_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.web_resource().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _web_resource_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.web_resource().get(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _web_resource_get_token(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SiteVerificationWebResourceGettokenRequest = Default::default(); + let mut call = self.hub.web_resource().get_token(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_site_init(request: &mut api::SiteVerificationWebResourceGettokenRequest) { + if request.site.is_none() { + request.site = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "verification-method" => { + request.verification_method = Some(value.unwrap_or("").to_string()); + }, + "site.identifier" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().identifier = value.unwrap_or("").to_string(); + }, + "site.type" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _web_resource_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SiteVerificationWebResourceResource = Default::default(); + let mut call = self.hub.web_resource().insert(&request, &self.opt.arg_verification_method); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_site_init(request: &mut api::SiteVerificationWebResourceResource) { + if request.site.is_none() { + request.site = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "owners" => { + if request.owners.is_none() { + request.owners = Some(Default::default()); + } + request.owners.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "site.identifier" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().identifier = value.unwrap_or("").to_string(); + }, + "site.type" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _web_resource_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.web_resource().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _web_resource_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SiteVerificationWebResourceResource = Default::default(); + let mut call = self.hub.web_resource().patch(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_site_init(request: &mut api::SiteVerificationWebResourceResource) { + if request.site.is_none() { + request.site = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "owners" => { + if request.owners.is_none() { + request.owners = Some(Default::default()); + } + request.owners.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "site.identifier" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().identifier = value.unwrap_or("").to_string(); + }, + "site.type" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _web_resource_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SiteVerificationWebResourceResource = Default::default(); + let mut call = self.hub.web_resource().update(&request, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_site_init(request: &mut api::SiteVerificationWebResourceResource) { + if request.site.is_none() { + request.site = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "owners" => { + if request.owners.is_none() { + request.owners = Some(Default::default()); + } + request.owners.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "site.identifier" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().identifier = value.unwrap_or("").to_string(); + }, + "site.type" => { + request_site_init(&mut request); + request.site.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_web_resource { + if self.opt.cmd_delete { + call_result = self._web_resource_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._web_resource_get(dry_run, &mut err); + } else if self.opt.cmd_get_token { + call_result = self._web_resource_get_token(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._web_resource_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._web_resource_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._web_resource_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._web_resource_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "siteverification1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "siteverification1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::SiteVerification::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/spectrum1_explorer-cli/Cargo.toml b/gen/spectrum1_explorer-cli/Cargo.toml new file mode 100644 index 00000000000..051cc86dbdb --- /dev/null +++ b/gen/spectrum1_explorer-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-spectrum1_explorer-cli" +version = "0.0.1+20150112" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with spectrum (protocol v1explorer)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/spectrum1_explorer-cli" +homepage = "http://developers.google.com/spectrum" +documentation = "http://byron.github.io/google-apis-rs/google_spectrum1_explorer_cli" +license = "MIT" +keywords = ["spectrum", "google", "cli"] + +[[bin]] +name = "spectrum1-explorer" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-spectrum1_explorer] +path = "../spectrum1_explorer" diff --git a/gen/spectrum1_explorer-cli/LICENSE.md b/gen/spectrum1_explorer-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/spectrum1_explorer-cli/LICENSE.md @@ -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. diff --git a/gen/spectrum1_explorer-cli/README.md b/gen/spectrum1_explorer-cli/README.md new file mode 100644 index 00000000000..06795b20d81 --- /dev/null +++ b/gen/spectrum1_explorer-cli/README.md @@ -0,0 +1,4 @@ +# HELLO SPECTRUM:V1EXPLORER + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/spectrum1_explorer-cli/mkdocs.yml b/gen/spectrum1_explorer-cli/mkdocs.yml new file mode 100644 index 00000000000..f03e6fd128d --- /dev/null +++ b/gen/spectrum1_explorer-cli/mkdocs.yml @@ -0,0 +1,22 @@ +site_name: spectrum v0.0.1+20150112 +site_url: http://byron.github.io/google-apis-rs/google-spectrum1_explorer-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/spectrum1_explorer-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['paws_get-spectrum.md', 'Paws', 'Get Spectrum'] +- ['paws_get-spectrum-batch.md', 'Paws', 'Get Spectrum Batch'] +- ['paws_init.md', 'Paws', 'Init'] +- ['paws_notify-spectrum-use.md', 'Paws', 'Notify Spectrum Use'] +- ['paws_register.md', 'Paws', 'Register'] +- ['paws_verify-device.md', 'Paws', 'Verify Device'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/spectrum1_explorer-cli/src/cmn.rs b/gen/spectrum1_explorer-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/spectrum1_explorer-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/spectrum1_explorer-cli/src/main.rs b/gen/spectrum1_explorer-cli/src/main.rs new file mode 100644 index 00000000000..da0c3bc0221 --- /dev/null +++ b/gen/spectrum1_explorer-cli/src/main.rs @@ -0,0 +1,1290 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_spectrum1_explorer as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + spectrum1-explorer [options] paws get-spectrum -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer [options] paws get-spectrum-batch -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer [options] paws init -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer [options] paws notify-spectrum-use -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer [options] paws register -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer [options] paws verify-device -r <kv>... [-p <v>]... [-o <out>] + spectrum1-explorer --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Spectrum<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _paws_get_spectrum(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsGetSpectrumRequest = Default::default(); + let mut call = self.hub.paws().get_spectrum(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_antenna_init(request: &mut api::PawsGetSpectrumRequest) { + if request.antenna.is_none() { + request.antenna = Some(Default::default()); + } + } + + fn request_device_desc_init(request: &mut api::PawsGetSpectrumRequest) { + if request.device_desc.is_none() { + request.device_desc = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::PawsGetSpectrumRequest) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + fn request_master_device_desc_init(request: &mut api::PawsGetSpectrumRequest) { + if request.master_device_desc.is_none() { + request.master_device_desc = Some(Default::default()); + } + } + + fn request_owner_init(request: &mut api::PawsGetSpectrumRequest) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-desc.etsi-en-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "device-desc.serial-number" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-technology-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-tvbd-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-device-category" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "device-desc.ruleset-ids" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "device-desc.etsi-en-device-emissions-class" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "device-desc.manufacturer-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "device-desc.model-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "version" => { + request_device_desc_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "antenna.height-type" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_type = value.unwrap_or("").to_string(); + }, + "antenna.height-uncertainty" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_uncertainty = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height-uncertainty", "number"); + }, + "antenna.height" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height", "number"); + }, + "request-type" => { + request_antenna_init(&mut request); + request.request_type = Some(value.unwrap_or("").to_string()); + }, + "master-device-desc.etsi-en-device-type" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "master-device-desc.fcc-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.serial-number" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "master-device-desc.etsi-en-technology-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.fcc-tvbd-device-type" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "master-device-desc.etsi-en-device-category" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "master-device-desc.ruleset-ids" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "master-device-desc.etsi-en-device-emissions-class" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "master-device-desc.manufacturer-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.model-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "location.confidence" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().confidence = arg_from_str(value.unwrap_or("-0"), err, "location.confidence", "integer"); + }, + "location.point.semi-minor-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_minor_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-minor-axis", "number"); + }, + "location.point.center.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.latitude", "number"); + }, + "location.point.center.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.longitude", "number"); + }, + "location.point.semi-major-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_major_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-major-axis", "number"); + }, + "location.point.orientation" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.orientation = arg_from_str(value.unwrap_or("0.0"), err, "location.point.orientation", "number"); + }, + "owner.operator.org.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.org.text = value.unwrap_or("").to_string(); + }, + "owner.operator.tel.uri" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.tel.uri = value.unwrap_or("").to_string(); + }, + "owner.operator.email.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.email.text = value.unwrap_or("").to_string(); + }, + "owner.operator.fn" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.fn_ = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.code" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.code = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.locality" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.locality = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.country" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.country = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.region" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.region = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.pobox" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.pobox = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.street" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.street = value.unwrap_or("").to_string(); + }, + "owner.owner.org.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.org.text = value.unwrap_or("").to_string(); + }, + "owner.owner.tel.uri" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.tel.uri = value.unwrap_or("").to_string(); + }, + "owner.owner.email.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.email.text = value.unwrap_or("").to_string(); + }, + "owner.owner.fn" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.fn_ = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.code" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.code = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.locality" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.locality = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.country" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.country = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.region" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.region = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.pobox" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.pobox = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.street" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.street = value.unwrap_or("").to_string(); + }, + "type" => { + request_owner_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _paws_get_spectrum_batch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsGetSpectrumBatchRequest = Default::default(); + let mut call = self.hub.paws().get_spectrum_batch(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_antenna_init(request: &mut api::PawsGetSpectrumBatchRequest) { + if request.antenna.is_none() { + request.antenna = Some(Default::default()); + } + } + + fn request_device_desc_init(request: &mut api::PawsGetSpectrumBatchRequest) { + if request.device_desc.is_none() { + request.device_desc = Some(Default::default()); + } + } + + fn request_master_device_desc_init(request: &mut api::PawsGetSpectrumBatchRequest) { + if request.master_device_desc.is_none() { + request.master_device_desc = Some(Default::default()); + } + } + + fn request_owner_init(request: &mut api::PawsGetSpectrumBatchRequest) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-desc.etsi-en-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "device-desc.serial-number" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-technology-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-tvbd-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-device-category" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "device-desc.ruleset-ids" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "device-desc.etsi-en-device-emissions-class" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "device-desc.manufacturer-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "device-desc.model-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "version" => { + request_device_desc_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "antenna.height-type" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_type = value.unwrap_or("").to_string(); + }, + "antenna.height-uncertainty" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_uncertainty = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height-uncertainty", "number"); + }, + "antenna.height" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height", "number"); + }, + "request-type" => { + request_antenna_init(&mut request); + request.request_type = Some(value.unwrap_or("").to_string()); + }, + "master-device-desc.etsi-en-device-type" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "master-device-desc.fcc-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.serial-number" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "master-device-desc.etsi-en-technology-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.fcc-tvbd-device-type" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "master-device-desc.etsi-en-device-category" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "master-device-desc.ruleset-ids" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "master-device-desc.etsi-en-device-emissions-class" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "master-device-desc.manufacturer-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "master-device-desc.model-id" => { + request_master_device_desc_init(&mut request); + request.master_device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "owner.operator.org.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.org.text = value.unwrap_or("").to_string(); + }, + "owner.operator.tel.uri" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.tel.uri = value.unwrap_or("").to_string(); + }, + "owner.operator.email.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.email.text = value.unwrap_or("").to_string(); + }, + "owner.operator.fn" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.fn_ = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.code" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.code = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.locality" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.locality = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.country" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.country = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.region" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.region = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.pobox" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.pobox = value.unwrap_or("").to_string(); + }, + "owner.operator.adr.street" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().operator.adr.street = value.unwrap_or("").to_string(); + }, + "owner.owner.org.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.org.text = value.unwrap_or("").to_string(); + }, + "owner.owner.tel.uri" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.tel.uri = value.unwrap_or("").to_string(); + }, + "owner.owner.email.text" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.email.text = value.unwrap_or("").to_string(); + }, + "owner.owner.fn" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.fn_ = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.code" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.code = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.locality" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.locality = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.country" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.country = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.region" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.region = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.pobox" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.pobox = value.unwrap_or("").to_string(); + }, + "owner.owner.adr.street" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().owner.adr.street = value.unwrap_or("").to_string(); + }, + "type" => { + request_owner_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _paws_init(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsInitRequest = Default::default(); + let mut call = self.hub.paws().init(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_device_desc_init(request: &mut api::PawsInitRequest) { + if request.device_desc.is_none() { + request.device_desc = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::PawsInitRequest) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-desc.etsi-en-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "device-desc.serial-number" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-technology-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-tvbd-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-device-category" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "device-desc.ruleset-ids" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "device-desc.etsi-en-device-emissions-class" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "device-desc.manufacturer-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "device-desc.model-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "type" => { + request_device_desc_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "location.confidence" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().confidence = arg_from_str(value.unwrap_or("-0"), err, "location.confidence", "integer"); + }, + "location.point.semi-minor-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_minor_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-minor-axis", "number"); + }, + "location.point.center.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.latitude", "number"); + }, + "location.point.center.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.longitude", "number"); + }, + "location.point.semi-major-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_major_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-major-axis", "number"); + }, + "location.point.orientation" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.orientation = arg_from_str(value.unwrap_or("0.0"), err, "location.point.orientation", "number"); + }, + "version" => { + request_location_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _paws_notify_spectrum_use(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsNotifySpectrumUseRequest = Default::default(); + let mut call = self.hub.paws().notify_spectrum_use(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_device_desc_init(request: &mut api::PawsNotifySpectrumUseRequest) { + if request.device_desc.is_none() { + request.device_desc = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::PawsNotifySpectrumUseRequest) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-desc.etsi-en-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "device-desc.serial-number" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-technology-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-tvbd-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-device-category" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "device-desc.ruleset-ids" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "device-desc.etsi-en-device-emissions-class" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "device-desc.manufacturer-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "device-desc.model-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "type" => { + request_device_desc_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "location.confidence" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().confidence = arg_from_str(value.unwrap_or("-0"), err, "location.confidence", "integer"); + }, + "location.point.semi-minor-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_minor_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-minor-axis", "number"); + }, + "location.point.center.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.latitude", "number"); + }, + "location.point.center.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.longitude", "number"); + }, + "location.point.semi-major-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_major_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-major-axis", "number"); + }, + "location.point.orientation" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.orientation = arg_from_str(value.unwrap_or("0.0"), err, "location.point.orientation", "number"); + }, + "version" => { + request_location_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _paws_register(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsRegisterRequest = Default::default(); + let mut call = self.hub.paws().register(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_antenna_init(request: &mut api::PawsRegisterRequest) { + if request.antenna.is_none() { + request.antenna = Some(Default::default()); + } + } + + fn request_device_desc_init(request: &mut api::PawsRegisterRequest) { + if request.device_desc.is_none() { + request.device_desc = Some(Default::default()); + } + } + + fn request_device_owner_init(request: &mut api::PawsRegisterRequest) { + if request.device_owner.is_none() { + request.device_owner = Some(Default::default()); + } + } + + fn request_location_init(request: &mut api::PawsRegisterRequest) { + if request.location.is_none() { + request.location = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "device-desc.etsi-en-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_id = value.unwrap_or("").to_string(); + }, + "device-desc.serial-number" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().serial_number = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-technology-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_technology_id = value.unwrap_or("").to_string(); + }, + "device-desc.fcc-tvbd-device-type" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().fcc_tvbd_device_type = value.unwrap_or("").to_string(); + }, + "device-desc.etsi-en-device-category" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_category = value.unwrap_or("").to_string(); + }, + "device-desc.ruleset-ids" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().ruleset_ids.push(value.unwrap_or("").to_string()); + }, + "device-desc.etsi-en-device-emissions-class" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().etsi_en_device_emissions_class = value.unwrap_or("").to_string(); + }, + "device-desc.manufacturer-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().manufacturer_id = value.unwrap_or("").to_string(); + }, + "device-desc.model-id" => { + request_device_desc_init(&mut request); + request.device_desc.as_mut().unwrap().model_id = value.unwrap_or("").to_string(); + }, + "antenna.height-type" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_type = value.unwrap_or("").to_string(); + }, + "antenna.height-uncertainty" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height_uncertainty = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height-uncertainty", "number"); + }, + "antenna.height" => { + request_antenna_init(&mut request); + request.antenna.as_mut().unwrap().height = arg_from_str(value.unwrap_or("0.0"), err, "antenna.height", "number"); + }, + "device-owner.operator.org.text" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.org.text = value.unwrap_or("").to_string(); + }, + "device-owner.operator.tel.uri" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.tel.uri = value.unwrap_or("").to_string(); + }, + "device-owner.operator.email.text" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.email.text = value.unwrap_or("").to_string(); + }, + "device-owner.operator.fn" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.fn_ = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.code" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.code = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.locality" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.locality = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.country" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.country = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.region" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.region = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.pobox" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.pobox = value.unwrap_or("").to_string(); + }, + "device-owner.operator.adr.street" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().operator.adr.street = value.unwrap_or("").to_string(); + }, + "device-owner.owner.org.text" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.org.text = value.unwrap_or("").to_string(); + }, + "device-owner.owner.tel.uri" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.tel.uri = value.unwrap_or("").to_string(); + }, + "device-owner.owner.email.text" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.email.text = value.unwrap_or("").to_string(); + }, + "device-owner.owner.fn" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.fn_ = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.code" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.code = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.locality" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.locality = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.country" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.country = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.region" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.region = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.pobox" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.pobox = value.unwrap_or("").to_string(); + }, + "device-owner.owner.adr.street" => { + request_device_owner_init(&mut request); + request.device_owner.as_mut().unwrap().owner.adr.street = value.unwrap_or("").to_string(); + }, + "version" => { + request_device_owner_init(&mut request); + request.version = Some(value.unwrap_or("").to_string()); + }, + "location.confidence" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().confidence = arg_from_str(value.unwrap_or("-0"), err, "location.confidence", "integer"); + }, + "location.point.semi-minor-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_minor_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-minor-axis", "number"); + }, + "location.point.center.latitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.latitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.latitude", "number"); + }, + "location.point.center.longitude" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.center.longitude = arg_from_str(value.unwrap_or("0.0"), err, "location.point.center.longitude", "number"); + }, + "location.point.semi-major-axis" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.semi_major_axis = arg_from_str(value.unwrap_or("0.0"), err, "location.point.semi-major-axis", "number"); + }, + "location.point.orientation" => { + request_location_init(&mut request); + request.location.as_mut().unwrap().point.orientation = arg_from_str(value.unwrap_or("0.0"), err, "location.point.orientation", "number"); + }, + "type" => { + request_location_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _paws_verify_device(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PawsVerifyDeviceRequest = Default::default(); + let mut call = self.hub.paws().verify_device(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "version" => { + request.version = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_paws { + if self.opt.cmd_get_spectrum { + call_result = self._paws_get_spectrum(dry_run, &mut err); + } else if self.opt.cmd_get_spectrum_batch { + call_result = self._paws_get_spectrum_batch(dry_run, &mut err); + } else if self.opt.cmd_init { + call_result = self._paws_init(dry_run, &mut err); + } else if self.opt.cmd_notify_spectrum_use { + call_result = self._paws_notify_spectrum_use(dry_run, &mut err); + } else if self.opt.cmd_register { + call_result = self._paws_register(dry_run, &mut err); + } else if self.opt.cmd_verify_device { + call_result = self._paws_verify_device(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "spectrum1-explorer-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "spectrum1-explorer", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Spectrum::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/sqladmin1_beta4-cli/Cargo.toml b/gen/sqladmin1_beta4-cli/Cargo.toml new file mode 100644 index 00000000000..fcb61e6c57c --- /dev/null +++ b/gen/sqladmin1_beta4-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-sqladmin1_beta4-cli" +version = "0.0.1+20150305" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with SQL Admin (protocol v1beta4)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/sqladmin1_beta4-cli" +homepage = "https://developers.google.com/cloud-sql/docs/admin-api/" +documentation = "http://byron.github.io/google-apis-rs/google_sqladmin1_beta4_cli" +license = "MIT" +keywords = ["sqladmin", "google", "cli"] + +[[bin]] +name = "sqladmin1-beta4" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-sqladmin1_beta4] +path = "../sqladmin1_beta4" diff --git a/gen/sqladmin1_beta4-cli/LICENSE.md b/gen/sqladmin1_beta4-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/sqladmin1_beta4-cli/LICENSE.md @@ -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. diff --git a/gen/sqladmin1_beta4-cli/README.md b/gen/sqladmin1_beta4-cli/README.md new file mode 100644 index 00000000000..3444fb3fd07 --- /dev/null +++ b/gen/sqladmin1_beta4-cli/README.md @@ -0,0 +1,4 @@ +# HELLO SQLADMIN:V1BETA4 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/sqladmin1_beta4-cli/mkdocs.yml b/gen/sqladmin1_beta4-cli/mkdocs.yml new file mode 100644 index 00000000000..8c97be99195 --- /dev/null +++ b/gen/sqladmin1_beta4-cli/mkdocs.yml @@ -0,0 +1,51 @@ +site_name: SQL Admin v0.0.1+20150305 +site_url: http://byron.github.io/google-apis-rs/google-sqladmin1_beta4-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/sqladmin1_beta4-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['backup-runs_get.md', 'Backup Runs', 'Get'] +- ['backup-runs_list.md', 'Backup Runs', 'List'] +- ['databases_delete.md', 'Databases', 'Delete'] +- ['databases_get.md', 'Databases', 'Get'] +- ['databases_insert.md', 'Databases', 'Insert'] +- ['databases_list.md', 'Databases', 'List'] +- ['databases_patch.md', 'Databases', 'Patch'] +- ['databases_update.md', 'Databases', 'Update'] +- ['flags_list.md', 'Flags', 'List'] +- ['instances_clone.md', 'Instances', 'Clone'] +- ['instances_delete.md', 'Instances', 'Delete'] +- ['instances_export.md', 'Instances', 'Export'] +- ['instances_get.md', 'Instances', 'Get'] +- ['instances_import.md', 'Instances', 'Import'] +- ['instances_insert.md', 'Instances', 'Insert'] +- ['instances_list.md', 'Instances', 'List'] +- ['instances_patch.md', 'Instances', 'Patch'] +- ['instances_promote-replica.md', 'Instances', 'Promote Replica'] +- ['instances_reset-ssl-config.md', 'Instances', 'Reset Ssl Config'] +- ['instances_restart.md', 'Instances', 'Restart'] +- ['instances_restore-backup.md', 'Instances', 'Restore Backup'] +- ['instances_start-replica.md', 'Instances', 'Start Replica'] +- ['instances_stop-replica.md', 'Instances', 'Stop Replica'] +- ['instances_update.md', 'Instances', 'Update'] +- ['operations_get.md', 'Operations', 'Get'] +- ['operations_list.md', 'Operations', 'List'] +- ['ssl-certs_delete.md', 'Ssl Certs', 'Delete'] +- ['ssl-certs_get.md', 'Ssl Certs', 'Get'] +- ['ssl-certs_insert.md', 'Ssl Certs', 'Insert'] +- ['ssl-certs_list.md', 'Ssl Certs', 'List'] +- ['tiers_list.md', 'Tiers', 'List'] +- ['users_delete.md', 'Users', 'Delete'] +- ['users_insert.md', 'Users', 'Insert'] +- ['users_list.md', 'Users', 'List'] +- ['users_update.md', 'Users', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/sqladmin1_beta4-cli/src/cmn.rs b/gen/sqladmin1_beta4-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/sqladmin1_beta4-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/sqladmin1_beta4-cli/src/main.rs b/gen/sqladmin1_beta4-cli/src/main.rs new file mode 100644 index 00000000000..8b4f12654ff --- /dev/null +++ b/gen/sqladmin1_beta4-cli/src/main.rs @@ -0,0 +1,2956 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_sqladmin1_beta4 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + sqladmin1-beta4 [options] backup-runs get <project> <instance> <id> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] backup-runs list <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases delete <project> <instance> <database> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases get <project> <instance> <database> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases insert <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases list <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases patch <project> <instance> <database> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] databases update <project> <instance> <database> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] flags list [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances clone <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances delete <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances export <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances get <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances import <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances insert <project> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances list <project> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances patch <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances promote-replica <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances reset-ssl-config <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances restart <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances restore-backup <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances start-replica <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances stop-replica <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] instances update <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] operations get <project> <operation> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] operations list <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] ssl-certs delete <project> <instance> <sha1-fingerprint> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] ssl-certs get <project> <instance> <sha1-fingerprint> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] ssl-certs insert <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] ssl-certs list <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] tiers list <project> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] users delete <project> <instance> <host> <name> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] users insert <project> <instance> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] users list <project> <instance> [-p <v>]... [-o <out>] + sqladmin1-beta4 [options] users update <project> <instance> <host> <name> -r <kv>... [-p <v>]... [-o <out>] + sqladmin1-beta4 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::SQLAdmin<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _backup_runs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.backup_runs().get(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _backup_runs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.backup_runs().list(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.databases().delete(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_database); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.databases().get(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_database); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Database = Default::default(); + let mut call = self.hub.databases().insert(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "charset" => { + request.charset = Some(value.unwrap_or("").to_string()); + }, + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "collation" => { + request.collation = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.databases().list(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Database = Default::default(); + let mut call = self.hub.databases().patch(&request, &self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_database); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "charset" => { + request.charset = Some(value.unwrap_or("").to_string()); + }, + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "collation" => { + request.collation = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _databases_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Database = Default::default(); + let mut call = self.hub.databases().update(&request, &self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_database); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "charset" => { + request.charset = Some(value.unwrap_or("").to_string()); + }, + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "collation" => { + request.collation = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _flags_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.flags().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_clone(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstancesCloneRequest = Default::default(); + let mut call = self.hub.instances().clone(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_clone_context_init(request: &mut api::InstancesCloneRequest) { + if request.clone_context.is_none() { + request.clone_context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "clone-context.bin-log-coordinates.bin-log-position" => { + request_clone_context_init(&mut request); + request.clone_context.as_mut().unwrap().bin_log_coordinates.bin_log_position = value.unwrap_or("").to_string(); + }, + "clone-context.bin-log-coordinates.kind" => { + request_clone_context_init(&mut request); + request.clone_context.as_mut().unwrap().bin_log_coordinates.kind = value.unwrap_or("").to_string(); + }, + "clone-context.bin-log-coordinates.bin-log-file-name" => { + request_clone_context_init(&mut request); + request.clone_context.as_mut().unwrap().bin_log_coordinates.bin_log_file_name = value.unwrap_or("").to_string(); + }, + "clone-context.kind" => { + request_clone_context_init(&mut request); + request.clone_context.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "clone-context.destination-instance-name" => { + request_clone_context_init(&mut request); + request.clone_context.as_mut().unwrap().destination_instance_name = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().delete(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_export(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstancesExportRequest = Default::default(); + let mut call = self.hub.instances().export(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_export_context_init(request: &mut api::InstancesExportRequest) { + if request.export_context.is_none() { + request.export_context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "export-context.kind" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "export-context.file-type" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().file_type = value.unwrap_or("").to_string(); + }, + "export-context.uri" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().uri = value.unwrap_or("").to_string(); + }, + "export-context.csv-export-options.select-query" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().csv_export_options.select_query = value.unwrap_or("").to_string(); + }, + "export-context.databases" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().databases.push(value.unwrap_or("").to_string()); + }, + "export-context.sql-export-options.tables" => { + request_export_context_init(&mut request); + request.export_context.as_mut().unwrap().sql_export_options.tables.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().get(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_import(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstancesImportRequest = Default::default(); + let mut call = self.hub.instances().import(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_import_context_init(request: &mut api::InstancesImportRequest) { + if request.import_context.is_none() { + request.import_context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "import-context.file-type" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().file_type = value.unwrap_or("").to_string(); + }, + "import-context.database" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().database = value.unwrap_or("").to_string(); + }, + "import-context.uri" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().uri = value.unwrap_or("").to_string(); + }, + "import-context.kind" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "import-context.csv-import-options.table" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().csv_import_options.table = value.unwrap_or("").to_string(); + }, + "import-context.csv-import-options.columns" => { + request_import_context_init(&mut request); + request.import_context.as_mut().unwrap().csv_import_options.columns.push(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DatabaseInstance = Default::default(); + let mut call = self.hub.instances().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_on_premises_configuration_init(request: &mut api::DatabaseInstance) { + if request.on_premises_configuration.is_none() { + request.on_premises_configuration = Some(Default::default()); + } + } + + fn request_replica_configuration_init(request: &mut api::DatabaseInstance) { + if request.replica_configuration.is_none() { + request.replica_configuration = Some(Default::default()); + } + } + + fn request_server_ca_cert_init(request: &mut api::DatabaseInstance) { + if request.server_ca_cert.is_none() { + request.server_ca_cert = Some(Default::default()); + } + } + + fn request_settings_init(request: &mut api::DatabaseInstance) { + if request.settings.is_none() { + request.settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "on-premises-configuration.kind" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "on-premises-configuration.host-port" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().host_port = value.unwrap_or("").to_string(); + }, + "kind" => { + request_on_premises_configuration_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "max-disk-size" => { + request_on_premises_configuration_init(&mut request); + request.max_disk_size = Some(value.unwrap_or("").to_string()); + }, + "ipv6-address" => { + request_on_premises_configuration_init(&mut request); + request.ipv6_address = Some(value.unwrap_or("").to_string()); + }, + "server-ca-cert.cert-serial-number" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert_serial_number = value.unwrap_or("").to_string(); + }, + "server-ca-cert.kind" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "server-ca-cert.sha1-fingerprint" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().sha1_fingerprint = value.unwrap_or("").to_string(); + }, + "server-ca-cert.common-name" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().common_name = value.unwrap_or("").to_string(); + }, + "server-ca-cert.instance" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().instance = value.unwrap_or("").to_string(); + }, + "server-ca-cert.cert" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert = value.unwrap_or("").to_string(); + }, + "server-ca-cert.expiration-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().expiration_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.create-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().create_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.self-link" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "replica-names" => { + request_server_ca_cert_init(&mut request); + if request.replica_names.is_none() { + request.replica_names = Some(Default::default()); + } + request.replica_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "project" => { + request_server_ca_cert_init(&mut request); + request.project = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request_server_ca_cert_init(&mut request); + request.region = Some(value.unwrap_or("").to_string()); + }, + "settings.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "settings.authorized-gae-applications" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().authorized_gae_applications.push(value.unwrap_or("").to_string()); + }, + "settings.activation-policy" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().activation_policy = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.kind = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.enabled", "boolean"); + }, + "settings.backup-configuration.start-time" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.start_time = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.binary-log-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.binary_log_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.binary-log-enabled", "boolean"); + }, + "settings.ip-configuration.ipv4-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.ipv4_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.ipv4-enabled", "boolean"); + }, + "settings.ip-configuration.require-ssl" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.require_ssl = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.require-ssl", "boolean"); + }, + "settings.tier" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().tier = value.unwrap_or("").to_string(); + }, + "settings.database-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().database_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.database-replication-enabled", "boolean"); + }, + "settings.replication-type" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().replication_type = value.unwrap_or("").to_string(); + }, + "settings.crash-safe-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().crash_safe_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.crash-safe-replication-enabled", "boolean"); + }, + "settings.pricing-plan" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().pricing_plan = value.unwrap_or("").to_string(); + }, + "settings.settings-version" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().settings_version = value.unwrap_or("").to_string(); + }, + "settings.location-preference.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.kind = value.unwrap_or("").to_string(); + }, + "settings.location-preference.zone" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.zone = value.unwrap_or("").to_string(); + }, + "settings.location-preference.follow-gae-application" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.follow_gae_application = value.unwrap_or("").to_string(); + }, + "master-instance-name" => { + request_settings_init(&mut request); + request.master_instance_name = Some(value.unwrap_or("").to_string()); + }, + "current-disk-size" => { + request_settings_init(&mut request); + request.current_disk_size = Some(value.unwrap_or("").to_string()); + }, + "state" => { + request_settings_init(&mut request); + request.state = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_settings_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "service-account-email-address" => { + request_settings_init(&mut request); + request.service_account_email_address = Some(value.unwrap_or("").to_string()); + }, + "replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.username" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.username = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.connect-retry-interval" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.connect_retry_interval = arg_from_str(value.unwrap_or("-0"), err, "replica-configuration.mysql-replica-configuration.connect-retry-interval", "integer"); + }, + "replica-configuration.mysql-replica-configuration.ssl-cipher" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ssl_cipher = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.ca-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ca_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.master-heartbeat-period" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.master_heartbeat_period = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.verify-server-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.verify_server_certificate = arg_from_str(value.unwrap_or("false"), err, "replica-configuration.mysql-replica-configuration.verify-server-certificate", "boolean"); + }, + "replica-configuration.mysql-replica-configuration.dump-file-path" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.dump_file_path = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.password" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.password = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-key" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_key = value.unwrap_or("").to_string(); + }, + "database-version" => { + request_replica_configuration_init(&mut request); + request.database_version = Some(value.unwrap_or("").to_string()); + }, + "instance-type" => { + request_replica_configuration_init(&mut request); + request.instance_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replica_configuration_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_replica_configuration_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DatabaseInstance = Default::default(); + let mut call = self.hub.instances().patch(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_on_premises_configuration_init(request: &mut api::DatabaseInstance) { + if request.on_premises_configuration.is_none() { + request.on_premises_configuration = Some(Default::default()); + } + } + + fn request_replica_configuration_init(request: &mut api::DatabaseInstance) { + if request.replica_configuration.is_none() { + request.replica_configuration = Some(Default::default()); + } + } + + fn request_server_ca_cert_init(request: &mut api::DatabaseInstance) { + if request.server_ca_cert.is_none() { + request.server_ca_cert = Some(Default::default()); + } + } + + fn request_settings_init(request: &mut api::DatabaseInstance) { + if request.settings.is_none() { + request.settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "on-premises-configuration.kind" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "on-premises-configuration.host-port" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().host_port = value.unwrap_or("").to_string(); + }, + "kind" => { + request_on_premises_configuration_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "max-disk-size" => { + request_on_premises_configuration_init(&mut request); + request.max_disk_size = Some(value.unwrap_or("").to_string()); + }, + "ipv6-address" => { + request_on_premises_configuration_init(&mut request); + request.ipv6_address = Some(value.unwrap_or("").to_string()); + }, + "server-ca-cert.cert-serial-number" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert_serial_number = value.unwrap_or("").to_string(); + }, + "server-ca-cert.kind" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "server-ca-cert.sha1-fingerprint" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().sha1_fingerprint = value.unwrap_or("").to_string(); + }, + "server-ca-cert.common-name" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().common_name = value.unwrap_or("").to_string(); + }, + "server-ca-cert.instance" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().instance = value.unwrap_or("").to_string(); + }, + "server-ca-cert.cert" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert = value.unwrap_or("").to_string(); + }, + "server-ca-cert.expiration-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().expiration_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.create-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().create_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.self-link" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "replica-names" => { + request_server_ca_cert_init(&mut request); + if request.replica_names.is_none() { + request.replica_names = Some(Default::default()); + } + request.replica_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "project" => { + request_server_ca_cert_init(&mut request); + request.project = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request_server_ca_cert_init(&mut request); + request.region = Some(value.unwrap_or("").to_string()); + }, + "settings.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "settings.authorized-gae-applications" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().authorized_gae_applications.push(value.unwrap_or("").to_string()); + }, + "settings.activation-policy" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().activation_policy = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.kind = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.enabled", "boolean"); + }, + "settings.backup-configuration.start-time" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.start_time = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.binary-log-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.binary_log_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.binary-log-enabled", "boolean"); + }, + "settings.ip-configuration.ipv4-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.ipv4_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.ipv4-enabled", "boolean"); + }, + "settings.ip-configuration.require-ssl" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.require_ssl = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.require-ssl", "boolean"); + }, + "settings.tier" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().tier = value.unwrap_or("").to_string(); + }, + "settings.database-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().database_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.database-replication-enabled", "boolean"); + }, + "settings.replication-type" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().replication_type = value.unwrap_or("").to_string(); + }, + "settings.crash-safe-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().crash_safe_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.crash-safe-replication-enabled", "boolean"); + }, + "settings.pricing-plan" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().pricing_plan = value.unwrap_or("").to_string(); + }, + "settings.settings-version" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().settings_version = value.unwrap_or("").to_string(); + }, + "settings.location-preference.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.kind = value.unwrap_or("").to_string(); + }, + "settings.location-preference.zone" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.zone = value.unwrap_or("").to_string(); + }, + "settings.location-preference.follow-gae-application" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.follow_gae_application = value.unwrap_or("").to_string(); + }, + "master-instance-name" => { + request_settings_init(&mut request); + request.master_instance_name = Some(value.unwrap_or("").to_string()); + }, + "current-disk-size" => { + request_settings_init(&mut request); + request.current_disk_size = Some(value.unwrap_or("").to_string()); + }, + "state" => { + request_settings_init(&mut request); + request.state = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_settings_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "service-account-email-address" => { + request_settings_init(&mut request); + request.service_account_email_address = Some(value.unwrap_or("").to_string()); + }, + "replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.username" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.username = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.connect-retry-interval" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.connect_retry_interval = arg_from_str(value.unwrap_or("-0"), err, "replica-configuration.mysql-replica-configuration.connect-retry-interval", "integer"); + }, + "replica-configuration.mysql-replica-configuration.ssl-cipher" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ssl_cipher = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.ca-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ca_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.master-heartbeat-period" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.master_heartbeat_period = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.verify-server-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.verify_server_certificate = arg_from_str(value.unwrap_or("false"), err, "replica-configuration.mysql-replica-configuration.verify-server-certificate", "boolean"); + }, + "replica-configuration.mysql-replica-configuration.dump-file-path" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.dump_file_path = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.password" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.password = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-key" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_key = value.unwrap_or("").to_string(); + }, + "database-version" => { + request_replica_configuration_init(&mut request); + request.database_version = Some(value.unwrap_or("").to_string()); + }, + "instance-type" => { + request_replica_configuration_init(&mut request); + request.instance_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replica_configuration_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_replica_configuration_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_promote_replica(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().promote_replica(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_reset_ssl_config(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().reset_ssl_config(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_restart(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().restart(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_restore_backup(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InstancesRestoreBackupRequest = Default::default(); + let mut call = self.hub.instances().restore_backup(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_restore_backup_context_init(request: &mut api::InstancesRestoreBackupRequest) { + if request.restore_backup_context.is_none() { + request.restore_backup_context = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "restore-backup-context.kind" => { + request_restore_backup_context_init(&mut request); + request.restore_backup_context.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "restore-backup-context.backup-run-id" => { + request_restore_backup_context_init(&mut request); + request.restore_backup_context.as_mut().unwrap().backup_run_id = value.unwrap_or("").to_string(); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_start_replica(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().start_replica(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_stop_replica(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.instances().stop_replica(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _instances_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::DatabaseInstance = Default::default(); + let mut call = self.hub.instances().update(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_on_premises_configuration_init(request: &mut api::DatabaseInstance) { + if request.on_premises_configuration.is_none() { + request.on_premises_configuration = Some(Default::default()); + } + } + + fn request_replica_configuration_init(request: &mut api::DatabaseInstance) { + if request.replica_configuration.is_none() { + request.replica_configuration = Some(Default::default()); + } + } + + fn request_server_ca_cert_init(request: &mut api::DatabaseInstance) { + if request.server_ca_cert.is_none() { + request.server_ca_cert = Some(Default::default()); + } + } + + fn request_settings_init(request: &mut api::DatabaseInstance) { + if request.settings.is_none() { + request.settings = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "on-premises-configuration.kind" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "on-premises-configuration.host-port" => { + request_on_premises_configuration_init(&mut request); + request.on_premises_configuration.as_mut().unwrap().host_port = value.unwrap_or("").to_string(); + }, + "kind" => { + request_on_premises_configuration_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "max-disk-size" => { + request_on_premises_configuration_init(&mut request); + request.max_disk_size = Some(value.unwrap_or("").to_string()); + }, + "ipv6-address" => { + request_on_premises_configuration_init(&mut request); + request.ipv6_address = Some(value.unwrap_or("").to_string()); + }, + "server-ca-cert.cert-serial-number" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert_serial_number = value.unwrap_or("").to_string(); + }, + "server-ca-cert.kind" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "server-ca-cert.sha1-fingerprint" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().sha1_fingerprint = value.unwrap_or("").to_string(); + }, + "server-ca-cert.common-name" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().common_name = value.unwrap_or("").to_string(); + }, + "server-ca-cert.instance" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().instance = value.unwrap_or("").to_string(); + }, + "server-ca-cert.cert" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().cert = value.unwrap_or("").to_string(); + }, + "server-ca-cert.expiration-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().expiration_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.create-time" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().create_time = value.unwrap_or("").to_string(); + }, + "server-ca-cert.self-link" => { + request_server_ca_cert_init(&mut request); + request.server_ca_cert.as_mut().unwrap().self_link = value.unwrap_or("").to_string(); + }, + "replica-names" => { + request_server_ca_cert_init(&mut request); + if request.replica_names.is_none() { + request.replica_names = Some(Default::default()); + } + request.replica_names.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "project" => { + request_server_ca_cert_init(&mut request); + request.project = Some(value.unwrap_or("").to_string()); + }, + "region" => { + request_server_ca_cert_init(&mut request); + request.region = Some(value.unwrap_or("").to_string()); + }, + "settings.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "settings.authorized-gae-applications" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().authorized_gae_applications.push(value.unwrap_or("").to_string()); + }, + "settings.activation-policy" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().activation_policy = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.kind = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.enabled", "boolean"); + }, + "settings.backup-configuration.start-time" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.start_time = value.unwrap_or("").to_string(); + }, + "settings.backup-configuration.binary-log-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().backup_configuration.binary_log_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.backup-configuration.binary-log-enabled", "boolean"); + }, + "settings.ip-configuration.ipv4-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.ipv4_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.ipv4-enabled", "boolean"); + }, + "settings.ip-configuration.require-ssl" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().ip_configuration.require_ssl = arg_from_str(value.unwrap_or("false"), err, "settings.ip-configuration.require-ssl", "boolean"); + }, + "settings.tier" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().tier = value.unwrap_or("").to_string(); + }, + "settings.database-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().database_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.database-replication-enabled", "boolean"); + }, + "settings.replication-type" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().replication_type = value.unwrap_or("").to_string(); + }, + "settings.crash-safe-replication-enabled" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().crash_safe_replication_enabled = arg_from_str(value.unwrap_or("false"), err, "settings.crash-safe-replication-enabled", "boolean"); + }, + "settings.pricing-plan" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().pricing_plan = value.unwrap_or("").to_string(); + }, + "settings.settings-version" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().settings_version = value.unwrap_or("").to_string(); + }, + "settings.location-preference.kind" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.kind = value.unwrap_or("").to_string(); + }, + "settings.location-preference.zone" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.zone = value.unwrap_or("").to_string(); + }, + "settings.location-preference.follow-gae-application" => { + request_settings_init(&mut request); + request.settings.as_mut().unwrap().location_preference.follow_gae_application = value.unwrap_or("").to_string(); + }, + "master-instance-name" => { + request_settings_init(&mut request); + request.master_instance_name = Some(value.unwrap_or("").to_string()); + }, + "current-disk-size" => { + request_settings_init(&mut request); + request.current_disk_size = Some(value.unwrap_or("").to_string()); + }, + "state" => { + request_settings_init(&mut request); + request.state = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_settings_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "service-account-email-address" => { + request_settings_init(&mut request); + request.service_account_email_address = Some(value.unwrap_or("").to_string()); + }, + "replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.username" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.username = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.kind" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.kind = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.connect-retry-interval" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.connect_retry_interval = arg_from_str(value.unwrap_or("-0"), err, "replica-configuration.mysql-replica-configuration.connect-retry-interval", "integer"); + }, + "replica-configuration.mysql-replica-configuration.ssl-cipher" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ssl_cipher = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.ca-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.ca_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_certificate = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.master-heartbeat-period" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.master_heartbeat_period = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.verify-server-certificate" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.verify_server_certificate = arg_from_str(value.unwrap_or("false"), err, "replica-configuration.mysql-replica-configuration.verify-server-certificate", "boolean"); + }, + "replica-configuration.mysql-replica-configuration.dump-file-path" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.dump_file_path = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.password" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.password = value.unwrap_or("").to_string(); + }, + "replica-configuration.mysql-replica-configuration.client-key" => { + request_replica_configuration_init(&mut request); + request.replica_configuration.as_mut().unwrap().mysql_replica_configuration.client_key = value.unwrap_or("").to_string(); + }, + "database-version" => { + request_replica_configuration_init(&mut request); + request.database_version = Some(value.unwrap_or("").to_string()); + }, + "instance-type" => { + request_replica_configuration_init(&mut request); + request.instance_type = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_replica_configuration_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_replica_configuration_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operations_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operations().get(&self.opt.arg_project, &self.opt.arg_operation); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _operations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.operations().list(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ssl_certs_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.ssl_certs().delete(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_sha1_fingerprint); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ssl_certs_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.ssl_certs().get(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_sha1_fingerprint); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ssl_certs_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::SslCertsInsertRequest = Default::default(); + let mut call = self.hub.ssl_certs().insert(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "common-name" => { + request.common_name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _ssl_certs_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.ssl_certs().list(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tiers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tiers().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().delete(&self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_host, &self.opt.arg_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::User = Default::default(); + let mut call = self.hub.users().insert(&request, &self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "host" => { + request.host = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.users().list(&self.opt.arg_project, &self.opt.arg_instance); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _users_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::User = Default::default(); + let mut call = self.hub.users().update(&request, &self.opt.arg_project, &self.opt.arg_instance, &self.opt.arg_host, &self.opt.arg_name); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "project" => { + request.project = Some(value.unwrap_or("").to_string()); + }, + "instance" => { + request.instance = Some(value.unwrap_or("").to_string()); + }, + "host" => { + request.host = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "password" => { + request.password = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_backup_runs { + if self.opt.cmd_get { + call_result = self._backup_runs_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._backup_runs_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_databases { + if self.opt.cmd_delete { + call_result = self._databases_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._databases_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._databases_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._databases_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._databases_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._databases_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_flags { + if self.opt.cmd_list { + call_result = self._flags_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_instances { + if self.opt.cmd_clone { + call_result = self._instances_clone(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._instances_delete(dry_run, &mut err); + } else if self.opt.cmd_export { + call_result = self._instances_export(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._instances_get(dry_run, &mut err); + } else if self.opt.cmd_import { + call_result = self._instances_import(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._instances_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._instances_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._instances_patch(dry_run, &mut err); + } else if self.opt.cmd_promote_replica { + call_result = self._instances_promote_replica(dry_run, &mut err); + } else if self.opt.cmd_reset_ssl_config { + call_result = self._instances_reset_ssl_config(dry_run, &mut err); + } else if self.opt.cmd_restart { + call_result = self._instances_restart(dry_run, &mut err); + } else if self.opt.cmd_restore_backup { + call_result = self._instances_restore_backup(dry_run, &mut err); + } else if self.opt.cmd_start_replica { + call_result = self._instances_start_replica(dry_run, &mut err); + } else if self.opt.cmd_stop_replica { + call_result = self._instances_stop_replica(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._instances_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_operations { + if self.opt.cmd_get { + call_result = self._operations_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._operations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_ssl_certs { + if self.opt.cmd_delete { + call_result = self._ssl_certs_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._ssl_certs_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._ssl_certs_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._ssl_certs_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tiers { + if self.opt.cmd_list { + call_result = self._tiers_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_users { + if self.opt.cmd_delete { + call_result = self._users_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._users_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._users_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._users_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "sqladmin1-beta4-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "sqladmin1-beta4", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::SQLAdmin::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/storage1-cli/Cargo.toml b/gen/storage1-cli/Cargo.toml new file mode 100644 index 00000000000..6d59861e813 --- /dev/null +++ b/gen/storage1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-storage1-cli" +version = "0.0.1+20150326" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with storage (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/storage1-cli" +homepage = "https://developers.google.com/storage/docs/json_api/" +documentation = "http://byron.github.io/google-apis-rs/google_storage1_cli" +license = "MIT" +keywords = ["storage", "google", "cli"] + +[[bin]] +name = "storage1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-storage1] +path = "../storage1" diff --git a/gen/storage1-cli/LICENSE.md b/gen/storage1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/storage1-cli/LICENSE.md @@ -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. diff --git a/gen/storage1-cli/README.md b/gen/storage1-cli/README.md new file mode 100644 index 00000000000..fd4488293c9 --- /dev/null +++ b/gen/storage1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO STORAGE:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/storage1-cli/mkdocs.yml b/gen/storage1-cli/mkdocs.yml new file mode 100644 index 00000000000..5c351c13098 --- /dev/null +++ b/gen/storage1-cli/mkdocs.yml @@ -0,0 +1,50 @@ +site_name: storage v0.0.1+20150326 +site_url: http://byron.github.io/google-apis-rs/google-storage1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/storage1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['bucket-access-controls_delete.md', 'Bucket Access Controls', 'Delete'] +- ['bucket-access-controls_get.md', 'Bucket Access Controls', 'Get'] +- ['bucket-access-controls_insert.md', 'Bucket Access Controls', 'Insert'] +- ['bucket-access-controls_list.md', 'Bucket Access Controls', 'List'] +- ['bucket-access-controls_patch.md', 'Bucket Access Controls', 'Patch'] +- ['bucket-access-controls_update.md', 'Bucket Access Controls', 'Update'] +- ['buckets_delete.md', 'Buckets', 'Delete'] +- ['buckets_get.md', 'Buckets', 'Get'] +- ['buckets_insert.md', 'Buckets', 'Insert'] +- ['buckets_list.md', 'Buckets', 'List'] +- ['buckets_patch.md', 'Buckets', 'Patch'] +- ['buckets_update.md', 'Buckets', 'Update'] +- ['channels_stop.md', 'Channels', 'Stop'] +- ['default-object-access-controls_delete.md', 'Default Object Access Controls', 'Delete'] +- ['default-object-access-controls_get.md', 'Default Object Access Controls', 'Get'] +- ['default-object-access-controls_insert.md', 'Default Object Access Controls', 'Insert'] +- ['default-object-access-controls_list.md', 'Default Object Access Controls', 'List'] +- ['default-object-access-controls_patch.md', 'Default Object Access Controls', 'Patch'] +- ['default-object-access-controls_update.md', 'Default Object Access Controls', 'Update'] +- ['object-access-controls_delete.md', 'Object Access Controls', 'Delete'] +- ['object-access-controls_get.md', 'Object Access Controls', 'Get'] +- ['object-access-controls_insert.md', 'Object Access Controls', 'Insert'] +- ['object-access-controls_list.md', 'Object Access Controls', 'List'] +- ['object-access-controls_patch.md', 'Object Access Controls', 'Patch'] +- ['object-access-controls_update.md', 'Object Access Controls', 'Update'] +- ['objects_compose.md', 'Objects', 'Compose'] +- ['objects_copy.md', 'Objects', 'Copy'] +- ['objects_delete.md', 'Objects', 'Delete'] +- ['objects_get.md', 'Objects', 'Get'] +- ['objects_insert.md', 'Objects', 'Insert'] +- ['objects_list.md', 'Objects', 'List'] +- ['objects_patch.md', 'Objects', 'Patch'] +- ['objects_update.md', 'Objects', 'Update'] +- ['objects_watch-all.md', 'Objects', 'Watch All'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/storage1-cli/src/cmn.rs b/gen/storage1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/storage1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/storage1-cli/src/main.rs b/gen/storage1-cli/src/main.rs new file mode 100644 index 00000000000..c3d1b62e630 --- /dev/null +++ b/gen/storage1-cli/src/main.rs @@ -0,0 +1,3654 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_storage1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + storage1 [options] bucket-access-controls delete <bucket> <entity> [-p <v>]... + storage1 [options] bucket-access-controls get <bucket> <entity> [-p <v>]... [-o <out>] + storage1 [options] bucket-access-controls insert <bucket> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] bucket-access-controls list <bucket> [-p <v>]... [-o <out>] + storage1 [options] bucket-access-controls patch <bucket> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] bucket-access-controls update <bucket> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] buckets delete <bucket> [-p <v>]... + storage1 [options] buckets get <bucket> [-p <v>]... [-o <out>] + storage1 [options] buckets insert <project> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] buckets list <project> [-p <v>]... [-o <out>] + storage1 [options] buckets patch <bucket> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] buckets update <bucket> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] channels stop -r <kv>... [-p <v>]... + storage1 [options] default-object-access-controls delete <bucket> <entity> [-p <v>]... + storage1 [options] default-object-access-controls get <bucket> <entity> [-p <v>]... [-o <out>] + storage1 [options] default-object-access-controls insert <bucket> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] default-object-access-controls list <bucket> [-p <v>]... [-o <out>] + storage1 [options] default-object-access-controls patch <bucket> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] default-object-access-controls update <bucket> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] object-access-controls delete <bucket> <object> <entity> [-p <v>]... + storage1 [options] object-access-controls get <bucket> <object> <entity> [-p <v>]... [-o <out>] + storage1 [options] object-access-controls insert <bucket> <object> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] object-access-controls list <bucket> <object> [-p <v>]... [-o <out>] + storage1 [options] object-access-controls patch <bucket> <object> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] object-access-controls update <bucket> <object> <entity> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] objects compose <destination-bucket> <destination-object> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] objects copy <source-bucket> <source-object> <destination-bucket> <destination-object> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] objects delete <bucket> <object> [-p <v>]... + storage1 [options] objects get <bucket> <object> [-p <v>]... [-o <out>] + storage1 [options] objects insert <bucket> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + storage1 [options] objects list <bucket> [-p <v>]... [-o <out>] + storage1 [options] objects patch <bucket> <object> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] objects update <bucket> <object> -r <kv>... [-p <v>]... [-o <out>] + storage1 [options] objects watch-all <bucket> -r <kv>... [-p <v>]... [-o <out>] + storage1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Storage<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _bucket_access_controls_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.bucket_access_controls().delete(&self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _bucket_access_controls_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.bucket_access_controls().get(&self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bucket_access_controls_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::BucketAccessControl = Default::default(); + let mut call = self.hub.bucket_access_controls().insert(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::BucketAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bucket_access_controls_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.bucket_access_controls().list(&self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bucket_access_controls_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::BucketAccessControl = Default::default(); + let mut call = self.hub.bucket_access_controls().patch(&request, &self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::BucketAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _bucket_access_controls_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::BucketAccessControl = Default::default(); + let mut call = self.hub.bucket_access_controls().update(&request, &self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::BucketAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _buckets_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.buckets().delete(&self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _buckets_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.buckets().get(&self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _buckets_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Bucket = Default::default(); + let mut call = self.hub.buckets().insert(&request, &self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-default-object-acl" => { + call = call.predefined_default_object_acl(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_logging_init(request: &mut api::Bucket) { + if request.logging.is_none() { + request.logging = Some(Default::default()); + } + } + + fn request_owner_init(request: &mut api::Bucket) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + fn request_versioning_init(request: &mut api::Bucket) { + if request.versioning.is_none() { + request.versioning = Some(Default::default()); + } + } + + fn request_website_init(request: &mut api::Bucket) { + if request.website.is_none() { + request.website = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website.not-found-page" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().not_found_page = value.unwrap_or("").to_string(); + }, + "website.main-page-suffix" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().main_page_suffix = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_website_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_website_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "logging.log-object-prefix" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_object_prefix = value.unwrap_or("").to_string(); + }, + "logging.log-bucket" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_bucket = value.unwrap_or("").to_string(); + }, + "name" => { + request_logging_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "time-created" => { + request_logging_init(&mut request); + request.time_created = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_logging_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request_logging_init(&mut request); + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_logging_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_logging_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "versioning.enabled" => { + request_versioning_init(&mut request); + request.versioning.as_mut().unwrap().enabled = arg_from_str(value.unwrap_or("false"), err, "versioning.enabled", "boolean"); + }, + "storage-class" => { + request_versioning_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _buckets_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.buckets().list(&self.opt.arg_project); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "prefix" => { + call = call.prefix(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _buckets_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Bucket = Default::default(); + let mut call = self.hub.buckets().patch(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-default-object-acl" => { + call = call.predefined_default_object_acl(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_logging_init(request: &mut api::Bucket) { + if request.logging.is_none() { + request.logging = Some(Default::default()); + } + } + + fn request_owner_init(request: &mut api::Bucket) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + fn request_versioning_init(request: &mut api::Bucket) { + if request.versioning.is_none() { + request.versioning = Some(Default::default()); + } + } + + fn request_website_init(request: &mut api::Bucket) { + if request.website.is_none() { + request.website = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website.not-found-page" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().not_found_page = value.unwrap_or("").to_string(); + }, + "website.main-page-suffix" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().main_page_suffix = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_website_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_website_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "logging.log-object-prefix" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_object_prefix = value.unwrap_or("").to_string(); + }, + "logging.log-bucket" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_bucket = value.unwrap_or("").to_string(); + }, + "name" => { + request_logging_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "time-created" => { + request_logging_init(&mut request); + request.time_created = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_logging_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request_logging_init(&mut request); + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_logging_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_logging_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "versioning.enabled" => { + request_versioning_init(&mut request); + request.versioning.as_mut().unwrap().enabled = arg_from_str(value.unwrap_or("false"), err, "versioning.enabled", "boolean"); + }, + "storage-class" => { + request_versioning_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _buckets_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Bucket = Default::default(); + let mut call = self.hub.buckets().update(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-default-object-acl" => { + call = call.predefined_default_object_acl(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_logging_init(request: &mut api::Bucket) { + if request.logging.is_none() { + request.logging = Some(Default::default()); + } + } + + fn request_owner_init(request: &mut api::Bucket) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + fn request_versioning_init(request: &mut api::Bucket) { + if request.versioning.is_none() { + request.versioning = Some(Default::default()); + } + } + + fn request_website_init(request: &mut api::Bucket) { + if request.website.is_none() { + request.website = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "website.not-found-page" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().not_found_page = value.unwrap_or("").to_string(); + }, + "website.main-page-suffix" => { + request_website_init(&mut request); + request.website.as_mut().unwrap().main_page_suffix = value.unwrap_or("").to_string(); + }, + "self-link" => { + request_website_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_website_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "logging.log-object-prefix" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_object_prefix = value.unwrap_or("").to_string(); + }, + "logging.log-bucket" => { + request_logging_init(&mut request); + request.logging.as_mut().unwrap().log_bucket = value.unwrap_or("").to_string(); + }, + "name" => { + request_logging_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "time-created" => { + request_logging_init(&mut request); + request.time_created = Some(value.unwrap_or("").to_string()); + }, + "location" => { + request_logging_init(&mut request); + request.location = Some(value.unwrap_or("").to_string()); + }, + "project-number" => { + request_logging_init(&mut request); + request.project_number = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_logging_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_logging_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "versioning.enabled" => { + request_versioning_init(&mut request); + request.versioning.as_mut().unwrap().enabled = arg_from_str(value.unwrap_or("false"), err, "versioning.enabled", "boolean"); + }, + "storage-class" => { + request_versioning_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_stop(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().stop(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _default_object_access_controls_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.default_object_access_controls().delete(&self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _default_object_access_controls_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.default_object_access_controls().get(&self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _default_object_access_controls_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.default_object_access_controls().insert(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _default_object_access_controls_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.default_object_access_controls().list(&self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _default_object_access_controls_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.default_object_access_controls().patch(&request, &self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _default_object_access_controls_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.default_object_access_controls().update(&request, &self.opt.arg_bucket, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _object_access_controls_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.object_access_controls().delete(&self.opt.arg_bucket, &self.opt.arg_object, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _object_access_controls_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.object_access_controls().get(&self.opt.arg_bucket, &self.opt.arg_object, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _object_access_controls_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.object_access_controls().insert(&request, &self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _object_access_controls_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.object_access_controls().list(&self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _object_access_controls_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.object_access_controls().patch(&request, &self.opt.arg_bucket, &self.opt.arg_object, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _object_access_controls_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ObjectAccessControl = Default::default(); + let mut call = self.hub.object_access_controls().update(&request, &self.opt.arg_bucket, &self.opt.arg_object, &self.opt.arg_entity); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_project_team_init(request: &mut api::ObjectAccessControl) { + if request.project_team.is_none() { + request.project_team = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "domain" => { + request.domain = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "object" => { + request.object = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "entity" => { + request.entity = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "role" => { + request.role = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "entity-id" => { + request.entity_id = Some(value.unwrap_or("").to_string()); + }, + "project-team.project-number" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().project_number = value.unwrap_or("").to_string(); + }, + "project-team.team" => { + request_project_team_init(&mut request); + request.project_team.as_mut().unwrap().team = value.unwrap_or("").to_string(); + }, + "email" => { + request_project_team_init(&mut request); + request.email = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request_project_team_init(&mut request); + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _objects_compose(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ComposeRequest = Default::default(); + let mut download_mode = false; + let mut call = self.hub.objects().compose(&request, &self.opt.arg_destination_bucket, &self.opt.arg_destination_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "destination-predefined-acl" => { + call = call.destination_predefined_acl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_destination_init(request: &mut api::ComposeRequest) { + if request.destination.is_none() { + request.destination = Some(Default::default()); + } + } + + fn request_destination_owner_init(request: &mut api::ComposeRequest) { + request_destination_init(request); + if request.destination.as_mut().unwrap().owner.is_none() { + request.destination.as_mut().unwrap().owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "destination.self-link" => { + request_destination_init(&mut request); + request.destination.as_mut().unwrap().self_link = Some(value.unwrap_or("").to_string()); + }, + "destination.generation" => { + request_destination_init(&mut request); + request.destination.as_mut().unwrap().generation = Some(value.unwrap_or("").to_string()); + }, + "destination.component-count" => { + request_destination_init(&mut request); + request.destination.as_mut().unwrap().component_count = Some(arg_from_str(value.unwrap_or("-0"), err, "destination.component-count", "integer")); + }, + "destination.media-link" => { + request_destination_init(&mut request); + request.destination.as_mut().unwrap().media_link = Some(value.unwrap_or("").to_string()); + }, + "destination.owner.entity-id" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "destination.owner.entity" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "destination.cache-control" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().cache_control = Some(value.unwrap_or("").to_string()); + }, + "destination.id" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().id = Some(value.unwrap_or("").to_string()); + }, + "destination.size" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().size = Some(value.unwrap_or("").to_string()); + }, + "destination.time-deleted" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().time_deleted = Some(value.unwrap_or("").to_string()); + }, + "destination.md5-hash" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().md5_hash = Some(value.unwrap_or("").to_string()); + }, + "destination.crc32c" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().crc32c = Some(value.unwrap_or("").to_string()); + }, + "destination.etag" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().etag = Some(value.unwrap_or("").to_string()); + }, + "destination.metadata" => { + request_destination_owner_init(&mut request); + if request.destination.as_mut().unwrap().metadata.is_none() { + request.destination.as_mut().unwrap().metadata = Some(Default::default()); + } + request.destination.as_mut().unwrap().metadata.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "destination.updated" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().updated = Some(value.unwrap_or("").to_string()); + }, + "destination.content-type" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().content_type = Some(value.unwrap_or("").to_string()); + }, + "destination.content-language" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().content_language = Some(value.unwrap_or("").to_string()); + }, + "destination.metageneration" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().metageneration = Some(value.unwrap_or("").to_string()); + }, + "destination.kind" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().kind = Some(value.unwrap_or("").to_string()); + }, + "destination.name" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "destination.bucket" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().bucket = Some(value.unwrap_or("").to_string()); + }, + "destination.content-encoding" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().content_encoding = Some(value.unwrap_or("").to_string()); + }, + "destination.storage-class" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().storage_class = Some(value.unwrap_or("").to_string()); + }, + "destination.content-disposition" => { + request_destination_owner_init(&mut request); + request.destination.as_mut().unwrap().content_disposition = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _objects_copy(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Object = Default::default(); + let mut download_mode = false; + let mut call = self.hub.objects().copy(&request, &self.opt.arg_source_bucket, &self.opt.arg_source_object, &self.opt.arg_destination_bucket, &self.opt.arg_destination_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source-generation" => { + call = call.source_generation(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "if-source-metageneration-not-match" => { + call = call.if_source_metageneration_not_match(value.unwrap_or("")); + }, + "if-source-metageneration-match" => { + call = call.if_source_metageneration_match(value.unwrap_or("")); + }, + "if-source-generation-not-match" => { + call = call.if_source_generation_not_match(value.unwrap_or("")); + }, + "if-source-generation-match" => { + call = call.if_source_generation_match(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "destination-predefined-acl" => { + call = call.destination_predefined_acl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_owner_init(request: &mut api::Object) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "component-count" => { + request.component_count = Some(arg_from_str(value.unwrap_or("-0"), err, "component-count", "integer")); + }, + "media-link" => { + request.media_link = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "cache-control" => { + request_owner_init(&mut request); + request.cache_control = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size" => { + request_owner_init(&mut request); + request.size = Some(value.unwrap_or("").to_string()); + }, + "time-deleted" => { + request_owner_init(&mut request); + request.time_deleted = Some(value.unwrap_or("").to_string()); + }, + "md5-hash" => { + request_owner_init(&mut request); + request.md5_hash = Some(value.unwrap_or("").to_string()); + }, + "crc32c" => { + request_owner_init(&mut request); + request.crc32c = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_owner_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "metadata" => { + request_owner_init(&mut request); + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + request.metadata.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "updated" => { + request_owner_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request_owner_init(&mut request); + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request_owner_init(&mut request); + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_owner_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_owner_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_owner_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request_owner_init(&mut request); + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "content-encoding" => { + request_owner_init(&mut request); + request.content_encoding = Some(value.unwrap_or("").to_string()); + }, + "storage-class" => { + request_owner_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + "content-disposition" => { + request_owner_init(&mut request); + request.content_disposition = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _objects_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.objects().delete(&self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _objects_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.objects().get(&self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _objects_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Object = Default::default(); + let mut call = self.hub.objects().insert(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "name" => { + call = call.name(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "content-encoding" => { + call = call.content_encoding(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_owner_init(request: &mut api::Object) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "component-count" => { + request.component_count = Some(arg_from_str(value.unwrap_or("-0"), err, "component-count", "integer")); + }, + "media-link" => { + request.media_link = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "cache-control" => { + request_owner_init(&mut request); + request.cache_control = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size" => { + request_owner_init(&mut request); + request.size = Some(value.unwrap_or("").to_string()); + }, + "time-deleted" => { + request_owner_init(&mut request); + request.time_deleted = Some(value.unwrap_or("").to_string()); + }, + "md5-hash" => { + request_owner_init(&mut request); + request.md5_hash = Some(value.unwrap_or("").to_string()); + }, + "crc32c" => { + request_owner_init(&mut request); + request.crc32c = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_owner_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "metadata" => { + request_owner_init(&mut request); + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + request.metadata.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "updated" => { + request_owner_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request_owner_init(&mut request); + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request_owner_init(&mut request); + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_owner_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_owner_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_owner_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request_owner_init(&mut request); + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "content-encoding" => { + request_owner_init(&mut request); + request.content_encoding = Some(value.unwrap_or("").to_string()); + }, + "storage-class" => { + request_owner_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + "content-disposition" => { + request_owner_init(&mut request); + request.content_disposition = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + io::copy(&mut response, &mut ostream).unwrap(); + None + } + } + } + } + + fn _objects_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.objects().list(&self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "versions" => { + call = call.versions(arg_from_str(value.unwrap_or("false"), err, "versions", "boolean")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "prefix" => { + call = call.prefix(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "delimiter" => { + call = call.delimiter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _objects_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Object = Default::default(); + let mut call = self.hub.objects().patch(&request, &self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_owner_init(request: &mut api::Object) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "component-count" => { + request.component_count = Some(arg_from_str(value.unwrap_or("-0"), err, "component-count", "integer")); + }, + "media-link" => { + request.media_link = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "cache-control" => { + request_owner_init(&mut request); + request.cache_control = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size" => { + request_owner_init(&mut request); + request.size = Some(value.unwrap_or("").to_string()); + }, + "time-deleted" => { + request_owner_init(&mut request); + request.time_deleted = Some(value.unwrap_or("").to_string()); + }, + "md5-hash" => { + request_owner_init(&mut request); + request.md5_hash = Some(value.unwrap_or("").to_string()); + }, + "crc32c" => { + request_owner_init(&mut request); + request.crc32c = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_owner_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "metadata" => { + request_owner_init(&mut request); + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + request.metadata.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "updated" => { + request_owner_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request_owner_init(&mut request); + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request_owner_init(&mut request); + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_owner_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_owner_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_owner_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request_owner_init(&mut request); + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "content-encoding" => { + request_owner_init(&mut request); + request.content_encoding = Some(value.unwrap_or("").to_string()); + }, + "storage-class" => { + request_owner_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + "content-disposition" => { + request_owner_init(&mut request); + request.content_disposition = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _objects_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Object = Default::default(); + let mut download_mode = false; + let mut call = self.hub.objects().update(&request, &self.opt.arg_bucket, &self.opt.arg_object); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "predefined-acl" => { + call = call.predefined_acl(value.unwrap_or("")); + }, + "if-metageneration-not-match" => { + call = call.if_metageneration_not_match(value.unwrap_or("")); + }, + "if-metageneration-match" => { + call = call.if_metageneration_match(value.unwrap_or("")); + }, + "if-generation-not-match" => { + call = call.if_generation_not_match(value.unwrap_or("")); + }, + "if-generation-match" => { + call = call.if_generation_match(value.unwrap_or("")); + }, + "generation" => { + call = call.generation(value.unwrap_or("")); + }, + "encryption-key-hash" => { + call = call.encryption_key_hash(value.unwrap_or("")); + }, + "encryption-key" => { + call = call.encryption_key(value.unwrap_or("")); + }, + "encryption-algorithm" => { + call = call.encryption_algorithm(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_owner_init(request: &mut api::Object) { + if request.owner.is_none() { + request.owner = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + "generation" => { + request.generation = Some(value.unwrap_or("").to_string()); + }, + "component-count" => { + request.component_count = Some(arg_from_str(value.unwrap_or("-0"), err, "component-count", "integer")); + }, + "media-link" => { + request.media_link = Some(value.unwrap_or("").to_string()); + }, + "owner.entity-id" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity_id = value.unwrap_or("").to_string(); + }, + "owner.entity" => { + request_owner_init(&mut request); + request.owner.as_mut().unwrap().entity = value.unwrap_or("").to_string(); + }, + "cache-control" => { + request_owner_init(&mut request); + request.cache_control = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_owner_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + "size" => { + request_owner_init(&mut request); + request.size = Some(value.unwrap_or("").to_string()); + }, + "time-deleted" => { + request_owner_init(&mut request); + request.time_deleted = Some(value.unwrap_or("").to_string()); + }, + "md5-hash" => { + request_owner_init(&mut request); + request.md5_hash = Some(value.unwrap_or("").to_string()); + }, + "crc32c" => { + request_owner_init(&mut request); + request.crc32c = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_owner_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "metadata" => { + request_owner_init(&mut request); + if request.metadata.is_none() { + request.metadata = Some(Default::default()); + } + request.metadata.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "updated" => { + request_owner_init(&mut request); + request.updated = Some(value.unwrap_or("").to_string()); + }, + "content-type" => { + request_owner_init(&mut request); + request.content_type = Some(value.unwrap_or("").to_string()); + }, + "content-language" => { + request_owner_init(&mut request); + request.content_language = Some(value.unwrap_or("").to_string()); + }, + "metageneration" => { + request_owner_init(&mut request); + request.metageneration = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request_owner_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_owner_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "bucket" => { + request_owner_init(&mut request); + request.bucket = Some(value.unwrap_or("").to_string()); + }, + "content-encoding" => { + request_owner_init(&mut request); + request.content_encoding = Some(value.unwrap_or("").to_string()); + }, + "storage-class" => { + request_owner_init(&mut request); + request.storage_class = Some(value.unwrap_or("").to_string()); + }, + "content-disposition" => { + request_owner_init(&mut request); + request.content_disposition = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _objects_watch_all(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.objects().watch_all(&request, &self.opt.arg_bucket); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "versions" => { + call = call.versions(arg_from_str(value.unwrap_or("false"), err, "versions", "boolean")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "prefix" => { + call = call.prefix(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "delimiter" => { + call = call.delimiter(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "resource-uri" => { + request.resource_uri = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "resource-id" => { + request.resource_id = Some(value.unwrap_or("").to_string()); + }, + "payload" => { + request.payload = Some(arg_from_str(value.unwrap_or("false"), err, "payload", "boolean")); + }, + "token" => { + request.token = Some(value.unwrap_or("").to_string()); + }, + "params" => { + if request.params.is_none() { + request.params = Some(Default::default()); + } + request.params.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "expiration" => { + request.expiration = Some(value.unwrap_or("").to_string()); + }, + "address" => { + request.address = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_bucket_access_controls { + if self.opt.cmd_delete { + call_result = self._bucket_access_controls_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._bucket_access_controls_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._bucket_access_controls_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._bucket_access_controls_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._bucket_access_controls_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._bucket_access_controls_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_buckets { + if self.opt.cmd_delete { + call_result = self._buckets_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._buckets_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._buckets_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._buckets_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._buckets_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._buckets_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_stop { + call_result = self._channels_stop(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_default_object_access_controls { + if self.opt.cmd_delete { + call_result = self._default_object_access_controls_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._default_object_access_controls_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._default_object_access_controls_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._default_object_access_controls_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._default_object_access_controls_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._default_object_access_controls_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_object_access_controls { + if self.opt.cmd_delete { + call_result = self._object_access_controls_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._object_access_controls_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._object_access_controls_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._object_access_controls_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._object_access_controls_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._object_access_controls_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_objects { + if self.opt.cmd_compose { + call_result = self._objects_compose(dry_run, &mut err); + } else if self.opt.cmd_copy { + call_result = self._objects_copy(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._objects_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._objects_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._objects_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._objects_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._objects_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._objects_update(dry_run, &mut err); + } else if self.opt.cmd_watch_all { + call_result = self._objects_watch_all(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "storage1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "storage1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Storage::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/tagmanager1-cli/Cargo.toml b/gen/tagmanager1-cli/Cargo.toml new file mode 100644 index 00000000000..210963f027c --- /dev/null +++ b/gen/tagmanager1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-tagmanager1-cli" +version = "0.0.1+20150121" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with Tag Manager (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/tagmanager1-cli" +homepage = "https://developers.google.com/tag-manager/api/v1/" +documentation = "http://byron.github.io/google-apis-rs/google_tagmanager1_cli" +license = "MIT" +keywords = ["tagmanager", "google", "cli"] + +[[bin]] +name = "tagmanager1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-tagmanager1] +path = "../tagmanager1" diff --git a/gen/tagmanager1-cli/LICENSE.md b/gen/tagmanager1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/tagmanager1-cli/LICENSE.md @@ -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. diff --git a/gen/tagmanager1-cli/README.md b/gen/tagmanager1-cli/README.md new file mode 100644 index 00000000000..1fcc018979b --- /dev/null +++ b/gen/tagmanager1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TAGMANAGER:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/tagmanager1-cli/mkdocs.yml b/gen/tagmanager1-cli/mkdocs.yml new file mode 100644 index 00000000000..5344c3a6d53 --- /dev/null +++ b/gen/tagmanager1-cli/mkdocs.yml @@ -0,0 +1,62 @@ +site_name: Tag Manager v0.0.1+20150121 +site_url: http://byron.github.io/google-apis-rs/google-tagmanager1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/tagmanager1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['accounts_containers-create.md', 'Accounts', 'Containers Create'] +- ['accounts_containers-delete.md', 'Accounts', 'Containers Delete'] +- ['accounts_containers-get.md', 'Accounts', 'Containers Get'] +- ['accounts_containers-list.md', 'Accounts', 'Containers List'] +- ['accounts_containers-macros-create.md', 'Accounts', 'Containers Macros Create'] +- ['accounts_containers-macros-delete.md', 'Accounts', 'Containers Macros Delete'] +- ['accounts_containers-macros-get.md', 'Accounts', 'Containers Macros Get'] +- ['accounts_containers-macros-list.md', 'Accounts', 'Containers Macros List'] +- ['accounts_containers-macros-update.md', 'Accounts', 'Containers Macros Update'] +- ['accounts_containers-rules-create.md', 'Accounts', 'Containers Rules Create'] +- ['accounts_containers-rules-delete.md', 'Accounts', 'Containers Rules Delete'] +- ['accounts_containers-rules-get.md', 'Accounts', 'Containers Rules Get'] +- ['accounts_containers-rules-list.md', 'Accounts', 'Containers Rules List'] +- ['accounts_containers-rules-update.md', 'Accounts', 'Containers Rules Update'] +- ['accounts_containers-tags-create.md', 'Accounts', 'Containers Tags Create'] +- ['accounts_containers-tags-delete.md', 'Accounts', 'Containers Tags Delete'] +- ['accounts_containers-tags-get.md', 'Accounts', 'Containers Tags Get'] +- ['accounts_containers-tags-list.md', 'Accounts', 'Containers Tags List'] +- ['accounts_containers-tags-update.md', 'Accounts', 'Containers Tags Update'] +- ['accounts_containers-triggers-create.md', 'Accounts', 'Containers Triggers Create'] +- ['accounts_containers-triggers-delete.md', 'Accounts', 'Containers Triggers Delete'] +- ['accounts_containers-triggers-get.md', 'Accounts', 'Containers Triggers Get'] +- ['accounts_containers-triggers-list.md', 'Accounts', 'Containers Triggers List'] +- ['accounts_containers-triggers-update.md', 'Accounts', 'Containers Triggers Update'] +- ['accounts_containers-update.md', 'Accounts', 'Containers Update'] +- ['accounts_containers-variables-create.md', 'Accounts', 'Containers Variables Create'] +- ['accounts_containers-variables-delete.md', 'Accounts', 'Containers Variables Delete'] +- ['accounts_containers-variables-get.md', 'Accounts', 'Containers Variables Get'] +- ['accounts_containers-variables-list.md', 'Accounts', 'Containers Variables List'] +- ['accounts_containers-variables-update.md', 'Accounts', 'Containers Variables Update'] +- ['accounts_containers-versions-create.md', 'Accounts', 'Containers Versions Create'] +- ['accounts_containers-versions-delete.md', 'Accounts', 'Containers Versions Delete'] +- ['accounts_containers-versions-get.md', 'Accounts', 'Containers Versions Get'] +- ['accounts_containers-versions-list.md', 'Accounts', 'Containers Versions List'] +- ['accounts_containers-versions-publish.md', 'Accounts', 'Containers Versions Publish'] +- ['accounts_containers-versions-restore.md', 'Accounts', 'Containers Versions Restore'] +- ['accounts_containers-versions-undelete.md', 'Accounts', 'Containers Versions Undelete'] +- ['accounts_containers-versions-update.md', 'Accounts', 'Containers Versions Update'] +- ['accounts_get.md', 'Accounts', 'Get'] +- ['accounts_list.md', 'Accounts', 'List'] +- ['accounts_permissions-create.md', 'Accounts', 'Permissions Create'] +- ['accounts_permissions-delete.md', 'Accounts', 'Permissions Delete'] +- ['accounts_permissions-get.md', 'Accounts', 'Permissions Get'] +- ['accounts_permissions-list.md', 'Accounts', 'Permissions List'] +- ['accounts_permissions-update.md', 'Accounts', 'Permissions Update'] +- ['accounts_update.md', 'Accounts', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/tagmanager1-cli/src/cmn.rs b/gen/tagmanager1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/tagmanager1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/tagmanager1-cli/src/main.rs b/gen/tagmanager1-cli/src/main.rs new file mode 100644 index 00000000000..41fb94ee6eb --- /dev/null +++ b/gen/tagmanager1-cli/src/main.rs @@ -0,0 +1,3483 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_tagmanager1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + tagmanager1 [options] accounts containers-create <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-delete <account-id> <container-id> [-p <v>]... + tagmanager1 [options] accounts containers-get <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-list <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-delete <account-id> <container-id> <macro-id> [-p <v>]... + tagmanager1 [options] accounts containers-macros-get <account-id> <container-id> <macro-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-macros-update <account-id> <container-id> <macro-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-delete <account-id> <container-id> <rule-id> [-p <v>]... + tagmanager1 [options] accounts containers-rules-get <account-id> <container-id> <rule-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-rules-update <account-id> <container-id> <rule-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-delete <account-id> <container-id> <tag-id> [-p <v>]... + tagmanager1 [options] accounts containers-tags-get <account-id> <container-id> <tag-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-tags-update <account-id> <container-id> <tag-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-delete <account-id> <container-id> <trigger-id> [-p <v>]... + tagmanager1 [options] accounts containers-triggers-get <account-id> <container-id> <trigger-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-triggers-update <account-id> <container-id> <trigger-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-update <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-delete <account-id> <container-id> <variable-id> [-p <v>]... + tagmanager1 [options] accounts containers-variables-get <account-id> <container-id> <variable-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-variables-update <account-id> <container-id> <variable-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-create <account-id> <container-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-delete <account-id> <container-id> <container-version-id> [-p <v>]... + tagmanager1 [options] accounts containers-versions-get <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-list <account-id> <container-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-publish <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-restore <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-undelete <account-id> <container-id> <container-version-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts containers-versions-update <account-id> <container-id> <container-version-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts get <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts list [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-create <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-delete <account-id> <permission-id> [-p <v>]... + tagmanager1 [options] accounts permissions-get <account-id> <permission-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-list <account-id> [-p <v>]... [-o <out>] + tagmanager1 [options] accounts permissions-update <account-id> <permission-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 [options] accounts update <account-id> -r <kv>... [-p <v>]... [-o <out>] + tagmanager1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::TagManager<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _accounts_containers_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Container = Default::default(); + let mut call = self.hub.accounts().containers_create(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time-zone-id" => { + request.time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "enabled-built-in-variable" => { + if request.enabled_built_in_variable.is_none() { + request.enabled_built_in_variable = Some(Default::default()); + } + request.enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "time-zone-country-id" => { + request.time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "time-zone-country-id", "int64")); + }, + "public-id" => { + request.public_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "domain-name" => { + if request.domain_name.is_none() { + request.domain_name = Some(Default::default()); + } + request.domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "usage-context" => { + if request.usage_context.is_none() { + request.usage_context = Some(Default::default()); + } + request.usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_delete(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_get(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Macro = Default::default(); + let mut call = self.hub.accounts().containers_macros_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "macro-id" => { + request.macro_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-rule-id" => { + if request.enabling_rule_id.is_none() { + request.enabling_rule_id = Some(Default::default()); + } + request.enabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "disabling-rule-id" => { + if request.disabling_rule_id.is_none() { + request.disabling_rule_id = Some(Default::default()); + } + request.disabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_macros_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_macros_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_macros_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Macro = Default::default(); + let mut call = self.hub.accounts().containers_macros_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_macro_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "macro-id" => { + request.macro_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-rule-id" => { + if request.enabling_rule_id.is_none() { + request.enabling_rule_id = Some(Default::default()); + } + request.enabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "disabling-rule-id" => { + if request.disabling_rule_id.is_none() { + request.disabling_rule_id = Some(Default::default()); + } + request.disabling_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Rule = Default::default(); + let mut call = self.hub.accounts().containers_rules_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "rule-id" => { + request.rule_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_rules_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_rules_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_rules_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Rule = Default::default(); + let mut call = self.hub.accounts().containers_rules_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_rule_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "rule-id" => { + request.rule_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Tag = Default::default(); + let mut call = self.hub.accounts().containers_tags_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_priority_init(request: &mut api::Tag) { + if request.priority.is_none() { + request.priority = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "blocking-trigger-id" => { + if request.blocking_trigger_id.is_none() { + request.blocking_trigger_id = Some(Default::default()); + } + request.blocking_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tag-id" => { + request.tag_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "priority.type" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "priority.value" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "priority.key" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "blocking-rule-id" => { + request_priority_init(&mut request); + if request.blocking_rule_id.is_none() { + request.blocking_rule_id = Some(Default::default()); + } + request.blocking_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "live-only" => { + request_priority_init(&mut request); + request.live_only = Some(arg_from_str(value.unwrap_or("false"), err, "live-only", "boolean")); + }, + "fingerprint" => { + request_priority_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "firing-rule-id" => { + request_priority_init(&mut request); + if request.firing_rule_id.is_none() { + request.firing_rule_id = Some(Default::default()); + } + request.firing_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "firing-trigger-id" => { + request_priority_init(&mut request); + if request.firing_trigger_id.is_none() { + request.firing_trigger_id = Some(Default::default()); + } + request.firing_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request_priority_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_priority_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_priority_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_tags_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_tags_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_tags_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Tag = Default::default(); + let mut call = self.hub.accounts().containers_tags_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_tag_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_priority_init(request: &mut api::Tag) { + if request.priority.is_none() { + request.priority = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "blocking-trigger-id" => { + if request.blocking_trigger_id.is_none() { + request.blocking_trigger_id = Some(Default::default()); + } + request.blocking_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "tag-id" => { + request.tag_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "priority.type" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "priority.value" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "priority.key" => { + request_priority_init(&mut request); + request.priority.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "blocking-rule-id" => { + request_priority_init(&mut request); + if request.blocking_rule_id.is_none() { + request.blocking_rule_id = Some(Default::default()); + } + request.blocking_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "live-only" => { + request_priority_init(&mut request); + request.live_only = Some(arg_from_str(value.unwrap_or("false"), err, "live-only", "boolean")); + }, + "fingerprint" => { + request_priority_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "firing-rule-id" => { + request_priority_init(&mut request); + if request.firing_rule_id.is_none() { + request.firing_rule_id = Some(Default::default()); + } + request.firing_rule_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "firing-trigger-id" => { + request_priority_init(&mut request); + if request.firing_trigger_id.is_none() { + request.firing_trigger_id = Some(Default::default()); + } + request.firing_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "type" => { + request_priority_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request_priority_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_priority_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Trigger = Default::default(); + let mut call = self.hub.accounts().containers_triggers_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_check_validation_init(request: &mut api::Trigger) { + if request.check_validation.is_none() { + request.check_validation = Some(Default::default()); + } + } + + fn request_enable_all_videos_init(request: &mut api::Trigger) { + if request.enable_all_videos.is_none() { + request.enable_all_videos = Some(Default::default()); + } + } + + fn request_event_name_init(request: &mut api::Trigger) { + if request.event_name.is_none() { + request.event_name = Some(Default::default()); + } + } + + fn request_interval_init(request: &mut api::Trigger) { + if request.interval.is_none() { + request.interval = Some(Default::default()); + } + } + + fn request_limit_init(request: &mut api::Trigger) { + if request.limit.is_none() { + request.limit = Some(Default::default()); + } + } + + fn request_unique_trigger_id_init(request: &mut api::Trigger) { + if request.unique_trigger_id.is_none() { + request.unique_trigger_id = Some(Default::default()); + } + } + + fn request_video_percentage_list_init(request: &mut api::Trigger) { + if request.video_percentage_list.is_none() { + request.video_percentage_list = Some(Default::default()); + } + } + + fn request_wait_for_tags_init(request: &mut api::Trigger) { + if request.wait_for_tags.is_none() { + request.wait_for_tags = Some(Default::default()); + } + } + + fn request_wait_for_tags_timeout_init(request: &mut api::Trigger) { + if request.wait_for_tags_timeout.is_none() { + request.wait_for_tags_timeout = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "video-percentage-list.type" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "video-percentage-list.value" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "video-percentage-list.key" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "interval.type" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "interval.value" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "interval.key" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "wait-for-tags.type" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "wait-for-tags.value" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "wait-for-tags.key" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "container-id" => { + request_wait_for_tags_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.type" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "unique-trigger-id.value" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "unique-trigger-id.key" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.type" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.value" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.key" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "name" => { + request_wait_for_tags_timeout_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "event-name.type" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "event-name.value" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "event-name.key" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "trigger-id" => { + request_event_name_init(&mut request); + request.trigger_id = Some(value.unwrap_or("").to_string()); + }, + "limit.type" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "limit.value" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "limit.key" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "check-validation.type" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "check-validation.value" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "check-validation.key" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "fingerprint" => { + request_check_validation_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_check_validation_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.type" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "enable-all-videos.value" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "enable-all-videos.key" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "account-id" => { + request_enable_all_videos_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_triggers_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_triggers_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_triggers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Trigger = Default::default(); + let mut call = self.hub.accounts().containers_triggers_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_trigger_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_check_validation_init(request: &mut api::Trigger) { + if request.check_validation.is_none() { + request.check_validation = Some(Default::default()); + } + } + + fn request_enable_all_videos_init(request: &mut api::Trigger) { + if request.enable_all_videos.is_none() { + request.enable_all_videos = Some(Default::default()); + } + } + + fn request_event_name_init(request: &mut api::Trigger) { + if request.event_name.is_none() { + request.event_name = Some(Default::default()); + } + } + + fn request_interval_init(request: &mut api::Trigger) { + if request.interval.is_none() { + request.interval = Some(Default::default()); + } + } + + fn request_limit_init(request: &mut api::Trigger) { + if request.limit.is_none() { + request.limit = Some(Default::default()); + } + } + + fn request_unique_trigger_id_init(request: &mut api::Trigger) { + if request.unique_trigger_id.is_none() { + request.unique_trigger_id = Some(Default::default()); + } + } + + fn request_video_percentage_list_init(request: &mut api::Trigger) { + if request.video_percentage_list.is_none() { + request.video_percentage_list = Some(Default::default()); + } + } + + fn request_wait_for_tags_init(request: &mut api::Trigger) { + if request.wait_for_tags.is_none() { + request.wait_for_tags = Some(Default::default()); + } + } + + fn request_wait_for_tags_timeout_init(request: &mut api::Trigger) { + if request.wait_for_tags_timeout.is_none() { + request.wait_for_tags_timeout = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "video-percentage-list.type" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "video-percentage-list.value" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "video-percentage-list.key" => { + request_video_percentage_list_init(&mut request); + request.video_percentage_list.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "interval.type" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "interval.value" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "interval.key" => { + request_interval_init(&mut request); + request.interval.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "wait-for-tags.type" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "wait-for-tags.value" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "wait-for-tags.key" => { + request_wait_for_tags_init(&mut request); + request.wait_for_tags.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "container-id" => { + request_wait_for_tags_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "unique-trigger-id.type" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "unique-trigger-id.value" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "unique-trigger-id.key" => { + request_unique_trigger_id_init(&mut request); + request.unique_trigger_id.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.type" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.value" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "wait-for-tags-timeout.key" => { + request_wait_for_tags_timeout_init(&mut request); + request.wait_for_tags_timeout.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "name" => { + request_wait_for_tags_timeout_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "event-name.type" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "event-name.value" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "event-name.key" => { + request_event_name_init(&mut request); + request.event_name.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "trigger-id" => { + request_event_name_init(&mut request); + request.trigger_id = Some(value.unwrap_or("").to_string()); + }, + "limit.type" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "limit.value" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "limit.key" => { + request_limit_init(&mut request); + request.limit.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "check-validation.type" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "check-validation.value" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "check-validation.key" => { + request_check_validation_init(&mut request); + request.check_validation.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "fingerprint" => { + request_check_validation_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request_check_validation_init(&mut request); + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "enable-all-videos.type" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "enable-all-videos.value" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().value = value.unwrap_or("").to_string(); + }, + "enable-all-videos.key" => { + request_enable_all_videos_init(&mut request); + request.enable_all_videos.as_mut().unwrap().key = value.unwrap_or("").to_string(); + }, + "account-id" => { + request_enable_all_videos_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Container = Default::default(); + let mut call = self.hub.accounts().containers_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "time-zone-id" => { + request.time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "enabled-built-in-variable" => { + if request.enabled_built_in_variable.is_none() { + request.enabled_built_in_variable = Some(Default::default()); + } + request.enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "time-zone-country-id" => { + request.time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "time-zone-country-id", "int64")); + }, + "public-id" => { + request.public_id = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "domain-name" => { + if request.domain_name.is_none() { + request.domain_name = Some(Default::default()); + } + request.domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "usage-context" => { + if request.usage_context.is_none() { + request.usage_context = Some(Default::default()); + } + request.usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Variable = Default::default(); + let mut call = self.hub.accounts().containers_variables_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "variable-id" => { + request.variable_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-trigger-id" => { + if request.enabling_trigger_id.is_none() { + request.enabling_trigger_id = Some(Default::default()); + } + request.enabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "disabling-trigger-id" => { + if request.disabling_trigger_id.is_none() { + request.disabling_trigger_id = Some(Default::default()); + } + request.disabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_variables_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_variables_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_variables_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Variable = Default::default(); + let mut call = self.hub.accounts().containers_variables_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_variable_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "schedule-start-ms" => { + request.schedule_start_ms = Some(value.unwrap_or("").to_string()); + }, + "schedule-end-ms" => { + request.schedule_end_ms = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "variable-id" => { + request.variable_id = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "enabling-trigger-id" => { + if request.enabling_trigger_id.is_none() { + request.enabling_trigger_id = Some(Default::default()); + } + request.enabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + "type" => { + request.type_ = Some(value.unwrap_or("").to_string()); + }, + "disabling-trigger-id" => { + if request.disabling_trigger_id.is_none() { + request.disabling_trigger_id = Some(Default::default()); + } + request.disabling_trigger_id.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container-id" => { + request.container_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::CreateContainerVersionRequestVersionOptions = Default::default(); + let mut call = self.hub.accounts().containers_versions_create(&request, &self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "quick-preview" => { + request.quick_preview = Some(arg_from_str(value.unwrap_or("false"), err, "quick-preview", "boolean")); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_delete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_containers_versions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_get(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_list(&self.opt.arg_account_id, &self.opt.arg_container_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "headers" => { + call = call.headers(arg_from_str(value.unwrap_or("false"), err, "headers", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_publish(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_publish(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_restore(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_restore(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_undelete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().containers_versions_undelete(&self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_containers_versions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ContainerVersion = Default::default(); + let mut call = self.hub.accounts().containers_versions_update(&request, &self.opt.arg_account_id, &self.opt.arg_container_id, &self.opt.arg_container_version_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_container_init(request: &mut api::ContainerVersion) { + if request.container.is_none() { + request.container = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "container.time-zone-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().time_zone_id = Some(value.unwrap_or("").to_string()); + }, + "container.enabled-built-in-variable" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().enabled_built_in_variable.is_none() { + request.container.as_mut().unwrap().enabled_built_in_variable = Some(Default::default()); + } + request.container.as_mut().unwrap().enabled_built_in_variable.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.time-zone-country-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().time_zone_country_id = Some(arg_from_str(value.unwrap_or("-0"), err, "container.time-zone-country-id", "int64")); + }, + "container.public-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().public_id = Some(value.unwrap_or("").to_string()); + }, + "container.container-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().container_id = Some(value.unwrap_or("").to_string()); + }, + "container.domain-name" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().domain_name.is_none() { + request.container.as_mut().unwrap().domain_name = Some(Default::default()); + } + request.container.as_mut().unwrap().domain_name.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.notes" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().notes = Some(value.unwrap_or("").to_string()); + }, + "container.usage-context" => { + request_container_init(&mut request); + if request.container.as_mut().unwrap().usage_context.is_none() { + request.container.as_mut().unwrap().usage_context = Some(Default::default()); + } + request.container.as_mut().unwrap().usage_context.as_mut().unwrap().push(value.unwrap_or("").to_string()); + }, + "container.fingerprint" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().fingerprint = Some(value.unwrap_or("").to_string()); + }, + "container.account-id" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().account_id = Some(value.unwrap_or("").to_string()); + }, + "container.name" => { + request_container_init(&mut request); + request.container.as_mut().unwrap().name = Some(value.unwrap_or("").to_string()); + }, + "container-id" => { + request_container_init(&mut request); + request.container_id = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request_container_init(&mut request); + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "notes" => { + request_container_init(&mut request); + request.notes = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request_container_init(&mut request); + request.name = Some(value.unwrap_or("").to_string()); + }, + "container-version-id" => { + request_container_init(&mut request); + request.container_version_id = Some(value.unwrap_or("").to_string()); + }, + "fingerprint" => { + request_container_init(&mut request); + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_container_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().get(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_create(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UserAccess = Default::default(); + let mut call = self.hub.accounts().permissions_create(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_account_access_init(request: &mut api::UserAccess) { + if request.account_access.is_none() { + request.account_access = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "account-access.permission" => { + request_account_access_init(&mut request); + request.account_access.as_mut().unwrap().permission.push(value.unwrap_or("").to_string()); + }, + "email-address" => { + request_account_access_init(&mut request); + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "permission-id" => { + request_account_access_init(&mut request); + request.permission_id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_account_access_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_delete(&self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _accounts_permissions_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_get(&self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.accounts().permissions_list(&self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_permissions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::UserAccess = Default::default(); + let mut call = self.hub.accounts().permissions_update(&request, &self.opt.arg_account_id, &self.opt.arg_permission_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_account_access_init(request: &mut api::UserAccess) { + if request.account_access.is_none() { + request.account_access = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "account-access.permission" => { + request_account_access_init(&mut request); + request.account_access.as_mut().unwrap().permission.push(value.unwrap_or("").to_string()); + }, + "email-address" => { + request_account_access_init(&mut request); + request.email_address = Some(value.unwrap_or("").to_string()); + }, + "permission-id" => { + request_account_access_init(&mut request); + request.permission_id = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request_account_access_init(&mut request); + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _accounts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Account = Default::default(); + let mut call = self.hub.accounts().update(&request, &self.opt.arg_account_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "fingerprint" => { + call = call.fingerprint(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "share-data" => { + request.share_data = Some(arg_from_str(value.unwrap_or("false"), err, "share-data", "boolean")); + }, + "fingerprint" => { + request.fingerprint = Some(value.unwrap_or("").to_string()); + }, + "name" => { + request.name = Some(value.unwrap_or("").to_string()); + }, + "account-id" => { + request.account_id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_accounts { + if self.opt.cmd_containers_create { + call_result = self._accounts_containers_create(dry_run, &mut err); + } else if self.opt.cmd_containers_delete { + call_result = self._accounts_containers_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_get { + call_result = self._accounts_containers_get(dry_run, &mut err); + } else if self.opt.cmd_containers_list { + call_result = self._accounts_containers_list(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_create { + call_result = self._accounts_containers_macros_create(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_delete { + call_result = self._accounts_containers_macros_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_get { + call_result = self._accounts_containers_macros_get(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_list { + call_result = self._accounts_containers_macros_list(dry_run, &mut err); + } else if self.opt.cmd_containers_macros_update { + call_result = self._accounts_containers_macros_update(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_create { + call_result = self._accounts_containers_rules_create(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_delete { + call_result = self._accounts_containers_rules_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_get { + call_result = self._accounts_containers_rules_get(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_list { + call_result = self._accounts_containers_rules_list(dry_run, &mut err); + } else if self.opt.cmd_containers_rules_update { + call_result = self._accounts_containers_rules_update(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_create { + call_result = self._accounts_containers_tags_create(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_delete { + call_result = self._accounts_containers_tags_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_get { + call_result = self._accounts_containers_tags_get(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_list { + call_result = self._accounts_containers_tags_list(dry_run, &mut err); + } else if self.opt.cmd_containers_tags_update { + call_result = self._accounts_containers_tags_update(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_create { + call_result = self._accounts_containers_triggers_create(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_delete { + call_result = self._accounts_containers_triggers_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_get { + call_result = self._accounts_containers_triggers_get(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_list { + call_result = self._accounts_containers_triggers_list(dry_run, &mut err); + } else if self.opt.cmd_containers_triggers_update { + call_result = self._accounts_containers_triggers_update(dry_run, &mut err); + } else if self.opt.cmd_containers_update { + call_result = self._accounts_containers_update(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_create { + call_result = self._accounts_containers_variables_create(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_delete { + call_result = self._accounts_containers_variables_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_get { + call_result = self._accounts_containers_variables_get(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_list { + call_result = self._accounts_containers_variables_list(dry_run, &mut err); + } else if self.opt.cmd_containers_variables_update { + call_result = self._accounts_containers_variables_update(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_create { + call_result = self._accounts_containers_versions_create(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_delete { + call_result = self._accounts_containers_versions_delete(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_get { + call_result = self._accounts_containers_versions_get(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_list { + call_result = self._accounts_containers_versions_list(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_publish { + call_result = self._accounts_containers_versions_publish(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_restore { + call_result = self._accounts_containers_versions_restore(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_undelete { + call_result = self._accounts_containers_versions_undelete(dry_run, &mut err); + } else if self.opt.cmd_containers_versions_update { + call_result = self._accounts_containers_versions_update(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._accounts_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._accounts_list(dry_run, &mut err); + } else if self.opt.cmd_permissions_create { + call_result = self._accounts_permissions_create(dry_run, &mut err); + } else if self.opt.cmd_permissions_delete { + call_result = self._accounts_permissions_delete(dry_run, &mut err); + } else if self.opt.cmd_permissions_get { + call_result = self._accounts_permissions_get(dry_run, &mut err); + } else if self.opt.cmd_permissions_list { + call_result = self._accounts_permissions_list(dry_run, &mut err); + } else if self.opt.cmd_permissions_update { + call_result = self._accounts_permissions_update(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._accounts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "tagmanager1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "tagmanager1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::TagManager::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/tagmanager1/src/cmn.rs b/gen/tagmanager1/src/cmn.rs index 438fd04c898..5d9b5ebbf80 100644 --- a/gen/tagmanager1/src/cmn.rs +++ b/gen/tagmanager1/src/cmn.rs @@ -4,6 +4,7 @@ use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; use std; use std::fmt::{self, Display}; use std::str::FromStr; +use std::error; use std::thread::sleep_ms; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; @@ -217,7 +218,7 @@ pub struct DefaultDelegate; impl Delegate for DefaultDelegate {} - +#[derive(Debug)] pub enum Error { /// The http connection failed HttpError(hyper::HttpError), @@ -247,6 +248,49 @@ pub enum Error { Failure(hyper::client::Response), } + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::HttpError(ref err) => err.fmt(f), + Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => + writeln!(f, "The media size {} exceeds the maximum allowed upload size of {}" + , resource_size, max_size), + Error::MissingAPIKey => { + writeln!(f, "The application's API key was not found in the configuration").ok(); + writeln!(f, "It is used as there are no Scopes defined for this method.") + }, + Error::MissingToken => + writeln!(f, "Didn't obtain authentication token from authenticator"), + Error::Cancelled => + writeln!(f, "Operation cancelled by delegate"), + Error::FieldClash(field) => + writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field), + Error::JsonDecodeError(ref err) => err.fmt(f), + Error::Failure(ref response) => + writeln!(f, "Http status indicates failure: {:?}", response), + } + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + match *self { + Error::HttpError(ref err) => err.description(), + Error::JsonDecodeError(ref err) => err.description(), + _ => "NO DESCRIPTION POSSIBLE - use `Display.fmt()` instead" + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + Error::HttpError(ref err) => err.cause(), + Error::JsonDecodeError(ref err) => err.cause(), + _ => None + } + } +} + /// A universal result type used as return for all calls. pub type Result<T> = std::result::Result<T, Error>; diff --git a/gen/taskqueue1_beta2-cli/Cargo.toml b/gen/taskqueue1_beta2-cli/Cargo.toml new file mode 100644 index 00000000000..6e5b17090e1 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-taskqueue1_beta2-cli" +version = "0.0.1+20141111" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with taskqueue (protocol v1beta2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/taskqueue1_beta2-cli" +homepage = "https://developers.google.com/appengine/docs/python/taskqueue/rest" +documentation = "http://byron.github.io/google-apis-rs/google_taskqueue1_beta2_cli" +license = "MIT" +keywords = ["taskqueue", "google", "cli"] + +[[bin]] +name = "taskqueue1-beta2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-taskqueue1_beta2] +path = "../taskqueue1_beta2" diff --git a/gen/taskqueue1_beta2-cli/LICENSE.md b/gen/taskqueue1_beta2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/taskqueue1_beta2-cli/LICENSE.md @@ -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. diff --git a/gen/taskqueue1_beta2-cli/README.md b/gen/taskqueue1_beta2-cli/README.md new file mode 100644 index 00000000000..7baaf70b4b9 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TASKQUEUE:V1BETA2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/taskqueue1_beta2-cli/mkdocs.yml b/gen/taskqueue1_beta2-cli/mkdocs.yml new file mode 100644 index 00000000000..88e631eedbb --- /dev/null +++ b/gen/taskqueue1_beta2-cli/mkdocs.yml @@ -0,0 +1,24 @@ +site_name: taskqueue v0.0.1+20141111 +site_url: http://byron.github.io/google-apis-rs/google-taskqueue1_beta2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/taskqueue1_beta2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['taskqueues_get.md', 'Taskqueues', 'Get'] +- ['tasks_delete.md', 'Tasks', 'Delete'] +- ['tasks_get.md', 'Tasks', 'Get'] +- ['tasks_insert.md', 'Tasks', 'Insert'] +- ['tasks_lease.md', 'Tasks', 'Lease'] +- ['tasks_list.md', 'Tasks', 'List'] +- ['tasks_patch.md', 'Tasks', 'Patch'] +- ['tasks_update.md', 'Tasks', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/taskqueue1_beta2-cli/src/cmn.rs b/gen/taskqueue1_beta2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/taskqueue1_beta2-cli/src/main.rs b/gen/taskqueue1_beta2-cli/src/main.rs new file mode 100644 index 00000000000..d60733d4211 --- /dev/null +++ b/gen/taskqueue1_beta2-cli/src/main.rs @@ -0,0 +1,628 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_taskqueue1_beta2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + taskqueue1-beta2 [options] taskqueues get <project> <taskqueue> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks delete <project> <taskqueue> <task> [-p <v>]... + taskqueue1-beta2 [options] tasks get <project> <taskqueue> <task> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks insert <project> <taskqueue> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks lease <project> <taskqueue> <num-tasks> <lease-secs> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks list <project> <taskqueue> [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks patch <project> <taskqueue> <task> <new-lease-seconds> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 [options] tasks update <project> <taskqueue> <task> <new-lease-seconds> -r <kv>... [-p <v>]... [-o <out>] + taskqueue1-beta2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Taskqueue<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _taskqueues_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.taskqueues().get(&self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "get-stats" => { + call = call.get_stats(arg_from_str(value.unwrap_or("false"), err, "get-stats", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().delete(&self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tasks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().get(&self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let mut call = self.hub.tasks().insert(&request, &self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_lease(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let num_tasks: i32 = arg_from_str(&self.opt.arg_num_tasks, err, "<num-tasks>", "integer"); + let lease_secs: i32 = arg_from_str(&self.opt.arg_lease_secs, err, "<lease-secs>", "integer"); + let mut call = self.hub.tasks().lease(&self.opt.arg_project, &self.opt.arg_taskqueue, num_tasks, lease_secs); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tag" => { + call = call.tag(value.unwrap_or("")); + }, + "group-by-tag" => { + call = call.group_by_tag(arg_from_str(value.unwrap_or("false"), err, "group-by-tag", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().list(&self.opt.arg_project, &self.opt.arg_taskqueue); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let new_lease_seconds: i32 = arg_from_str(&self.opt.arg_new_lease_seconds, err, "<new-lease-seconds>", "integer"); + let mut call = self.hub.tasks().patch(&request, &self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task, new_lease_seconds); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let new_lease_seconds: i32 = arg_from_str(&self.opt.arg_new_lease_seconds, err, "<new-lease-seconds>", "integer"); + let mut call = self.hub.tasks().update(&request, &self.opt.arg_project, &self.opt.arg_taskqueue, &self.opt.arg_task, new_lease_seconds); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "lease-timestamp" => { + request.lease_timestamp = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "retry-count" => { + request.retry_count = Some(arg_from_str(value.unwrap_or("-0"), err, "retry-count", "integer")); + }, + "tag" => { + request.tag = Some(value.unwrap_or("").to_string()); + }, + "payload-base64" => { + request.payload_base64 = Some(value.unwrap_or("").to_string()); + }, + "queue-name" => { + request.queue_name = Some(value.unwrap_or("").to_string()); + }, + "enqueue-timestamp" => { + request.enqueue_timestamp = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_taskqueues { + if self.opt.cmd_get { + call_result = self._taskqueues_get(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tasks { + if self.opt.cmd_delete { + call_result = self._tasks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tasks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._tasks_insert(dry_run, &mut err); + } else if self.opt.cmd_lease { + call_result = self._tasks_lease(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tasks_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tasks_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._tasks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "taskqueue1-beta2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "taskqueue1-beta2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Taskqueue::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/tasks1-cli/Cargo.toml b/gen/tasks1-cli/Cargo.toml new file mode 100644 index 00000000000..d6ac3a5477f --- /dev/null +++ b/gen/tasks1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-tasks1-cli" +version = "0.0.1+20141121" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with tasks (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/tasks1-cli" +homepage = "https://developers.google.com/google-apps/tasks/firstapp" +documentation = "http://byron.github.io/google-apis-rs/google_tasks1_cli" +license = "MIT" +keywords = ["tasks", "google", "cli"] + +[[bin]] +name = "tasks1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-tasks1] +path = "../tasks1" diff --git a/gen/tasks1-cli/LICENSE.md b/gen/tasks1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/tasks1-cli/LICENSE.md @@ -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. diff --git a/gen/tasks1-cli/README.md b/gen/tasks1-cli/README.md new file mode 100644 index 00000000000..52a45e5033c --- /dev/null +++ b/gen/tasks1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TASKS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/tasks1-cli/mkdocs.yml b/gen/tasks1-cli/mkdocs.yml new file mode 100644 index 00000000000..d3f87e7d922 --- /dev/null +++ b/gen/tasks1-cli/mkdocs.yml @@ -0,0 +1,30 @@ +site_name: tasks v0.0.1+20141121 +site_url: http://byron.github.io/google-apis-rs/google-tasks1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/tasks1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['tasklists_delete.md', 'Tasklists', 'Delete'] +- ['tasklists_get.md', 'Tasklists', 'Get'] +- ['tasklists_insert.md', 'Tasklists', 'Insert'] +- ['tasklists_list.md', 'Tasklists', 'List'] +- ['tasklists_patch.md', 'Tasklists', 'Patch'] +- ['tasklists_update.md', 'Tasklists', 'Update'] +- ['tasks_clear.md', 'Tasks', 'Clear'] +- ['tasks_delete.md', 'Tasks', 'Delete'] +- ['tasks_get.md', 'Tasks', 'Get'] +- ['tasks_insert.md', 'Tasks', 'Insert'] +- ['tasks_list.md', 'Tasks', 'List'] +- ['tasks_move.md', 'Tasks', 'Move'] +- ['tasks_patch.md', 'Tasks', 'Patch'] +- ['tasks_update.md', 'Tasks', 'Update'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/tasks1-cli/src/cmn.rs b/gen/tasks1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/tasks1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/tasks1-cli/src/main.rs b/gen/tasks1-cli/src/main.rs new file mode 100644 index 00000000000..65f6d2ab943 --- /dev/null +++ b/gen/tasks1-cli/src/main.rs @@ -0,0 +1,1088 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_tasks1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + tasks1 [options] tasklists delete <tasklist> [-p <v>]... + tasks1 [options] tasklists get <tasklist> [-p <v>]... [-o <out>] + tasks1 [options] tasklists insert -r <kv>... [-p <v>]... [-o <out>] + tasks1 [options] tasklists list [-p <v>]... [-o <out>] + tasks1 [options] tasklists patch <tasklist> -r <kv>... [-p <v>]... [-o <out>] + tasks1 [options] tasklists update <tasklist> -r <kv>... [-p <v>]... [-o <out>] + tasks1 [options] tasks clear <tasklist> [-p <v>]... + tasks1 [options] tasks delete <tasklist> <task> [-p <v>]... + tasks1 [options] tasks get <tasklist> <task> [-p <v>]... [-o <out>] + tasks1 [options] tasks insert <tasklist> -r <kv>... [-p <v>]... [-o <out>] + tasks1 [options] tasks list <tasklist> [-p <v>]... [-o <out>] + tasks1 [options] tasks move <tasklist> <task> [-p <v>]... [-o <out>] + tasks1 [options] tasks patch <tasklist> <task> -r <kv>... [-p <v>]... [-o <out>] + tasks1 [options] tasks update <tasklist> <task> -r <kv>... [-p <v>]... [-o <out>] + tasks1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::TasksHub<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _tasklists_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasklists().delete(&self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tasklists_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasklists().get(&self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasklists_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TaskList = Default::default(); + let mut call = self.hub.tasklists().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasklists_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasklists().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasklists_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TaskList = Default::default(); + let mut call = self.hub.tasklists().patch(&request, &self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasklists_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::TaskList = Default::default(); + let mut call = self.hub.tasklists().update(&request, &self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_clear(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().clear(&self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tasks_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().delete(&self.opt.arg_tasklist, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _tasks_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().get(&self.opt.arg_tasklist, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let mut call = self.hub.tasks().insert(&request, &self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "previous" => { + call = call.previous(value.unwrap_or("")); + }, + "parent" => { + call = call.parent(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent" => { + request.parent = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "completed" => { + request.completed = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "due" => { + request.due = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "position" => { + request.position = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().list(&self.opt.arg_tasklist); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "updated-min" => { + call = call.updated_min(value.unwrap_or("")); + }, + "show-hidden" => { + call = call.show_hidden(arg_from_str(value.unwrap_or("false"), err, "show-hidden", "boolean")); + }, + "show-deleted" => { + call = call.show_deleted(arg_from_str(value.unwrap_or("false"), err, "show-deleted", "boolean")); + }, + "show-completed" => { + call = call.show_completed(arg_from_str(value.unwrap_or("false"), err, "show-completed", "boolean")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(value.unwrap_or("")); + }, + "due-min" => { + call = call.due_min(value.unwrap_or("")); + }, + "due-max" => { + call = call.due_max(value.unwrap_or("")); + }, + "completed-min" => { + call = call.completed_min(value.unwrap_or("")); + }, + "completed-max" => { + call = call.completed_max(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_move(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.tasks().move_(&self.opt.arg_tasklist, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "previous" => { + call = call.previous(value.unwrap_or("")); + }, + "parent" => { + call = call.parent(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_patch(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let mut call = self.hub.tasks().patch(&request, &self.opt.arg_tasklist, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent" => { + request.parent = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "completed" => { + request.completed = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "due" => { + request.due = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "position" => { + request.position = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _tasks_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Task = Default::default(); + let mut call = self.hub.tasks().update(&request, &self.opt.arg_tasklist, &self.opt.arg_task); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "parent" => { + request.parent = Some(value.unwrap_or("").to_string()); + }, + "title" => { + request.title = Some(value.unwrap_or("").to_string()); + }, + "deleted" => { + request.deleted = Some(arg_from_str(value.unwrap_or("false"), err, "deleted", "boolean")); + }, + "completed" => { + request.completed = Some(value.unwrap_or("").to_string()); + }, + "updated" => { + request.updated = Some(value.unwrap_or("").to_string()); + }, + "due" => { + request.due = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "notes" => { + request.notes = Some(value.unwrap_or("").to_string()); + }, + "position" => { + request.position = Some(value.unwrap_or("").to_string()); + }, + "hidden" => { + request.hidden = Some(arg_from_str(value.unwrap_or("false"), err, "hidden", "boolean")); + }, + "id" => { + request.id = Some(value.unwrap_or("").to_string()); + }, + "self-link" => { + request.self_link = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_tasklists { + if self.opt.cmd_delete { + call_result = self._tasklists_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tasklists_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._tasklists_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tasklists_list(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tasklists_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._tasklists_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_tasks { + if self.opt.cmd_clear { + call_result = self._tasks_clear(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._tasks_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._tasks_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._tasks_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._tasks_list(dry_run, &mut err); + } else if self.opt.cmd_move { + call_result = self._tasks_move(dry_run, &mut err); + } else if self.opt.cmd_patch { + call_result = self._tasks_patch(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._tasks_update(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "tasks1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "tasks1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::TasksHub::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/translate2-cli/Cargo.toml b/gen/translate2-cli/Cargo.toml new file mode 100644 index 00000000000..67ad1da6510 --- /dev/null +++ b/gen/translate2-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-translate2-cli" +version = "0.0.1+20141123" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with translate (protocol v2)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/translate2-cli" +homepage = "https://developers.google.com/translate/v2/using_rest" +documentation = "http://byron.github.io/google-apis-rs/google_translate2_cli" +license = "MIT" +keywords = ["translate", "google", "cli"] + +[[bin]] +name = "translate2" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-translate2] +path = "../translate2" diff --git a/gen/translate2-cli/LICENSE.md b/gen/translate2-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/translate2-cli/LICENSE.md @@ -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. diff --git a/gen/translate2-cli/README.md b/gen/translate2-cli/README.md new file mode 100644 index 00000000000..648e8e8fe7b --- /dev/null +++ b/gen/translate2-cli/README.md @@ -0,0 +1,4 @@ +# HELLO TRANSLATE:V2 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/translate2-cli/mkdocs.yml b/gen/translate2-cli/mkdocs.yml new file mode 100644 index 00000000000..7bf15057d02 --- /dev/null +++ b/gen/translate2-cli/mkdocs.yml @@ -0,0 +1,19 @@ +site_name: translate v0.0.1+20141123 +site_url: http://byron.github.io/google-apis-rs/google-translate2-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/translate2-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['detections_list.md', 'Detections', 'List'] +- ['languages_list.md', 'Languages', 'List'] +- ['translations_list.md', 'Translations', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/translate2-cli/src/cmn.rs b/gen/translate2-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/translate2-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/translate2-cli/src/main.rs b/gen/translate2-cli/src/main.rs new file mode 100644 index 00000000000..eece901a269 --- /dev/null +++ b/gen/translate2-cli/src/main.rs @@ -0,0 +1,283 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_translate2 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + translate2 [options] detections list <q> [-p <v>]... [-o <out>] + translate2 [options] languages list [-p <v>]... [-o <out>] + translate2 [options] translations list <q> <target> [-p <v>]... [-o <out>] + translate2 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Translate<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _detections_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.detections().list(&self.opt.arg_q); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _languages_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.languages().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "target" => { + call = call.target(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _translations_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.translations().list(&self.opt.arg_q, &self.opt.arg_target); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "source" => { + call = call.source(value.unwrap_or("")); + }, + "format" => { + call = call.format(value.unwrap_or("")); + }, + "cid" => { + call = call.add_cid(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_detections { + if self.opt.cmd_list { + call_result = self._detections_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_languages { + if self.opt.cmd_list { + call_result = self._languages_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_translations { + if self.opt.cmd_list { + call_result = self._translations_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "translate2-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "translate2", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Translate::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/urlshortener1-cli/Cargo.toml b/gen/urlshortener1-cli/Cargo.toml new file mode 100644 index 00000000000..bbae77b254a --- /dev/null +++ b/gen/urlshortener1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-urlshortener1-cli" +version = "0.0.1+20150319" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with urlshortener (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/urlshortener1-cli" +homepage = "https://developers.google.com/url-shortener/v1/getting_started" +documentation = "http://byron.github.io/google-apis-rs/google_urlshortener1_cli" +license = "MIT" +keywords = ["urlshortener", "google", "cli"] + +[[bin]] +name = "urlshortener1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-urlshortener1] +path = "../urlshortener1" diff --git a/gen/urlshortener1-cli/LICENSE.md b/gen/urlshortener1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/urlshortener1-cli/LICENSE.md @@ -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. diff --git a/gen/urlshortener1-cli/README.md b/gen/urlshortener1-cli/README.md new file mode 100644 index 00000000000..90ebf7b4658 --- /dev/null +++ b/gen/urlshortener1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO URLSHORTENER:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/urlshortener1-cli/mkdocs.yml b/gen/urlshortener1-cli/mkdocs.yml new file mode 100644 index 00000000000..d5f3db5303f --- /dev/null +++ b/gen/urlshortener1-cli/mkdocs.yml @@ -0,0 +1,19 @@ +site_name: urlshortener v0.0.1+20150319 +site_url: http://byron.github.io/google-apis-rs/google-urlshortener1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/urlshortener1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['url_get.md', 'Url', 'Get'] +- ['url_insert.md', 'Url', 'Insert'] +- ['url_list.md', 'Url', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/urlshortener1-cli/src/cmn.rs b/gen/urlshortener1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/urlshortener1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/urlshortener1-cli/src/main.rs b/gen/urlshortener1-cli/src/main.rs new file mode 100644 index 00000000000..fbcf4f8ae9e --- /dev/null +++ b/gen/urlshortener1-cli/src/main.rs @@ -0,0 +1,352 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_urlshortener1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + urlshortener1 [options] url get <short-url> [-p <v>]... [-o <out>] + urlshortener1 [options] url insert -r <kv>... [-p <v>]... [-o <out>] + urlshortener1 [options] url list [-p <v>]... [-o <out>] + urlshortener1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Urlshortener<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _url_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.url().get(&self.opt.arg_short_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Url = Default::default(); + let mut call = self.hub.url().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_analytics_init(request: &mut api::Url) { + if request.analytics.is_none() { + request.analytics = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status" => { + request.status = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "created" => { + request.created = Some(value.unwrap_or("").to_string()); + }, + "analytics.week.short-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().week.short_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.week.long-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().week.long_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.all-time.short-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().all_time.short_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.all-time.long-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().all_time.long_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.two-hours.short-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().two_hours.short_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.two-hours.long-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().two_hours.long_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.day.short-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().day.short_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.day.long-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().day.long_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.month.short-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().month.short_url_clicks = value.unwrap_or("").to_string(); + }, + "analytics.month.long-url-clicks" => { + request_analytics_init(&mut request); + request.analytics.as_mut().unwrap().month.long_url_clicks = value.unwrap_or("").to_string(); + }, + "long-url" => { + request_analytics_init(&mut request); + request.long_url = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_analytics_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _url_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.url().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-token" => { + call = call.start_token(value.unwrap_or("")); + }, + "projection" => { + call = call.projection(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_url { + if self.opt.cmd_get { + call_result = self._url_get(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._url_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._url_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "urlshortener1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "urlshortener1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Urlshortener::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/webfonts1-cli/Cargo.toml b/gen/webfonts1-cli/Cargo.toml new file mode 100644 index 00000000000..7caf5f3ecb0 --- /dev/null +++ b/gen/webfonts1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-webfonts1-cli" +version = "0.0.1+20140210" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with webfonts (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/webfonts1-cli" +homepage = "https://developers.google.com/fonts/docs/developer_api" +documentation = "http://byron.github.io/google-apis-rs/google_webfonts1_cli" +license = "MIT" +keywords = ["webfonts", "google", "cli"] + +[[bin]] +name = "webfonts1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-webfonts1] +path = "../webfonts1" diff --git a/gen/webfonts1-cli/LICENSE.md b/gen/webfonts1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/webfonts1-cli/LICENSE.md @@ -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. diff --git a/gen/webfonts1-cli/README.md b/gen/webfonts1-cli/README.md new file mode 100644 index 00000000000..5c37fe560e8 --- /dev/null +++ b/gen/webfonts1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO WEBFONTS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/webfonts1-cli/mkdocs.yml b/gen/webfonts1-cli/mkdocs.yml new file mode 100644 index 00000000000..924720343c7 --- /dev/null +++ b/gen/webfonts1-cli/mkdocs.yml @@ -0,0 +1,17 @@ +site_name: webfonts v0.0.1+20140210 +site_url: http://byron.github.io/google-apis-rs/google-webfonts1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/webfonts1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['webfonts_list.md', 'Webfonts', 'List'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/webfonts1-cli/src/cmn.rs b/gen/webfonts1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/webfonts1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/webfonts1-cli/src/main.rs b/gen/webfonts1-cli/src/main.rs new file mode 100644 index 00000000000..c7f0adde68f --- /dev/null +++ b/gen/webfonts1-cli/src/main.rs @@ -0,0 +1,172 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_webfonts1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + webfonts1 [options] webfonts list [-p <v>]... [-o <out>] + webfonts1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --config-dir <folder> + 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] +"); + +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::Webfonts<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _webfonts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.webfonts().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_webfonts { + if self.opt.cmd_list { + call_result = self._webfonts_list(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "webfonts1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "webfonts1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Webfonts::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/webmasters3-cli/Cargo.toml b/gen/webmasters3-cli/Cargo.toml new file mode 100644 index 00000000000..684bda9f95b --- /dev/null +++ b/gen/webmasters3-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-webmasters3-cli" +version = "0.0.1+20140908" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with webmasters (protocol v3)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/webmasters3-cli" +homepage = "https://developers.google.com/webmaster-tools/v3/welcome" +documentation = "http://byron.github.io/google-apis-rs/google_webmasters3_cli" +license = "MIT" +keywords = ["webmasters", "google", "cli"] + +[[bin]] +name = "webmasters3" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-webmasters3] +path = "../webmasters3" diff --git a/gen/webmasters3-cli/LICENSE.md b/gen/webmasters3-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/webmasters3-cli/LICENSE.md @@ -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. diff --git a/gen/webmasters3-cli/README.md b/gen/webmasters3-cli/README.md new file mode 100644 index 00000000000..4dd6d812ad1 --- /dev/null +++ b/gen/webmasters3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO WEBMASTERS:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/webmasters3-cli/mkdocs.yml b/gen/webmasters3-cli/mkdocs.yml new file mode 100644 index 00000000000..37c5f7b19a0 --- /dev/null +++ b/gen/webmasters3-cli/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: webmasters v0.0.1+20140908 +site_url: http://byron.github.io/google-apis-rs/google-webmasters3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/webmasters3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['sitemaps_delete.md', 'Sitemaps', 'Delete'] +- ['sitemaps_get.md', 'Sitemaps', 'Get'] +- ['sitemaps_list.md', 'Sitemaps', 'List'] +- ['sitemaps_submit.md', 'Sitemaps', 'Submit'] +- ['sites_add.md', 'Sites', 'Add'] +- ['sites_delete.md', 'Sites', 'Delete'] +- ['sites_get.md', 'Sites', 'Get'] +- ['sites_list.md', 'Sites', 'List'] +- ['urlcrawlerrorscounts_query.md', 'Urlcrawlerrorscounts', 'Query'] +- ['urlcrawlerrorssamples_get.md', 'Urlcrawlerrorssamples', 'Get'] +- ['urlcrawlerrorssamples_list.md', 'Urlcrawlerrorssamples', 'List'] +- ['urlcrawlerrorssamples_mark-as-fixed.md', 'Urlcrawlerrorssamples', 'Mark As Fixed'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/webmasters3-cli/src/cmn.rs b/gen/webmasters3-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/webmasters3-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/webmasters3-cli/src/main.rs b/gen/webmasters3-cli/src/main.rs new file mode 100644 index 00000000000..dff0e1a4973 --- /dev/null +++ b/gen/webmasters3-cli/src/main.rs @@ -0,0 +1,704 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_webmasters3 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + webmasters3 [options] sitemaps delete <site-url> <feedpath> [-p <v>]... + webmasters3 [options] sitemaps get <site-url> <feedpath> [-p <v>]... [-o <out>] + webmasters3 [options] sitemaps list <site-url> [-p <v>]... [-o <out>] + webmasters3 [options] sitemaps submit <site-url> <feedpath> [-p <v>]... + webmasters3 [options] sites add <site-url> [-p <v>]... + webmasters3 [options] sites delete <site-url> [-p <v>]... + webmasters3 [options] sites get <site-url> [-p <v>]... [-o <out>] + webmasters3 [options] sites list [-p <v>]... [-o <out>] + webmasters3 [options] urlcrawlerrorscounts query <site-url> [-p <v>]... [-o <out>] + webmasters3 [options] urlcrawlerrorssamples get <site-url> <url> <category> <platform> [-p <v>]... [-o <out>] + webmasters3 [options] urlcrawlerrorssamples list <site-url> <category> <platform> [-p <v>]... [-o <out>] + webmasters3 [options] urlcrawlerrorssamples mark-as-fixed <site-url> <url> <category> <platform> [-p <v>]... + webmasters3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::Webmasters<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _sitemaps_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sitemaps().delete(&self.opt.arg_site_url, &self.opt.arg_feedpath); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _sitemaps_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sitemaps().get(&self.opt.arg_site_url, &self.opt.arg_feedpath); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sitemaps_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sitemaps().list(&self.opt.arg_site_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sitemap-index" => { + call = call.sitemap_index(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sitemaps_submit(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sitemaps().submit(&self.opt.arg_site_url, &self.opt.arg_feedpath); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _sites_add(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().add(&self.opt.arg_site_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _sites_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().delete(&self.opt.arg_site_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _sites_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().get(&self.opt.arg_site_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _sites_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.sites().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlcrawlerrorscounts_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.urlcrawlerrorscounts().query(&self.opt.arg_site_url); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "platform" => { + call = call.platform(value.unwrap_or("")); + }, + "latest-counts-only" => { + call = call.latest_counts_only(arg_from_str(value.unwrap_or("false"), err, "latest-counts-only", "boolean")); + }, + "category" => { + call = call.category(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlcrawlerrorssamples_get(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.urlcrawlerrorssamples().get(&self.opt.arg_site_url, &self.opt.arg_url, &self.opt.arg_category, &self.opt.arg_platform); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlcrawlerrorssamples_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.urlcrawlerrorssamples().list(&self.opt.arg_site_url, &self.opt.arg_category, &self.opt.arg_platform); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _urlcrawlerrorssamples_mark_as_fixed(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.urlcrawlerrorssamples().mark_as_fixed(&self.opt.arg_site_url, &self.opt.arg_url, &self.opt.arg_category, &self.opt.arg_platform); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_sitemaps { + if self.opt.cmd_delete { + call_result = self._sitemaps_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._sitemaps_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._sitemaps_list(dry_run, &mut err); + } else if self.opt.cmd_submit { + call_result = self._sitemaps_submit(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_sites { + if self.opt.cmd_add { + call_result = self._sites_add(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._sites_delete(dry_run, &mut err); + } else if self.opt.cmd_get { + call_result = self._sites_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._sites_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_urlcrawlerrorscounts { + if self.opt.cmd_query { + call_result = self._urlcrawlerrorscounts_query(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_urlcrawlerrorssamples { + if self.opt.cmd_get { + call_result = self._urlcrawlerrorssamples_get(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._urlcrawlerrorssamples_list(dry_run, &mut err); + } else if self.opt.cmd_mark_as_fixed { + call_result = self._urlcrawlerrorssamples_mark_as_fixed(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "webmasters3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "webmasters3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::Webmasters::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file diff --git a/gen/youtube3-cli/Cargo.toml b/gen/youtube3-cli/Cargo.toml index b96b47a2b4f..dfd13c85971 100644 --- a/gen/youtube3-cli/Cargo.toml +++ b/gen/youtube3-cli/Cargo.toml @@ -20,9 +20,11 @@ name = "youtube3" hyper = "*" mime = "*" yup-oauth2 = "*" -docopt = "*" -docopt_macros = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" [dependencies.google-youtube3] path = "../youtube3" diff --git a/gen/youtube3-cli/README.md b/gen/youtube3-cli/README.md new file mode 100644 index 00000000000..a7c7291d0d9 --- /dev/null +++ b/gen/youtube3-cli/README.md @@ -0,0 +1,4 @@ +# HELLO YOUTUBE:V3 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/youtube3-cli/mkdocs.yml b/gen/youtube3-cli/mkdocs.yml new file mode 100644 index 00000000000..6fcf44b4d2c --- /dev/null +++ b/gen/youtube3-cli/mkdocs.yml @@ -0,0 +1,66 @@ +site_name: YouTube v0.0.1+20150327 +site_url: http://byron.github.io/google-apis-rs/google-youtube3-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/youtube3-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['activities_insert.md', 'Activities', 'Insert'] +- ['activities_list.md', 'Activities', 'List'] +- ['captions_delete.md', 'Captions', 'Delete'] +- ['captions_download.md', 'Captions', 'Download'] +- ['captions_insert.md', 'Captions', 'Insert'] +- ['captions_list.md', 'Captions', 'List'] +- ['captions_update.md', 'Captions', 'Update'] +- ['channel-banners_insert.md', 'Channel Banners', 'Insert'] +- ['channel-sections_delete.md', 'Channel Sections', 'Delete'] +- ['channel-sections_insert.md', 'Channel Sections', 'Insert'] +- ['channel-sections_list.md', 'Channel Sections', 'List'] +- ['channel-sections_update.md', 'Channel Sections', 'Update'] +- ['channels_list.md', 'Channels', 'List'] +- ['channels_update.md', 'Channels', 'Update'] +- ['guide-categories_list.md', 'Guide Categories', 'List'] +- ['i18n-languages_list.md', 'I18n Languages', 'List'] +- ['i18n-regions_list.md', 'I18n Regions', 'List'] +- ['live-broadcasts_bind.md', 'Live Broadcasts', 'Bind'] +- ['live-broadcasts_control.md', 'Live Broadcasts', 'Control'] +- ['live-broadcasts_delete.md', 'Live Broadcasts', 'Delete'] +- ['live-broadcasts_insert.md', 'Live Broadcasts', 'Insert'] +- ['live-broadcasts_list.md', 'Live Broadcasts', 'List'] +- ['live-broadcasts_transition.md', 'Live Broadcasts', 'Transition'] +- ['live-broadcasts_update.md', 'Live Broadcasts', 'Update'] +- ['live-streams_delete.md', 'Live Streams', 'Delete'] +- ['live-streams_insert.md', 'Live Streams', 'Insert'] +- ['live-streams_list.md', 'Live Streams', 'List'] +- ['live-streams_update.md', 'Live Streams', 'Update'] +- ['playlist-items_delete.md', 'Playlist Items', 'Delete'] +- ['playlist-items_insert.md', 'Playlist Items', 'Insert'] +- ['playlist-items_list.md', 'Playlist Items', 'List'] +- ['playlist-items_update.md', 'Playlist Items', 'Update'] +- ['playlists_delete.md', 'Playlists', 'Delete'] +- ['playlists_insert.md', 'Playlists', 'Insert'] +- ['playlists_list.md', 'Playlists', 'List'] +- ['playlists_update.md', 'Playlists', 'Update'] +- ['search_list.md', 'Search', 'List'] +- ['subscriptions_delete.md', 'Subscriptions', 'Delete'] +- ['subscriptions_insert.md', 'Subscriptions', 'Insert'] +- ['subscriptions_list.md', 'Subscriptions', 'List'] +- ['thumbnails_set.md', 'Thumbnails', 'Set'] +- ['video-categories_list.md', 'Video Categories', 'List'] +- ['videos_delete.md', 'Videos', 'Delete'] +- ['videos_get-rating.md', 'Videos', 'Get Rating'] +- ['videos_insert.md', 'Videos', 'Insert'] +- ['videos_list.md', 'Videos', 'List'] +- ['videos_rate.md', 'Videos', 'Rate'] +- ['videos_update.md', 'Videos', 'Update'] +- ['watermarks_set.md', 'Watermarks', 'Set'] +- ['watermarks_unset.md', 'Watermarks', 'Unset'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/youtube3-cli/src/cmn.rs b/gen/youtube3-cli/src/cmn.rs index 1d43a4a85c2..fd8d66fa4c3 100644 --- a/gen/youtube3-cli/src/cmn.rs +++ b/gen/youtube3-cli/src/cmn.rs @@ -1,2 +1,439 @@ // 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/youtube3-cli/src/main.rs b/gen/youtube3-cli/src/main.rs index fe26205ead1..ec0faf80a07 100644 --- a/gen/youtube3-cli/src/main.rs +++ b/gen/youtube3-cli/src/main.rs @@ -1,36 +1,7187 @@ // DO NOT EDIT ! // This file was generated automatically from 'src/mako/cli/main.rs.mako' // DO NOT EDIT ! -#![feature(plugin)] +#![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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_youtube3 as api; -docopt!(Args derive Debug, " +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " Usage: - youtube3 activities (insert|list) - youtube3 captions (delete|download|insert|list|update) - youtube3 channel-banners insert - youtube3 channel-sections (delete|insert|list|update) - youtube3 channels (list|update) - youtube3 guide-categories list - youtube3 i18n-languages list - youtube3 i18n-regions list - youtube3 live-broadcasts (bind|control|delete|insert|list|transition|update) - youtube3 live-streams (delete|insert|list|update) - youtube3 playlist-items (delete|insert|list|update) - youtube3 playlists (delete|insert|list|update) - youtube3 search list - youtube3 subscriptions (delete|insert|list) - youtube3 thumbnails set - youtube3 video-categories list - youtube3 videos (delete|get-rating|insert|list|rate|update) - youtube3 watermarks (set|unset) - youtube3 --help + youtube3 [options] activities insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] activities list <part> [-p <v>]... [-o <out>] + youtube3 [options] captions delete <id> [-p <v>]... + youtube3 [options] captions download <id> [-p <v>]... [-o <out>] + youtube3 [options] captions insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + youtube3 [options] captions list <part> <video-id> [-p <v>]... [-o <out>] + youtube3 [options] captions update -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + youtube3 [options] channel-banners insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + youtube3 [options] channel-sections delete <id> [-p <v>]... + youtube3 [options] channel-sections insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] channel-sections list <part> [-p <v>]... [-o <out>] + youtube3 [options] channel-sections update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] channels list <part> [-p <v>]... [-o <out>] + youtube3 [options] channels update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] guide-categories list <part> [-p <v>]... [-o <out>] + youtube3 [options] i18n-languages list <part> [-p <v>]... [-o <out>] + youtube3 [options] i18n-regions list <part> [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts bind <id> <part> [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts control <id> <part> [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts delete <id> [-p <v>]... + youtube3 [options] live-broadcasts insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts list <part> [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts transition <broadcast-status> <id> <part> [-p <v>]... [-o <out>] + youtube3 [options] live-broadcasts update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] live-streams delete <id> [-p <v>]... + youtube3 [options] live-streams insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] live-streams list <part> [-p <v>]... [-o <out>] + youtube3 [options] live-streams update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] playlist-items delete <id> [-p <v>]... + youtube3 [options] playlist-items insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] playlist-items list <part> [-p <v>]... [-o <out>] + youtube3 [options] playlist-items update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] playlists delete <id> [-p <v>]... + youtube3 [options] playlists insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] playlists list <part> [-p <v>]... [-o <out>] + youtube3 [options] playlists update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] search list <part> [-p <v>]... [-o <out>] + youtube3 [options] subscriptions delete <id> [-p <v>]... + youtube3 [options] subscriptions insert -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] subscriptions list <part> [-p <v>]... [-o <out>] + youtube3 [options] thumbnails set <video-id> -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + youtube3 [options] video-categories list <part> [-p <v>]... [-o <out>] + youtube3 [options] videos delete <id> [-p <v>]... + youtube3 [options] videos get-rating <id> [-p <v>]... [-o <out>] + youtube3 [options] videos insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... [-o <out>] + youtube3 [options] videos list <part> [-p <v>]... [-o <out>] + youtube3 [options] videos rate <id> <rating> [-p <v>]... + youtube3 [options] videos update -r <kv>... [-p <v>]... [-o <out>] + youtube3 [options] watermarks set <channel-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>]... + youtube3 [options] watermarks unset <channel-id> [-p <v>]... + youtube3 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] "); +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::YouTube<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _activities_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Activity = Default::default(); + let mut call = self.hub.activities().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Activity) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Activity) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.type" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "snippet.group-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().group_id = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "content-details.comment.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().comment.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.comment.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().comment.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.comment.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().comment.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.comment.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().comment.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.playlist-item.playlist-item-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlist_item.playlist_item_id = value.unwrap_or("").to_string(); + }, + "content-details.like.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().like.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.like.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().like.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.like.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().like.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.like.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().like.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.cta-type" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.cta_type = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.ad-tag" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.ad_tag = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.destination-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.destination_url = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.forecasting-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.forecasting_url.push(value.unwrap_or("").to_string()); + }, + "content-details.promoted-item.impression-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.impression_url.push(value.unwrap_or("").to_string()); + }, + "content-details.promoted-item.creative-view-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.creative_view_url = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.video_id = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.description-text" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.description_text = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.custom-cta-button-text" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.custom_cta_button_text = value.unwrap_or("").to_string(); + }, + "content-details.promoted-item.click-tracking-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().promoted_item.click_tracking_url = value.unwrap_or("").to_string(); + }, + "content-details.social.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.social.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.social.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.social.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.social.image-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.image_url = value.unwrap_or("").to_string(); + }, + "content-details.social.type" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.type_ = value.unwrap_or("").to_string(); + }, + "content-details.social.reference-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.reference_url = value.unwrap_or("").to_string(); + }, + "content-details.social.author" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().social.author = value.unwrap_or("").to_string(); + }, + "content-details.favorite.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().favorite.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.favorite.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().favorite.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.favorite.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().favorite.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.favorite.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().favorite.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.upload.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().upload.video_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.reason" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.reason = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.seed-resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.seed_resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.seed-resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.seed_resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.seed-resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.seed_resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.recommendation.seed-resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().recommendation.seed_resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.subscription.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().subscription.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.subscription.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().subscription.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.subscription.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().subscription.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.subscription.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().subscription.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.bulletin.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bulletin.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.bulletin.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bulletin.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.bulletin.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bulletin.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.bulletin.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bulletin.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "content-details.channel-item.resource-id.kind" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channel_item.resource_id.kind = value.unwrap_or("").to_string(); + }, + "content-details.channel-item.resource-id.channel-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channel_item.resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "content-details.channel-item.resource-id.playlist-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channel_item.resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "content-details.channel-item.resource-id.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channel_item.resource_id.video_id = value.unwrap_or("").to_string(); + }, + "kind" => { + request_content_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_content_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _activities_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.activities().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "region-code" => { + call = call.region_code(value.unwrap_or("")); + }, + "published-before" => { + call = call.published_before(value.unwrap_or("")); + }, + "published-after" => { + call = call.published_after(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "home" => { + call = call.home(arg_from_str(value.unwrap_or("false"), err, "home", "boolean")); + }, + "channel-id" => { + call = call.channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _captions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.captions().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of" => { + call = call.on_behalf_of(value.unwrap_or("")); + }, + "debug-project-id-override" => { + call = call.debug_project_id_override(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _captions_download(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut download_mode = false; + let mut call = self.hub.captions().download(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "tlang" => { + call = call.tlang(value.unwrap_or("")); + }, + "tfmt" => { + call = call.tfmt(value.unwrap_or("")); + }, + "on-behalf-of" => { + call = call.on_behalf_of(value.unwrap_or("")); + }, + "debug-project-id-override" => { + call = call.debug_project_id_override(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + if key == "alt" && value.unwrap_or("unset") == "media" { + download_mode = true; + } + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + if !download_mode { + } else { + io::copy(&mut response, &mut ostream).unwrap(); + } + None + } + } + } + } + + fn _captions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Caption = Default::default(); + let mut call = self.hub.captions().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync" => { + call = call.sync(arg_from_str(value.unwrap_or("false"), err, "sync", "boolean")); + }, + "on-behalf-of" => { + call = call.on_behalf_of(value.unwrap_or("")); + }, + "debug-project-id-override" => { + call = call.debug_project_id_override(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_snippet_init(request: &mut api::Caption) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.status" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "snippet.audio-track-type" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().audio_track_type = value.unwrap_or("").to_string(); + }, + "snippet.language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().language = value.unwrap_or("").to_string(); + }, + "snippet.name" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "snippet.video-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().video_id = value.unwrap_or("").to_string(); + }, + "snippet.is-draft" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_draft = arg_from_str(value.unwrap_or("false"), err, "snippet.is-draft", "boolean"); + }, + "snippet.is-auto-synced" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_auto_synced = arg_from_str(value.unwrap_or("false"), err, "snippet.is-auto-synced", "boolean"); + }, + "snippet.track-kind" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().track_kind = value.unwrap_or("").to_string(); + }, + "snippet.last-updated" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().last_updated = value.unwrap_or("").to_string(); + }, + "snippet.is-cc" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_cc = arg_from_str(value.unwrap_or("false"), err, "snippet.is-cc", "boolean"); + }, + "snippet.is-easy-reader" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_easy_reader = arg_from_str(value.unwrap_or("false"), err, "snippet.is-easy-reader", "boolean"); + }, + "snippet.is-large" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_large = arg_from_str(value.unwrap_or("false"), err, "snippet.is-large", "boolean"); + }, + "snippet.failure-reason" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().failure_reason = value.unwrap_or("").to_string(); + }, + "kind" => { + request_snippet_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _captions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.captions().list(&self.opt.arg_part, &self.opt.arg_video_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of" => { + call = call.on_behalf_of(value.unwrap_or("")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "debug-project-id-override" => { + call = call.debug_project_id_override(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _captions_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Caption = Default::default(); + let mut call = self.hub.captions().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "sync" => { + call = call.sync(arg_from_str(value.unwrap_or("false"), err, "sync", "boolean")); + }, + "on-behalf-of" => { + call = call.on_behalf_of(value.unwrap_or("")); + }, + "debug-project-id-override" => { + call = call.debug_project_id_override(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_snippet_init(request: &mut api::Caption) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.status" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().status = value.unwrap_or("").to_string(); + }, + "snippet.audio-track-type" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().audio_track_type = value.unwrap_or("").to_string(); + }, + "snippet.language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().language = value.unwrap_or("").to_string(); + }, + "snippet.name" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().name = value.unwrap_or("").to_string(); + }, + "snippet.video-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().video_id = value.unwrap_or("").to_string(); + }, + "snippet.is-draft" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_draft = arg_from_str(value.unwrap_or("false"), err, "snippet.is-draft", "boolean"); + }, + "snippet.is-auto-synced" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_auto_synced = arg_from_str(value.unwrap_or("false"), err, "snippet.is-auto-synced", "boolean"); + }, + "snippet.track-kind" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().track_kind = value.unwrap_or("").to_string(); + }, + "snippet.last-updated" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().last_updated = value.unwrap_or("").to_string(); + }, + "snippet.is-cc" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_cc = arg_from_str(value.unwrap_or("false"), err, "snippet.is-cc", "boolean"); + }, + "snippet.is-easy-reader" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_easy_reader = arg_from_str(value.unwrap_or("false"), err, "snippet.is-easy-reader", "boolean"); + }, + "snippet.is-large" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().is_large = arg_from_str(value.unwrap_or("false"), err, "snippet.is-large", "boolean"); + }, + "snippet.failure-reason" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().failure_reason = value.unwrap_or("").to_string(); + }, + "kind" => { + request_snippet_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channel_banners_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ChannelBannerResource = Default::default(); + let mut call = self.hub.channel_banners().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + match &field_name.to_string()[..] { + "url" => { + request.url = Some(value.unwrap_or("").to_string()); + }, + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channel_sections_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.channel_sections().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _channel_sections_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ChannelSection = Default::default(); + let mut call = self.hub.channel_sections().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::ChannelSection) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::ChannelSection) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.style" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().style = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.position" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().position = arg_from_str(value.unwrap_or("-0"), err, "snippet.position", "integer"); + }, + "snippet.type" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "content-details.channels" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channels.push(value.unwrap_or("").to_string()); + }, + "content-details.playlists" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlists.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_content_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_content_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channel_sections_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.channel_sections().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "channel-id" => { + call = call.channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channel_sections_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::ChannelSection = Default::default(); + let mut call = self.hub.channel_sections().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::ChannelSection) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::ChannelSection) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.style" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().style = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.position" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().position = arg_from_str(value.unwrap_or("-0"), err, "snippet.position", "integer"); + }, + "snippet.type" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "content-details.channels" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().channels.push(value.unwrap_or("").to_string()); + }, + "content-details.playlists" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().playlists.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_content_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_content_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.channels().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "my-subscribers" => { + call = call.my_subscribers(arg_from_str(value.unwrap_or("false"), err, "my-subscribers", "boolean")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "managed-by-me" => { + call = call.managed_by_me(arg_from_str(value.unwrap_or("false"), err, "managed-by-me", "boolean")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "for-username" => { + call = call.for_username(value.unwrap_or("")); + }, + "category-id" => { + call = call.category_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _channels_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Channel = Default::default(); + let mut call = self.hub.channels().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_audit_details_init(request: &mut api::Channel) { + if request.audit_details.is_none() { + request.audit_details = Some(Default::default()); + } + } + + fn request_branding_settings_init(request: &mut api::Channel) { + if request.branding_settings.is_none() { + request.branding_settings = Some(Default::default()); + } + } + + fn request_content_details_init(request: &mut api::Channel) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_content_owner_details_init(request: &mut api::Channel) { + if request.content_owner_details.is_none() { + request.content_owner_details = Some(Default::default()); + } + } + + fn request_invideo_promotion_init(request: &mut api::Channel) { + if request.invideo_promotion.is_none() { + request.invideo_promotion = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Channel) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_statistics_init(request: &mut api::Channel) { + if request.statistics.is_none() { + request.statistics = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Channel) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + fn request_topic_details_init(request: &mut api::Channel) { + if request.topic_details.is_none() { + request.topic_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "status.is-linked" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().is_linked = arg_from_str(value.unwrap_or("false"), err, "status.is-linked", "boolean"); + }, + "status.long-uploads-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().long_uploads_status = value.unwrap_or("").to_string(); + }, + "invideo-promotion.default-timing.offset-ms" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().default_timing.offset_ms = value.unwrap_or("").to_string(); + }, + "invideo-promotion.default-timing.type" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().default_timing.type_ = value.unwrap_or("").to_string(); + }, + "invideo-promotion.default-timing.duration-ms" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().default_timing.duration_ms = value.unwrap_or("").to_string(); + }, + "invideo-promotion.position.corner-position" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().position.corner_position = value.unwrap_or("").to_string(); + }, + "invideo-promotion.position.type" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().position.type_ = value.unwrap_or("").to_string(); + }, + "invideo-promotion.use-smart-timing" => { + request_invideo_promotion_init(&mut request); + request.invideo_promotion.as_mut().unwrap().use_smart_timing = arg_from_str(value.unwrap_or("false"), err, "invideo-promotion.use-smart-timing", "boolean"); + }, + "kind" => { + request_invideo_promotion_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "statistics.comment-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().comment_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.comment-count", "int64"); + }, + "statistics.subscriber-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().subscriber_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.subscriber-count", "int64"); + }, + "statistics.video-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().video_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.video-count", "int64"); + }, + "statistics.hidden-subscriber-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().hidden_subscriber_count = arg_from_str(value.unwrap_or("false"), err, "statistics.hidden-subscriber-count", "boolean"); + }, + "statistics.view-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().view_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.view-count", "int64"); + }, + "content-owner-details.content-owner" => { + request_content_owner_details_init(&mut request); + request.content_owner_details.as_mut().unwrap().content_owner = value.unwrap_or("").to_string(); + }, + "content-owner-details.time-linked" => { + request_content_owner_details_init(&mut request); + request.content_owner_details.as_mut().unwrap().time_linked = value.unwrap_or("").to_string(); + }, + "topic-details.topic-ids" => { + request_topic_details_init(&mut request); + request.topic_details.as_mut().unwrap().topic_ids.push(value.unwrap_or("").to_string()); + }, + "content-details.related-playlists.watch-later" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().related_playlists.watch_later = value.unwrap_or("").to_string(); + }, + "content-details.related-playlists.watch-history" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().related_playlists.watch_history = value.unwrap_or("").to_string(); + }, + "content-details.related-playlists.uploads" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().related_playlists.uploads = value.unwrap_or("").to_string(); + }, + "content-details.related-playlists.favorites" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().related_playlists.favorites = value.unwrap_or("").to_string(); + }, + "content-details.related-playlists.likes" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().related_playlists.likes = value.unwrap_or("").to_string(); + }, + "content-details.google-plus-user-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().google_plus_user_id = value.unwrap_or("").to_string(); + }, + "branding-settings.image.large-branded-banner-image-imap-script.default" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.large_branded_banner_image_imap_script.default = value.unwrap_or("").to_string(); + }, + "branding-settings.image.large-branded-banner-image-imap-script.default-language.value" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.large_branded_banner_image_imap_script.default_language.value = value.unwrap_or("").to_string(); + }, + "branding-settings.image.small-branded-banner-image-url.default" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.small_branded_banner_image_url.default = value.unwrap_or("").to_string(); + }, + "branding-settings.image.small-branded-banner-image-url.default-language.value" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.small_branded_banner_image_url.default_language.value = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tv-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tv_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tv-low-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tv_low_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.large-branded-banner-image-url.default" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.large_branded_banner_image_url.default = value.unwrap_or("").to_string(); + }, + "branding-settings.image.large-branded-banner-image-url.default-language.value" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.large_branded_banner_image_url.default_language.value = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tv-high-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tv_high_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.background-image-url.default" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.background_image_url.default = value.unwrap_or("").to_string(); + }, + "branding-settings.image.background-image-url.default-language.value" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.background_image_url.default_language.value = value.unwrap_or("").to_string(); + }, + "branding-settings.image.small-branded-banner-image-imap-script.default" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.small_branded_banner_image_imap_script.default = value.unwrap_or("").to_string(); + }, + "branding-settings.image.small-branded-banner-image-imap-script.default-language.value" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.small_branded_banner_image_imap_script.default_language.value = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-external-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_external_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.watch-icon-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.watch_icon_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tv-medium-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tv_medium_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-mobile-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_mobile_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tablet-hd-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tablet_hd_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tablet-low-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tablet_low_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.tracking-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.tracking_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-mobile-extra-hd-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_mobile_extra_hd_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tablet-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tablet_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-mobile-low-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_mobile_low_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-mobile-medium-hd-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_mobile_medium_hd_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-tablet-extra-hd-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_tablet_extra_hd_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.image.banner-mobile-hd-image-url" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().image.banner_mobile_hd_image_url = value.unwrap_or("").to_string(); + }, + "branding-settings.watch.text-color" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().watch.text_color = value.unwrap_or("").to_string(); + }, + "branding-settings.watch.featured-playlist-id" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().watch.featured_playlist_id = value.unwrap_or("").to_string(); + }, + "branding-settings.watch.background-color" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().watch.background_color = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.description" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.description = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.title" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.title = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.moderate-comments" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.moderate_comments = arg_from_str(value.unwrap_or("false"), err, "branding-settings.channel.moderate-comments", "boolean"); + }, + "branding-settings.channel.show-browse-view" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.show_browse_view = arg_from_str(value.unwrap_or("false"), err, "branding-settings.channel.show-browse-view", "boolean"); + }, + "branding-settings.channel.featured-channels-title" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.featured_channels_title = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.default-language" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.default_language = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.unsubscribed-trailer" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.unsubscribed_trailer = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.keywords" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.keywords = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.profile-color" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.profile_color = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.default-tab" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.default_tab = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.featured-channels-urls" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.featured_channels_urls.push(value.unwrap_or("").to_string()); + }, + "branding-settings.channel.tracking-analytics-account-id" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.tracking_analytics_account_id = value.unwrap_or("").to_string(); + }, + "branding-settings.channel.show-related-channels" => { + request_branding_settings_init(&mut request); + request.branding_settings.as_mut().unwrap().channel.show_related_channels = arg_from_str(value.unwrap_or("false"), err, "branding-settings.channel.show-related-channels", "boolean"); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.localized.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.description = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "audit-details.community-guidelines-good-standing" => { + request_audit_details_init(&mut request); + request.audit_details.as_mut().unwrap().community_guidelines_good_standing = arg_from_str(value.unwrap_or("false"), err, "audit-details.community-guidelines-good-standing", "boolean"); + }, + "audit-details.content-id-claims-good-standing" => { + request_audit_details_init(&mut request); + request.audit_details.as_mut().unwrap().content_id_claims_good_standing = arg_from_str(value.unwrap_or("false"), err, "audit-details.content-id-claims-good-standing", "boolean"); + }, + "audit-details.overall-good-standing" => { + request_audit_details_init(&mut request); + request.audit_details.as_mut().unwrap().overall_good_standing = arg_from_str(value.unwrap_or("false"), err, "audit-details.overall-good-standing", "boolean"); + }, + "audit-details.copyright-strikes-good-standing" => { + request_audit_details_init(&mut request); + request.audit_details.as_mut().unwrap().copyright_strikes_good_standing = arg_from_str(value.unwrap_or("false"), err, "audit-details.copyright-strikes-good-standing", "boolean"); + }, + "etag" => { + request_audit_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_audit_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _guide_categories_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.guide_categories().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "region-code" => { + call = call.region_code(value.unwrap_or("")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _i18n_languages_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.i18n_languages().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _i18n_regions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.i18n_regions().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_bind(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_broadcasts().bind(&self.opt.arg_id, &self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "stream-id" => { + call = call.stream_id(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_control(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_broadcasts().control(&self.opt.arg_id, &self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "walltime" => { + call = call.walltime(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "offset-time-ms" => { + call = call.offset_time_ms(value.unwrap_or("")); + }, + "display-slate" => { + call = call.display_slate(arg_from_str(value.unwrap_or("false"), err, "display-slate", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_broadcasts().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _live_broadcasts_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LiveBroadcast = Default::default(); + let mut call = self.hub.live_broadcasts().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::LiveBroadcast) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::LiveBroadcast) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::LiveBroadcast) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.recording-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().recording_status = value.unwrap_or("").to_string(); + }, + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "status.life-cycle-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().life_cycle_status = value.unwrap_or("").to_string(); + }, + "status.live-broadcast-priority" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().live_broadcast_priority = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.start-with-slate" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().start_with_slate = arg_from_str(value.unwrap_or("false"), err, "content-details.start-with-slate", "boolean"); + }, + "content-details.bound-stream-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bound_stream_id = value.unwrap_or("").to_string(); + }, + "content-details.enable-embed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_embed = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-embed", "boolean"); + }, + "content-details.enable-closed-captions" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_closed_captions = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-closed-captions", "boolean"); + }, + "content-details.enable-content-encryption" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_content_encryption = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-content-encryption", "boolean"); + }, + "content-details.record-from-start" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().record_from_start = arg_from_str(value.unwrap_or("false"), err, "content-details.record-from-start", "boolean"); + }, + "content-details.enable-dvr" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_dvr = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-dvr", "boolean"); + }, + "content-details.monitor-stream.broadcast-stream-delay-ms" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.broadcast_stream_delay_ms = arg_from_str(value.unwrap_or("-0"), err, "content-details.monitor-stream.broadcast-stream-delay-ms", "integer"); + }, + "content-details.monitor-stream.embed-html" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.embed_html = value.unwrap_or("").to_string(); + }, + "content-details.monitor-stream.enable-monitor-stream" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.enable_monitor_stream = arg_from_str(value.unwrap_or("false"), err, "content-details.monitor-stream.enable-monitor-stream", "boolean"); + }, + "snippet.actual-end-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().actual_end_time = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.scheduled-start-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().scheduled_start_time = value.unwrap_or("").to_string(); + }, + "snippet.actual-start-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().actual_start_time = value.unwrap_or("").to_string(); + }, + "snippet.scheduled-end-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().scheduled_end_time = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_broadcasts().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "broadcast-status" => { + call = call.broadcast_status(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_transition(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_broadcasts().transition(&self.opt.arg_broadcast_status, &self.opt.arg_id, &self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_broadcasts_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LiveBroadcast = Default::default(); + let mut call = self.hub.live_broadcasts().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::LiveBroadcast) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::LiveBroadcast) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::LiveBroadcast) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.recording-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().recording_status = value.unwrap_or("").to_string(); + }, + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "status.life-cycle-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().life_cycle_status = value.unwrap_or("").to_string(); + }, + "status.live-broadcast-priority" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().live_broadcast_priority = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.start-with-slate" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().start_with_slate = arg_from_str(value.unwrap_or("false"), err, "content-details.start-with-slate", "boolean"); + }, + "content-details.bound-stream-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().bound_stream_id = value.unwrap_or("").to_string(); + }, + "content-details.enable-embed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_embed = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-embed", "boolean"); + }, + "content-details.enable-closed-captions" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_closed_captions = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-closed-captions", "boolean"); + }, + "content-details.enable-content-encryption" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_content_encryption = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-content-encryption", "boolean"); + }, + "content-details.record-from-start" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().record_from_start = arg_from_str(value.unwrap_or("false"), err, "content-details.record-from-start", "boolean"); + }, + "content-details.enable-dvr" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().enable_dvr = arg_from_str(value.unwrap_or("false"), err, "content-details.enable-dvr", "boolean"); + }, + "content-details.monitor-stream.broadcast-stream-delay-ms" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.broadcast_stream_delay_ms = arg_from_str(value.unwrap_or("-0"), err, "content-details.monitor-stream.broadcast-stream-delay-ms", "integer"); + }, + "content-details.monitor-stream.embed-html" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.embed_html = value.unwrap_or("").to_string(); + }, + "content-details.monitor-stream.enable-monitor-stream" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().monitor_stream.enable_monitor_stream = arg_from_str(value.unwrap_or("false"), err, "content-details.monitor-stream.enable-monitor-stream", "boolean"); + }, + "snippet.actual-end-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().actual_end_time = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.scheduled-start-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().scheduled_start_time = value.unwrap_or("").to_string(); + }, + "snippet.actual-start-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().actual_start_time = value.unwrap_or("").to_string(); + }, + "snippet.scheduled-end-time" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().scheduled_end_time = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_streams_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_streams().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _live_streams_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LiveStream = Default::default(); + let mut call = self.hub.live_streams().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_cdn_init(request: &mut api::LiveStream) { + if request.cdn.is_none() { + request.cdn = Some(Default::default()); + } + } + + fn request_content_details_init(request: &mut api::LiveStream) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::LiveStream) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::LiveStream) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.stream-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().stream_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.is-reusable" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().is_reusable = arg_from_str(value.unwrap_or("false"), err, "content-details.is-reusable", "boolean"); + }, + "content-details.closed-captions-ingestion-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().closed_captions_ingestion_url = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-type" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_type = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.backup-ingestion-address" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.backup_ingestion_address = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.stream-name" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.stream_name = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.ingestion-address" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.ingestion_address = value.unwrap_or("").to_string(); + }, + "cdn.format" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().format = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_streams_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.live_streams().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _live_streams_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::LiveStream = Default::default(); + let mut call = self.hub.live_streams().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_cdn_init(request: &mut api::LiveStream) { + if request.cdn.is_none() { + request.cdn = Some(Default::default()); + } + } + + fn request_content_details_init(request: &mut api::LiveStream) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::LiveStream) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::LiveStream) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.stream-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().stream_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.is-reusable" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().is_reusable = arg_from_str(value.unwrap_or("false"), err, "content-details.is-reusable", "boolean"); + }, + "content-details.closed-captions-ingestion-url" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().closed_captions_ingestion_url = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-type" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_type = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.backup-ingestion-address" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.backup_ingestion_address = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.stream-name" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.stream_name = value.unwrap_or("").to_string(); + }, + "cdn.ingestion-info.ingestion-address" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().ingestion_info.ingestion_address = value.unwrap_or("").to_string(); + }, + "cdn.format" => { + request_cdn_init(&mut request); + request.cdn.as_mut().unwrap().format = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlist_items_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.playlist_items().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _playlist_items_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlaylistItem = Default::default(); + let mut call = self.hub.playlist_items().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::PlaylistItem) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::PlaylistItem) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::PlaylistItem) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.note" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().note = value.unwrap_or("").to_string(); + }, + "content-details.start-at" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().start_at = value.unwrap_or("").to_string(); + }, + "content-details.end-at" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().end_at = value.unwrap_or("").to_string(); + }, + "content-details.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().video_id = value.unwrap_or("").to_string(); + }, + "snippet.playlist-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().playlist_id = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.kind" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.kind = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.playlist-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.video-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.video_id = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.position" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().position = arg_from_str(value.unwrap_or("-0"), err, "snippet.position", "integer"); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlist_items_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.playlist_items().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "video-id" => { + call = call.video_id(value.unwrap_or("")); + }, + "playlist-id" => { + call = call.playlist_id(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlist_items_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::PlaylistItem = Default::default(); + let mut call = self.hub.playlist_items().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::PlaylistItem) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::PlaylistItem) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::PlaylistItem) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.note" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().note = value.unwrap_or("").to_string(); + }, + "content-details.start-at" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().start_at = value.unwrap_or("").to_string(); + }, + "content-details.end-at" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().end_at = value.unwrap_or("").to_string(); + }, + "content-details.video-id" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().video_id = value.unwrap_or("").to_string(); + }, + "snippet.playlist-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().playlist_id = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.kind" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.kind = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.playlist-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.video-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.video_id = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.position" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().position = arg_from_str(value.unwrap_or("-0"), err, "snippet.position", "integer"); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlists_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.playlists().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _playlists_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Playlist = Default::default(); + let mut call = self.hub.playlists().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Playlist) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_player_init(request: &mut api::Playlist) { + if request.player.is_none() { + request.player = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Playlist) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Playlist) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.item-count", "integer"); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.tags" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.localized.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.description = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "player.embed-html" => { + request_player_init(&mut request); + request.player.as_mut().unwrap().embed_html = value.unwrap_or("").to_string(); + }, + "etag" => { + request_player_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_player_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlists_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.playlists().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "channel-id" => { + call = call.channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _playlists_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Playlist = Default::default(); + let mut call = self.hub.playlists().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Playlist) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_player_init(request: &mut api::Playlist) { + if request.player.is_none() { + request.player = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Playlist) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Playlist) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "kind" => { + request_status_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.item-count", "integer"); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.tags" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.localized.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.description = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "player.embed-html" => { + request_player_init(&mut request); + request.player.as_mut().unwrap().embed_html = value.unwrap_or("").to_string(); + }, + "etag" => { + request_player_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_player_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _search_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.search().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "video-type" => { + call = call.video_type(value.unwrap_or("")); + }, + "video-syndicated" => { + call = call.video_syndicated(value.unwrap_or("")); + }, + "video-license" => { + call = call.video_license(value.unwrap_or("")); + }, + "video-embeddable" => { + call = call.video_embeddable(value.unwrap_or("")); + }, + "video-duration" => { + call = call.video_duration(value.unwrap_or("")); + }, + "video-dimension" => { + call = call.video_dimension(value.unwrap_or("")); + }, + "video-definition" => { + call = call.video_definition(value.unwrap_or("")); + }, + "video-category-id" => { + call = call.video_category_id(value.unwrap_or("")); + }, + "video-caption" => { + call = call.video_caption(value.unwrap_or("")); + }, + "type" => { + call = call.type_(value.unwrap_or("")); + }, + "topic-id" => { + call = call.topic_id(value.unwrap_or("")); + }, + "safe-search" => { + call = call.safe_search(value.unwrap_or("")); + }, + "relevance-language" => { + call = call.relevance_language(value.unwrap_or("")); + }, + "related-to-video-id" => { + call = call.related_to_video_id(value.unwrap_or("")); + }, + "region-code" => { + call = call.region_code(value.unwrap_or("")); + }, + "q" => { + call = call.q(value.unwrap_or("")); + }, + "published-before" => { + call = call.published_before(value.unwrap_or("")); + }, + "published-after" => { + call = call.published_after(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order" => { + call = call.order(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "location-radius" => { + call = call.location_radius(value.unwrap_or("")); + }, + "location" => { + call = call.location(value.unwrap_or("")); + }, + "for-mine" => { + call = call.for_mine(arg_from_str(value.unwrap_or("false"), err, "for-mine", "boolean")); + }, + "for-developer" => { + call = call.for_developer(arg_from_str(value.unwrap_or("false"), err, "for-developer", "boolean")); + }, + "for-content-owner" => { + call = call.for_content_owner(arg_from_str(value.unwrap_or("false"), err, "for-content-owner", "boolean")); + }, + "event-type" => { + call = call.event_type(value.unwrap_or("")); + }, + "channel-type" => { + call = call.channel_type(value.unwrap_or("")); + }, + "channel-id" => { + call = call.channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _subscriptions_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Subscription = Default::default(); + let mut call = self.hub.subscriptions().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Subscription) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Subscription) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_subscriber_snippet_init(request: &mut api::Subscription) { + if request.subscriber_snippet.is_none() { + request.subscriber_snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "content-details.new-item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().new_item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.new-item-count", "integer"); + }, + "content-details.activity-type" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().activity_type = value.unwrap_or("").to_string(); + }, + "content-details.total-item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().total_item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.total-item-count", "integer"); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.kind" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.kind = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.channel_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.playlist-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.playlist_id = value.unwrap_or("").to_string(); + }, + "snippet.resource-id.video-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().resource_id.video_id = value.unwrap_or("").to_string(); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "etag" => { + request_snippet_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.title" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "subscriber-snippet.channel-id" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "subscriber-snippet.description" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "subscriber-snippet.thumbnails.default.url" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.thumbnails.default.width" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.default.width", "integer")); + }, + "subscriber-snippet.thumbnails.default.height" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.default.height", "integer")); + }, + "subscriber-snippet.thumbnails.high.url" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.thumbnails.high.width" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.high.width", "integer")); + }, + "subscriber-snippet.thumbnails.high.height" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.high.height", "integer")); + }, + "subscriber-snippet.thumbnails.medium.url" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.thumbnails.medium.width" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.medium.width", "integer")); + }, + "subscriber-snippet.thumbnails.medium.height" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.medium.height", "integer")); + }, + "subscriber-snippet.thumbnails.maxres.url" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.thumbnails.maxres.width" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.maxres.width", "integer")); + }, + "subscriber-snippet.thumbnails.maxres.height" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.maxres.height", "integer")); + }, + "subscriber-snippet.thumbnails.standard.url" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "subscriber-snippet.thumbnails.standard.width" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.standard.width", "integer")); + }, + "subscriber-snippet.thumbnails.standard.height" => { + request_subscriber_snippet_init(&mut request); + request.subscriber_snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "subscriber-snippet.thumbnails.standard.height", "integer")); + }, + "id" => { + request_subscriber_snippet_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _subscriptions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.subscriptions().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "order" => { + call = call.order(value.unwrap_or("")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "my-subscribers" => { + call = call.my_subscribers(arg_from_str(value.unwrap_or("false"), err, "my-subscribers", "boolean")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "for-channel-id" => { + call = call.for_channel_id(value.unwrap_or("")); + }, + "channel-id" => { + call = call.channel_id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _thumbnails_set(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.thumbnails().set(&self.opt.arg_video_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _video_categories_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.video_categories().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "region-code" => { + call = call.region_code(value.unwrap_or("")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _videos_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.videos().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _videos_get_rating(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.videos().get_rating(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _videos_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Video = Default::default(); + let mut call = self.hub.videos().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "stabilize" => { + call = call.stabilize(arg_from_str(value.unwrap_or("false"), err, "stabilize", "boolean")); + }, + "on-behalf-of-content-owner-channel" => { + call = call.on_behalf_of_content_owner_channel(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "notify-subscribers" => { + call = call.notify_subscribers(arg_from_str(value.unwrap_or("false"), err, "notify-subscribers", "boolean")); + }, + "auto-levels" => { + call = call.auto_levels(arg_from_str(value.unwrap_or("false"), err, "auto-levels", "boolean")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_age_gating_init(request: &mut api::Video) { + if request.age_gating.is_none() { + request.age_gating = Some(Default::default()); + } + } + + fn request_content_details_init(request: &mut api::Video) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_file_details_init(request: &mut api::Video) { + if request.file_details.is_none() { + request.file_details = Some(Default::default()); + } + } + + fn request_live_streaming_details_init(request: &mut api::Video) { + if request.live_streaming_details.is_none() { + request.live_streaming_details = Some(Default::default()); + } + } + + fn request_monetization_details_init(request: &mut api::Video) { + if request.monetization_details.is_none() { + request.monetization_details = Some(Default::default()); + } + } + + fn request_player_init(request: &mut api::Video) { + if request.player.is_none() { + request.player = Some(Default::default()); + } + } + + fn request_processing_details_init(request: &mut api::Video) { + if request.processing_details.is_none() { + request.processing_details = Some(Default::default()); + } + } + + fn request_project_details_init(request: &mut api::Video) { + if request.project_details.is_none() { + request.project_details = Some(Default::default()); + } + } + + fn request_recording_details_init(request: &mut api::Video) { + if request.recording_details.is_none() { + request.recording_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Video) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_statistics_init(request: &mut api::Video) { + if request.statistics.is_none() { + request.statistics = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Video) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + fn request_suggestions_init(request: &mut api::Video) { + if request.suggestions.is_none() { + request.suggestions = Some(Default::default()); + } + } + + fn request_topic_details_init(request: &mut api::Video) { + if request.topic_details.is_none() { + request.topic_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.license" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().license = value.unwrap_or("").to_string(); + }, + "status.embeddable" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().embeddable = arg_from_str(value.unwrap_or("false"), err, "status.embeddable", "boolean"); + }, + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "status.publish-at" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().publish_at = value.unwrap_or("").to_string(); + }, + "status.public-stats-viewable" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().public_stats_viewable = arg_from_str(value.unwrap_or("false"), err, "status.public-stats-viewable", "boolean"); + }, + "status.upload-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().upload_status = value.unwrap_or("").to_string(); + }, + "status.rejection-reason" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().rejection_reason = value.unwrap_or("").to_string(); + }, + "status.failure-reason" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().failure_reason = value.unwrap_or("").to_string(); + }, + "topic-details.topic-ids" => { + request_topic_details_init(&mut request); + request.topic_details.as_mut().unwrap().topic_ids.push(value.unwrap_or("").to_string()); + }, + "topic-details.relevant-topic-ids" => { + request_topic_details_init(&mut request); + request.topic_details.as_mut().unwrap().relevant_topic_ids.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_topic_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "statistics.comment-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().comment_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.comment-count", "int64"); + }, + "statistics.view-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().view_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.view-count", "int64"); + }, + "statistics.favorite-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().favorite_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.favorite-count", "int64"); + }, + "statistics.dislike-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().dislike_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.dislike-count", "int64"); + }, + "statistics.like-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().like_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.like-count", "int64"); + }, + "content-details.definition" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().definition = value.unwrap_or("").to_string(); + }, + "content-details.country-restriction.exception" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().country_restriction.exception.push(value.unwrap_or("").to_string()); + }, + "content-details.country-restriction.allowed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().country_restriction.allowed = arg_from_str(value.unwrap_or("false"), err, "content-details.country-restriction.allowed", "boolean"); + }, + "content-details.content-rating.yt-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.yt_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.catvfr-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.catvfr_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cbfc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cbfc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bfvc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bfvc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mda-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mda_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.acb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.acb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nfvcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nfvcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bmukk-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bmukk_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.chfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.chfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.resorteviolencia-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.resorteviolencia_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.csa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.csa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.moctw-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.moctw_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.anatel-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.anatel_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.catv-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.catv_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.pefilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.pefilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.djctq-rating-reasons" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.djctq_rating_reasons.push(value.unwrap_or("").to_string()); + }, + "content-details.content-rating.incaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.incaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.oflc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.oflc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fpb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fpb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mccaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mccaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.tvpg-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.tvpg_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rtc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rtc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cscf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cscf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fsk-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fsk_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bbfc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bbfc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kmrb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kmrb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.smsa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.smsa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.egfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.egfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cicf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cicf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nbcpl-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nbcpl_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nbc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nbc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.djctq-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.djctq_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ifco-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ifco_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fco-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fco_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.eefilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.eefilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.medietilsynet-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.medietilsynet_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.grfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.grfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ccc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ccc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rte-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rte_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.czfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.czfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.lsf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.lsf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fmoc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fmoc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.eirin-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.eirin_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cce-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cce_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nkclv-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nkclv_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mtrcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mtrcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mibac-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mibac_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ilfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ilfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.smais-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.smais_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.russia-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.russia_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mpaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mpaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kfcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kfcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.agcom-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.agcom_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.chvrs-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.chvrs_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cna-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cna_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.icaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.icaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mccyp-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mccyp_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nfrc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nfrc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.skfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.skfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.moc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.moc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rcnof-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rcnof_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.meku-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.meku_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fcbm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fcbm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kijkwijzer-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kijkwijzer_rating = value.unwrap_or("").to_string(); + }, + "content-details.caption" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().caption = value.unwrap_or("").to_string(); + }, + "content-details.region-restriction.blocked" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().region_restriction.blocked.push(value.unwrap_or("").to_string()); + }, + "content-details.region-restriction.allowed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().region_restriction.allowed.push(value.unwrap_or("").to_string()); + }, + "content-details.duration" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().duration = value.unwrap_or("").to_string(); + }, + "content-details.licensed-content" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().licensed_content = arg_from_str(value.unwrap_or("false"), err, "content-details.licensed-content", "boolean"); + }, + "content-details.dimension" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "monetization-details.access.exception" => { + request_monetization_details_init(&mut request); + request.monetization_details.as_mut().unwrap().access.exception.push(value.unwrap_or("").to_string()); + }, + "monetization-details.access.allowed" => { + request_monetization_details_init(&mut request); + request.monetization_details.as_mut().unwrap().access.allowed = arg_from_str(value.unwrap_or("false"), err, "monetization-details.access.allowed", "boolean"); + }, + "age-gating.restricted" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "age-gating.restricted", "boolean"); + }, + "age-gating.alcohol-content" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().alcohol_content = arg_from_str(value.unwrap_or("false"), err, "age-gating.alcohol-content", "boolean"); + }, + "age-gating.video-game-rating" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().video_game_rating = value.unwrap_or("").to_string(); + }, + "suggestions.processing-errors" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_errors.push(value.unwrap_or("").to_string()); + }, + "suggestions.editor-suggestions" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().editor_suggestions.push(value.unwrap_or("").to_string()); + }, + "suggestions.processing-warnings" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_warnings.push(value.unwrap_or("").to_string()); + }, + "suggestions.processing-hints" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_hints.push(value.unwrap_or("").to_string()); + }, + "live-streaming-details.concurrent-viewers" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().concurrent_viewers = value.unwrap_or("").to_string(); + }, + "live-streaming-details.scheduled-start-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().scheduled_start_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.scheduled-end-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().scheduled_end_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.actual-start-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().actual_start_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.actual-end-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().actual_end_time = value.unwrap_or("").to_string(); + }, + "file-details.bitrate-bps" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().bitrate_bps = value.unwrap_or("").to_string(); + }, + "file-details.container" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().container = value.unwrap_or("").to_string(); + }, + "file-details.recording-location.latitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.latitude", "number"); + }, + "file-details.recording-location.altitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.altitude", "number"); + }, + "file-details.recording-location.longitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.longitude", "number"); + }, + "file-details.file-type" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_type = value.unwrap_or("").to_string(); + }, + "file-details.creation-time" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().creation_time = value.unwrap_or("").to_string(); + }, + "file-details.duration-ms" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().duration_ms = value.unwrap_or("").to_string(); + }, + "file-details.file-name" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_name = value.unwrap_or("").to_string(); + }, + "file-details.file-size" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_size = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.tags" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.live-broadcast-content" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().live_broadcast_content = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.category-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().category_id = value.unwrap_or("").to_string(); + }, + "snippet.localized.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.description = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "player.embed-html" => { + request_player_init(&mut request); + request.player.as_mut().unwrap().embed_html = value.unwrap_or("").to_string(); + }, + "processing-details.file-details-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().file_details_availability = value.unwrap_or("").to_string(); + }, + "processing-details.editor-suggestions-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().editor_suggestions_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-status" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_status = value.unwrap_or("").to_string(); + }, + "processing-details.processing-issues-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_issues_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-failure-reason" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_failure_reason = value.unwrap_or("").to_string(); + }, + "processing-details.thumbnails-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().thumbnails_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.time-left-ms" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.time_left_ms = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.parts-processed" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.parts_processed = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.parts-total" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.parts_total = value.unwrap_or("").to_string(); + }, + "processing-details.tag-suggestions-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().tag_suggestions_availability = value.unwrap_or("").to_string(); + }, + "etag" => { + request_processing_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "project-details.tags" => { + request_project_details_init(&mut request); + request.project_details.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "recording-details.recording-date" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().recording_date = value.unwrap_or("").to_string(); + }, + "recording-details.location-description" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location_description = value.unwrap_or("").to_string(); + }, + "recording-details.location.latitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.latitude", "number"); + }, + "recording-details.location.altitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.altitude", "number"); + }, + "recording-details.location.longitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.longitude", "number"); + }, + "id" => { + request_recording_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _videos_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.videos().list(&self.opt.arg_part); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "video-category-id" => { + call = call.video_category_id(value.unwrap_or("")); + }, + "region-code" => { + call = call.region_code(value.unwrap_or("")); + }, + "page-token" => { + call = call.page_token(value.unwrap_or("")); + }, + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "my-rating" => { + call = call.my_rating(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "locale" => { + call = call.locale(value.unwrap_or("")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "hl" => { + call = call.hl(value.unwrap_or("")); + }, + "chart" => { + call = call.chart(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _videos_rate(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.videos().rate(&self.opt.arg_id, &self.opt.arg_rating); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _videos_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Video = Default::default(); + let mut call = self.hub.videos().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_age_gating_init(request: &mut api::Video) { + if request.age_gating.is_none() { + request.age_gating = Some(Default::default()); + } + } + + fn request_content_details_init(request: &mut api::Video) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_file_details_init(request: &mut api::Video) { + if request.file_details.is_none() { + request.file_details = Some(Default::default()); + } + } + + fn request_live_streaming_details_init(request: &mut api::Video) { + if request.live_streaming_details.is_none() { + request.live_streaming_details = Some(Default::default()); + } + } + + fn request_monetization_details_init(request: &mut api::Video) { + if request.monetization_details.is_none() { + request.monetization_details = Some(Default::default()); + } + } + + fn request_player_init(request: &mut api::Video) { + if request.player.is_none() { + request.player = Some(Default::default()); + } + } + + fn request_processing_details_init(request: &mut api::Video) { + if request.processing_details.is_none() { + request.processing_details = Some(Default::default()); + } + } + + fn request_project_details_init(request: &mut api::Video) { + if request.project_details.is_none() { + request.project_details = Some(Default::default()); + } + } + + fn request_recording_details_init(request: &mut api::Video) { + if request.recording_details.is_none() { + request.recording_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Video) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + fn request_statistics_init(request: &mut api::Video) { + if request.statistics.is_none() { + request.statistics = Some(Default::default()); + } + } + + fn request_status_init(request: &mut api::Video) { + if request.status.is_none() { + request.status = Some(Default::default()); + } + } + + fn request_suggestions_init(request: &mut api::Video) { + if request.suggestions.is_none() { + request.suggestions = Some(Default::default()); + } + } + + fn request_topic_details_init(request: &mut api::Video) { + if request.topic_details.is_none() { + request.topic_details = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "status.license" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().license = value.unwrap_or("").to_string(); + }, + "status.embeddable" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().embeddable = arg_from_str(value.unwrap_or("false"), err, "status.embeddable", "boolean"); + }, + "status.privacy-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().privacy_status = value.unwrap_or("").to_string(); + }, + "status.publish-at" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().publish_at = value.unwrap_or("").to_string(); + }, + "status.public-stats-viewable" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().public_stats_viewable = arg_from_str(value.unwrap_or("false"), err, "status.public-stats-viewable", "boolean"); + }, + "status.upload-status" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().upload_status = value.unwrap_or("").to_string(); + }, + "status.rejection-reason" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().rejection_reason = value.unwrap_or("").to_string(); + }, + "status.failure-reason" => { + request_status_init(&mut request); + request.status.as_mut().unwrap().failure_reason = value.unwrap_or("").to_string(); + }, + "topic-details.topic-ids" => { + request_topic_details_init(&mut request); + request.topic_details.as_mut().unwrap().topic_ids.push(value.unwrap_or("").to_string()); + }, + "topic-details.relevant-topic-ids" => { + request_topic_details_init(&mut request); + request.topic_details.as_mut().unwrap().relevant_topic_ids.push(value.unwrap_or("").to_string()); + }, + "kind" => { + request_topic_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "statistics.comment-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().comment_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.comment-count", "int64"); + }, + "statistics.view-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().view_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.view-count", "int64"); + }, + "statistics.favorite-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().favorite_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.favorite-count", "int64"); + }, + "statistics.dislike-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().dislike_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.dislike-count", "int64"); + }, + "statistics.like-count" => { + request_statistics_init(&mut request); + request.statistics.as_mut().unwrap().like_count = arg_from_str(value.unwrap_or("-0"), err, "statistics.like-count", "int64"); + }, + "content-details.definition" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().definition = value.unwrap_or("").to_string(); + }, + "content-details.country-restriction.exception" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().country_restriction.exception.push(value.unwrap_or("").to_string()); + }, + "content-details.country-restriction.allowed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().country_restriction.allowed = arg_from_str(value.unwrap_or("false"), err, "content-details.country-restriction.allowed", "boolean"); + }, + "content-details.content-rating.yt-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.yt_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.catvfr-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.catvfr_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cbfc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cbfc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bfvc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bfvc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mda-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mda_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.acb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.acb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nfvcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nfvcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bmukk-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bmukk_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.chfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.chfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.resorteviolencia-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.resorteviolencia_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.csa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.csa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.moctw-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.moctw_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.anatel-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.anatel_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.catv-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.catv_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.pefilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.pefilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.djctq-rating-reasons" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.djctq_rating_reasons.push(value.unwrap_or("").to_string()); + }, + "content-details.content-rating.incaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.incaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.oflc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.oflc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fpb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fpb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mccaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mccaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.tvpg-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.tvpg_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rtc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rtc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cscf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cscf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fsk-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fsk_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.bbfc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.bbfc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kmrb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kmrb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.smsa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.smsa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.egfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.egfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cicf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cicf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nbcpl-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nbcpl_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nbc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nbc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.djctq-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.djctq_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ifco-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ifco_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fco-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fco_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.eefilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.eefilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.medietilsynet-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.medietilsynet_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.grfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.grfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ccc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ccc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rte-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rte_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.czfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.czfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.lsf-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.lsf_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fmoc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fmoc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.eirin-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.eirin_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cce-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cce_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nkclv-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nkclv_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mtrcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mtrcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mibac-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mibac_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.ilfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.ilfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.smais-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.smais_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.russia-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.russia_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mpaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mpaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kfcb-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kfcb_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.agcom-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.agcom_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.chvrs-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.chvrs_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.cna-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.cna_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.icaa-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.icaa_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.mccyp-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.mccyp_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.nfrc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.nfrc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.skfilm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.skfilm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.moc-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.moc_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.rcnof-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.rcnof_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.meku-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.meku_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.fcbm-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.fcbm_rating = value.unwrap_or("").to_string(); + }, + "content-details.content-rating.kijkwijzer-rating" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().content_rating.kijkwijzer_rating = value.unwrap_or("").to_string(); + }, + "content-details.caption" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().caption = value.unwrap_or("").to_string(); + }, + "content-details.region-restriction.blocked" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().region_restriction.blocked.push(value.unwrap_or("").to_string()); + }, + "content-details.region-restriction.allowed" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().region_restriction.allowed.push(value.unwrap_or("").to_string()); + }, + "content-details.duration" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().duration = value.unwrap_or("").to_string(); + }, + "content-details.licensed-content" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().licensed_content = arg_from_str(value.unwrap_or("false"), err, "content-details.licensed-content", "boolean"); + }, + "content-details.dimension" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().dimension = value.unwrap_or("").to_string(); + }, + "monetization-details.access.exception" => { + request_monetization_details_init(&mut request); + request.monetization_details.as_mut().unwrap().access.exception.push(value.unwrap_or("").to_string()); + }, + "monetization-details.access.allowed" => { + request_monetization_details_init(&mut request); + request.monetization_details.as_mut().unwrap().access.allowed = arg_from_str(value.unwrap_or("false"), err, "monetization-details.access.allowed", "boolean"); + }, + "age-gating.restricted" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().restricted = arg_from_str(value.unwrap_or("false"), err, "age-gating.restricted", "boolean"); + }, + "age-gating.alcohol-content" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().alcohol_content = arg_from_str(value.unwrap_or("false"), err, "age-gating.alcohol-content", "boolean"); + }, + "age-gating.video-game-rating" => { + request_age_gating_init(&mut request); + request.age_gating.as_mut().unwrap().video_game_rating = value.unwrap_or("").to_string(); + }, + "suggestions.processing-errors" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_errors.push(value.unwrap_or("").to_string()); + }, + "suggestions.editor-suggestions" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().editor_suggestions.push(value.unwrap_or("").to_string()); + }, + "suggestions.processing-warnings" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_warnings.push(value.unwrap_or("").to_string()); + }, + "suggestions.processing-hints" => { + request_suggestions_init(&mut request); + request.suggestions.as_mut().unwrap().processing_hints.push(value.unwrap_or("").to_string()); + }, + "live-streaming-details.concurrent-viewers" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().concurrent_viewers = value.unwrap_or("").to_string(); + }, + "live-streaming-details.scheduled-start-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().scheduled_start_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.scheduled-end-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().scheduled_end_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.actual-start-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().actual_start_time = value.unwrap_or("").to_string(); + }, + "live-streaming-details.actual-end-time" => { + request_live_streaming_details_init(&mut request); + request.live_streaming_details.as_mut().unwrap().actual_end_time = value.unwrap_or("").to_string(); + }, + "file-details.bitrate-bps" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().bitrate_bps = value.unwrap_or("").to_string(); + }, + "file-details.container" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().container = value.unwrap_or("").to_string(); + }, + "file-details.recording-location.latitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.latitude", "number"); + }, + "file-details.recording-location.altitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.altitude", "number"); + }, + "file-details.recording-location.longitude" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().recording_location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "file-details.recording-location.longitude", "number"); + }, + "file-details.file-type" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_type = value.unwrap_or("").to_string(); + }, + "file-details.creation-time" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().creation_time = value.unwrap_or("").to_string(); + }, + "file-details.duration-ms" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().duration_ms = value.unwrap_or("").to_string(); + }, + "file-details.file-name" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_name = value.unwrap_or("").to_string(); + }, + "file-details.file-size" => { + request_file_details_init(&mut request); + request.file_details.as_mut().unwrap().file_size = value.unwrap_or("").to_string(); + }, + "snippet.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().description = value.unwrap_or("").to_string(); + }, + "snippet.tags" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "snippet.channel-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_id = value.unwrap_or("").to_string(); + }, + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.live-broadcast-content" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().live_broadcast_content = value.unwrap_or("").to_string(); + }, + "snippet.default-language" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().default_language = value.unwrap_or("").to_string(); + }, + "snippet.channel-title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().channel_title = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "snippet.category-id" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().category_id = value.unwrap_or("").to_string(); + }, + "snippet.localized.description" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.description = value.unwrap_or("").to_string(); + }, + "snippet.localized.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().localized.title = value.unwrap_or("").to_string(); + }, + "snippet.thumbnails.default.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.default.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.width", "integer")); + }, + "snippet.thumbnails.default.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.default.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.default.height", "integer")); + }, + "snippet.thumbnails.high.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.high.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.width", "integer")); + }, + "snippet.thumbnails.high.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.high.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.high.height", "integer")); + }, + "snippet.thumbnails.medium.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.medium.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.width", "integer")); + }, + "snippet.thumbnails.medium.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.medium.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.medium.height", "integer")); + }, + "snippet.thumbnails.maxres.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.maxres.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.width", "integer")); + }, + "snippet.thumbnails.maxres.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.maxres.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.maxres.height", "integer")); + }, + "snippet.thumbnails.standard.url" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.url = Some(value.unwrap_or("").to_string()); + }, + "snippet.thumbnails.standard.width" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.width = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.width", "integer")); + }, + "snippet.thumbnails.standard.height" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().thumbnails.standard.height = Some(arg_from_str(value.unwrap_or("-0"), err, "snippet.thumbnails.standard.height", "integer")); + }, + "player.embed-html" => { + request_player_init(&mut request); + request.player.as_mut().unwrap().embed_html = value.unwrap_or("").to_string(); + }, + "processing-details.file-details-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().file_details_availability = value.unwrap_or("").to_string(); + }, + "processing-details.editor-suggestions-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().editor_suggestions_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-status" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_status = value.unwrap_or("").to_string(); + }, + "processing-details.processing-issues-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_issues_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-failure-reason" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_failure_reason = value.unwrap_or("").to_string(); + }, + "processing-details.thumbnails-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().thumbnails_availability = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.time-left-ms" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.time_left_ms = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.parts-processed" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.parts_processed = value.unwrap_or("").to_string(); + }, + "processing-details.processing-progress.parts-total" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().processing_progress.parts_total = value.unwrap_or("").to_string(); + }, + "processing-details.tag-suggestions-availability" => { + request_processing_details_init(&mut request); + request.processing_details.as_mut().unwrap().tag_suggestions_availability = value.unwrap_or("").to_string(); + }, + "etag" => { + request_processing_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "project-details.tags" => { + request_project_details_init(&mut request); + request.project_details.as_mut().unwrap().tags.push(value.unwrap_or("").to_string()); + }, + "recording-details.recording-date" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().recording_date = value.unwrap_or("").to_string(); + }, + "recording-details.location-description" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location_description = value.unwrap_or("").to_string(); + }, + "recording-details.location.latitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.latitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.latitude", "number"); + }, + "recording-details.location.altitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.altitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.altitude", "number"); + }, + "recording-details.location.longitude" => { + request_recording_details_init(&mut request); + request.recording_details.as_mut().unwrap().location.longitude = arg_from_str(value.unwrap_or("0.0"), err, "recording-details.location.longitude", "number"); + }, + "id" => { + request_recording_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _watermarks_set(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::InvideoBranding = Default::default(); + let mut call = self.hub.watermarks().set(&request, &self.opt.arg_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_position_init(request: &mut api::InvideoBranding) { + if request.position.is_none() { + request.position = Some(Default::default()); + } + } + + fn request_timing_init(request: &mut api::InvideoBranding) { + if request.timing.is_none() { + request.timing = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "target-channel-id" => { + request.target_channel_id = Some(value.unwrap_or("").to_string()); + }, + "position.corner-position" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().corner_position = value.unwrap_or("").to_string(); + }, + "position.type" => { + request_position_init(&mut request); + request.position.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "image-url" => { + request_position_init(&mut request); + request.image_url = Some(value.unwrap_or("").to_string()); + }, + "timing.offset-ms" => { + request_timing_init(&mut request); + request.timing.as_mut().unwrap().offset_ms = value.unwrap_or("").to_string(); + }, + "timing.type" => { + request_timing_init(&mut request); + request.timing.as_mut().unwrap().type_ = value.unwrap_or("").to_string(); + }, + "timing.duration-ms" => { + request_timing_init(&mut request); + request.timing.as_mut().unwrap().duration_ms = value.unwrap_or("").to_string(); + }, + "image-bytes" => { + request_timing_init(&mut request); + request.image_bytes = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = + if self.opt.cmd_simple { + "simple" + } else if self.opt.cmd_resumable { + "resumable" + } else { + unreachable!() + }; + let mut input_file = input_file_from_opts(&self.opt.arg_file, err); + let mime_type = input_mime_from_opts(&self.opt.arg_mime, err); + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "simple" => call.upload(input_file.unwrap(), mime_type.unwrap()), + "resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _watermarks_unset(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.watermarks().unset(&self.opt.arg_channel_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_activities { + if self.opt.cmd_insert { + call_result = self._activities_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._activities_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_captions { + if self.opt.cmd_delete { + call_result = self._captions_delete(dry_run, &mut err); + } else if self.opt.cmd_download { + call_result = self._captions_download(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._captions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._captions_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._captions_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channel_banners { + if self.opt.cmd_insert { + call_result = self._channel_banners_insert(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channel_sections { + if self.opt.cmd_delete { + call_result = self._channel_sections_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._channel_sections_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._channel_sections_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._channel_sections_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_channels { + if self.opt.cmd_list { + call_result = self._channels_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._channels_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_guide_categories { + if self.opt.cmd_list { + call_result = self._guide_categories_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_i18n_languages { + if self.opt.cmd_list { + call_result = self._i18n_languages_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_i18n_regions { + if self.opt.cmd_list { + call_result = self._i18n_regions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_live_broadcasts { + if self.opt.cmd_bind { + call_result = self._live_broadcasts_bind(dry_run, &mut err); + } else if self.opt.cmd_control { + call_result = self._live_broadcasts_control(dry_run, &mut err); + } else if self.opt.cmd_delete { + call_result = self._live_broadcasts_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._live_broadcasts_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._live_broadcasts_list(dry_run, &mut err); + } else if self.opt.cmd_transition { + call_result = self._live_broadcasts_transition(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._live_broadcasts_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_live_streams { + if self.opt.cmd_delete { + call_result = self._live_streams_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._live_streams_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._live_streams_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._live_streams_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_playlist_items { + if self.opt.cmd_delete { + call_result = self._playlist_items_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._playlist_items_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._playlist_items_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._playlist_items_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_playlists { + if self.opt.cmd_delete { + call_result = self._playlists_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._playlists_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._playlists_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._playlists_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_search { + if self.opt.cmd_list { + call_result = self._search_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_subscriptions { + if self.opt.cmd_delete { + call_result = self._subscriptions_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._subscriptions_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._subscriptions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_thumbnails { + if self.opt.cmd_set { + call_result = self._thumbnails_set(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_video_categories { + if self.opt.cmd_list { + call_result = self._video_categories_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_videos { + if self.opt.cmd_delete { + call_result = self._videos_delete(dry_run, &mut err); + } else if self.opt.cmd_get_rating { + call_result = self._videos_get_rating(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._videos_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._videos_list(dry_run, &mut err); + } else if self.opt.cmd_rate { + call_result = self._videos_rate(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._videos_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_watermarks { + if self.opt.cmd_set { + call_result = self._watermarks_set(dry_run, &mut err); + } else if self.opt.cmd_unset { + call_result = self._watermarks_unset(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "youtube3-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "youtube3", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::YouTube::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + fn main() { - let _: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); - println!("Hello, youtube:v3 !"); + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } } \ No newline at end of file diff --git a/gen/youtubeanalytics1-cli/Cargo.toml b/gen/youtubeanalytics1-cli/Cargo.toml new file mode 100644 index 00000000000..a4315236266 --- /dev/null +++ b/gen/youtubeanalytics1-cli/Cargo.toml @@ -0,0 +1,30 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-youtubeanalytics1-cli" +version = "0.0.1+20150304" +authors = ["Sebastian Thiel <byronimo@gmail>"] +description = "A complete library to interact with YouTube Analytics (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/youtubeanalytics1-cli" +homepage = "http://developers.google.com/youtube/analytics/" +documentation = "http://byron.github.io/google-apis-rs/google_youtubeanalytics1_cli" +license = "MIT" +keywords = ["youtubeAnalytics", "google", "cli"] + +[[bin]] +name = "youtubeanalytics1" + +[dependencies] +hyper = "*" +mime = "*" +yup-oauth2 = "*" +docopt = "= 0.6.59" +docopt_macros = "= 0.6.59" +rustc-serialize = "*" +serde = ">= 0.3.0" +serde_macros = "*" + +[dependencies.google-youtubeanalytics1] +path = "../youtubeanalytics1" diff --git a/gen/youtubeanalytics1-cli/LICENSE.md b/gen/youtubeanalytics1-cli/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/youtubeanalytics1-cli/LICENSE.md @@ -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. diff --git a/gen/youtubeanalytics1-cli/README.md b/gen/youtubeanalytics1-cli/README.md new file mode 100644 index 00000000000..8ea2b9f5cc9 --- /dev/null +++ b/gen/youtubeanalytics1-cli/README.md @@ -0,0 +1,4 @@ +# HELLO YOUTUBEANALYTICS:V1 + + +Include information about application secret files, and how we automatically write a default one. \ No newline at end of file diff --git a/gen/youtubeanalytics1-cli/mkdocs.yml b/gen/youtubeanalytics1-cli/mkdocs.yml new file mode 100644 index 00000000000..420207a5ab1 --- /dev/null +++ b/gen/youtubeanalytics1-cli/mkdocs.yml @@ -0,0 +1,26 @@ +site_name: YouTube Analytics v0.0.1+20150304 +site_url: http://byron.github.io/google-apis-rs/google-youtubeanalytics1-cli +site_description: Write integrating applications with bcore + +repo_url: https://github.com/Byron/google-apis-rs/tree/master/gen/youtubeanalytics1-cli + +docs_dir: docs +site_dir: build_html + +pages: +- ['index.md', 'Home'] +- ['batch-report-definitions_list.md', 'Batch Report Definitions', 'List'] +- ['batch-reports_list.md', 'Batch Reports', 'List'] +- ['group-items_delete.md', 'Group Items', 'Delete'] +- ['group-items_insert.md', 'Group Items', 'Insert'] +- ['group-items_list.md', 'Group Items', 'List'] +- ['groups_delete.md', 'Groups', 'Delete'] +- ['groups_insert.md', 'Groups', 'Insert'] +- ['groups_list.md', 'Groups', 'List'] +- ['groups_update.md', 'Groups', 'Update'] +- ['reports_query.md', 'Reports', 'Query'] + +theme: readthedocs + +copyright: Copyright © 2015, `Sebastian Thiel` + diff --git a/gen/youtubeanalytics1-cli/src/cmn.rs b/gen/youtubeanalytics1-cli/src/cmn.rs new file mode 100644 index 00000000000..fd8d66fa4c3 --- /dev/null +++ b/gen/youtubeanalytics1-cli/src/cmn.rs @@ -0,0 +1,439 @@ +// 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) + -> (&'a str, Option<&'a str>) { + let mut add_err = || err.issues.push(CLIError::InvalidKeyValueSyntax(kv.to_string())); + match kv.rfind('=') { + 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 { + // NOTE: logging might be interesting, currently we swallow all errors + fn set(&mut self, scope_hash: u64, token: Option<Token>) { + let json_token = json::encode(&token).unwrap(); + let res = fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)); + if let Ok(mut f) = res { + f.write(json_token.as_bytes()).ok(); + } + } + + fn get(&self, scope_hash: u64) -> Option<Token> { + if let Ok(mut f) = fs::File::open(&self.path(scope_hash)) { + let mut json_string = String::new(); + if let Ok(_) = f.read_to_string(&mut json_string) { + if let Ok(token) = json::decode::<Token>(&json_string) { + return Some(token) + } + } + } + None + } +} + + +#[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), + 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) + => writeln!(f, "'{}' does not match pattern <key>=<value>", kv), + + } + } +} + +#[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) -> 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 + let secret = ApplicationSecret { + client_id: "14070749909-vgip2f1okm7bkvajhi9jugan6126io9v.apps.googleusercontent.com".to_string(), + client_secret: "UqkDJd5RFwnHoiG5x5Rub8SI".to_string(), + token_uri: "https://accounts.google.com/o/oauth2/token".to_string(), + auth_uri: Default::default(), + redirect_uris: Default::default(), + client_email: None, + auth_provider_x509_cert_url: None, + client_x509_cert_url: Some("https://www.googleapis.com/oauth2/v1/certs".to_string()) + }; + + let app_secret = ConsoleApplicationSecret { + installed: Some(secret), + web: None, + }; + + let json_enocded_secret = json::encode(&app_secret).unwrap(); + err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) { + Err(cfe) => cfe, + Ok(mut f) => { + match f.write(json_enocded_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!(); +} \ No newline at end of file diff --git a/gen/youtubeanalytics1-cli/src/main.rs b/gen/youtubeanalytics1-cli/src/main.rs new file mode 100644 index 00000000000..e4ef6914dfc --- /dev/null +++ b/gen/youtubeanalytics1-cli/src/main.rs @@ -0,0 +1,800 @@ +// 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 rustc_serialize; +extern crate serde; +extern crate hyper; +extern crate mime; +extern crate google_youtubeanalytics1 as api; + +use std::env; +use std::io::{self, Write}; + +docopt!(Options derive Debug, " +Usage: + youtubeanalytics1 [options] batch-report-definitions list <on-behalf-of-content-owner> [-p <v>]... [-o <out>] + youtubeanalytics1 [options] batch-reports list <batch-report-definition-id> <on-behalf-of-content-owner> [-p <v>]... [-o <out>] + youtubeanalytics1 [options] group-items delete <id> [-p <v>]... + youtubeanalytics1 [options] group-items insert -r <kv>... [-p <v>]... [-o <out>] + youtubeanalytics1 [options] group-items list <group-id> [-p <v>]... [-o <out>] + youtubeanalytics1 [options] groups delete <id> [-p <v>]... + youtubeanalytics1 [options] groups insert -r <kv>... [-p <v>]... [-o <out>] + youtubeanalytics1 [options] groups list [-p <v>]... [-o <out>] + youtubeanalytics1 [options] groups update -r <kv>... [-p <v>]... [-o <out>] + youtubeanalytics1 [options] reports query <ids> <start-date> <end-date> <metrics> [-p <v>]... [-o <out>] + youtubeanalytics1 --help + +All documentation details can be found TODO: <URL to github.io docs here, see #51> + +Configuration: + --scope <url> + Specify the authentication a method should be executed in. Each scope requires + the user to grant this application permission to use it. + If unset, it defaults to the shortest scope url for a particular method. + --config-dir <folder> + 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] +"); + +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::YouTubeAnalytics<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>, +} + + +impl Engine { + fn _batch_report_definitions_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.batch_report_definitions().list(&self.opt.arg_on_behalf_of_content_owner); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _batch_reports_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.batch_reports().list(&self.opt.arg_batch_report_definition_id, &self.opt.arg_on_behalf_of_content_owner); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _group_items_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.group_items().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _group_items_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::GroupItem = Default::default(); + let mut call = self.hub.group_items().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_resource_init(request: &mut api::GroupItem) { + if request.resource.is_none() { + request.resource = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "kind" => { + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request.etag = Some(value.unwrap_or("").to_string()); + }, + "resource.kind" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().kind = value.unwrap_or("").to_string(); + }, + "resource.id" => { + request_resource_init(&mut request); + request.resource.as_mut().unwrap().id = value.unwrap_or("").to_string(); + }, + "group-id" => { + request_resource_init(&mut request); + request.group_id = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_resource_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _group_items_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.group_items().list(&self.opt.arg_group_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_delete(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.groups().delete(&self.opt.arg_id); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok(mut response) => { + println!("DEBUG: REMOVE ME {:?}", response); + None + } + } + } + } + + fn _groups_insert(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Group = Default::default(); + let mut call = self.hub.groups().insert(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Group) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Group) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "content-details.item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.item-count", "int64"); + }, + "content-details.item-type" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_type = value.unwrap_or("").to_string(); + }, + "kind" => { + request_content_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_content_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_list(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.groups().list(); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "mine" => { + call = call.mine(arg_from_str(value.unwrap_or("false"), err, "mine", "boolean")); + }, + "id" => { + call = call.id(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _groups_update(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut request: api::Group = Default::default(); + let mut call = self.hub.groups().update(&request); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "on-behalf-of-content-owner" => { + call = call.on_behalf_of_content_owner(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let mut field_name: FieldCursor = Default::default(); + for kvarg in self.opt.arg_kv.iter() { + let (key, value) = parse_kv_arg(&*kvarg, err); + if let Err(field_err) = field_name.set(&*key) { + err.issues.push(field_err); + } + fn request_content_details_init(request: &mut api::Group) { + if request.content_details.is_none() { + request.content_details = Some(Default::default()); + } + } + + fn request_snippet_init(request: &mut api::Group) { + if request.snippet.is_none() { + request.snippet = Some(Default::default()); + } + } + + match &field_name.to_string()[..] { + "snippet.published-at" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().published_at = value.unwrap_or("").to_string(); + }, + "snippet.title" => { + request_snippet_init(&mut request); + request.snippet.as_mut().unwrap().title = value.unwrap_or("").to_string(); + }, + "content-details.item-count" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_count = arg_from_str(value.unwrap_or("-0"), err, "content-details.item-count", "int64"); + }, + "content-details.item-type" => { + request_content_details_init(&mut request); + request.content_details.as_mut().unwrap().item_type = value.unwrap_or("").to_string(); + }, + "kind" => { + request_content_details_init(&mut request); + request.kind = Some(value.unwrap_or("").to_string()); + }, + "etag" => { + request_content_details_init(&mut request); + request.etag = Some(value.unwrap_or("").to_string()); + }, + "id" => { + request_content_details_init(&mut request); + request.id = Some(value.unwrap_or("").to_string()); + }, + _ => { + err.issues.push(CLIError::Field(FieldError::Unknown(field_name.to_string()))); + } + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _reports_query(&self, dry_run: bool, err: &mut InvalidOptionsError) + -> Option<api::Error> { + let mut call = self.hub.reports().query(&self.opt.arg_ids, &self.opt.arg_start_date, &self.opt.arg_end_date, &self.opt.arg_metrics); + for parg in self.opt.arg_v.iter() { + let (key, value) = parse_kv_arg(&*parg, err); + match key { + "start-index" => { + call = call.start_index(arg_from_str(value.unwrap_or("-0"), err, "start-index", "integer")); + }, + "sort" => { + call = call.sort(value.unwrap_or("")); + }, + "max-results" => { + call = call.max_results(arg_from_str(value.unwrap_or("-0"), err, "max-results", "integer")); + }, + "filters" => { + call = call.filters(value.unwrap_or("")); + }, + "dimensions" => { + call = call.dimensions(value.unwrap_or("")); + }, + "currency" => { + call = call.currency(value.unwrap_or("")); + }, + "alt" + |"fields" + |"key" + |"oauth-token" + |"pretty-print" + |"quota-user" + |"user-ip" => { + let map = [ + ("oauth-token", "oauth_token"), + ("pretty-print", "prettyPrint"), + ("quota-user", "quotaUser"), + ("user-ip", "userIp"), + ]; + call = call.param(map.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset")) + }, + _ => err.issues.push(CLIError::UnknownParameter(key.to_string())), + } + } + let protocol = "standard-request"; + if dry_run { + None + } else { + assert!(err.issues.len() == 0); + let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out); + match match protocol { + "standard-request" => call.doit(), + _ => unreachable!(), + } { + Err(api_err) => Some(api_err), + Ok((mut response, output_schema)) => { + println!("DEBUG: REMOVE ME {:?}", response); + serde::json::to_writer(&mut ostream, &output_schema).unwrap(); + None + } + } + } + } + + fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) { + let mut err = InvalidOptionsError::new(); + let mut call_result: Option<api::Error>; + let mut err_opt: Option<InvalidOptionsError> = None; + + if self.opt.cmd_batch_report_definitions { + if self.opt.cmd_list { + call_result = self._batch_report_definitions_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_batch_reports { + if self.opt.cmd_list { + call_result = self._batch_reports_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_group_items { + if self.opt.cmd_delete { + call_result = self._group_items_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._group_items_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._group_items_list(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_groups { + if self.opt.cmd_delete { + call_result = self._groups_delete(dry_run, &mut err); + } else if self.opt.cmd_insert { + call_result = self._groups_insert(dry_run, &mut err); + } else if self.opt.cmd_list { + call_result = self._groups_list(dry_run, &mut err); + } else if self.opt.cmd_update { + call_result = self._groups_update(dry_run, &mut err); + } else { + unreachable!(); + } + } else if self.opt.cmd_reports { + if self.opt.cmd_query { + call_result = self._reports_query(dry_run, &mut err); + } else { + unreachable!(); + } + } 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<Engine, InvalidOptionsError> { + 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, "youtubeanalytics1-secret.json") { + Ok(secret) => (config_dir, secret), + Err(e) => return Err(InvalidOptionsError::single(e, 4)) + } + }; + + let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, + hyper::Client::new(), + JsonTokenStorage { + program_name: "youtubeanalytics1", + db_dir: config_dir.clone(), + }, None); + let engine = Engine { + opt: opt, + hub: api::YouTubeAnalytics::new(hyper::Client::new(), 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<api::Error> { + self._doit(false).0 + } +} + +fn main() { + let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); + match Engine::new(opts) { + Err(err) => { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(err.exit_code); + }, + Ok(engine) => { + if let Some(err) = engine.doit() { + write!(io::stderr(), "{}", err).ok(); + env::set_exit_status(1); + } + } + } +} \ No newline at end of file