ログってなんぼ

日々のメモです

TreasureData:tdコマンド使うなら補完機能も入れとこか

treasure-data/td はてなブックマーク - treasure-data/td

コマンドラインからTreasureDataを操作するtdコマンドには、コマンド(のオプション)を補完するための便利なcompletationファイルが用意されてます。

用意されてます( ー`дー´)キリッ とドヤ顔で書いてしまいましたが、たまたまtdコマンドのソース確認してたついでに偶然見つけただけなんすけど・・・

素の状態でもusageが割と充実していて、どんな感じでコマンドを打てばいいかわかりやすいので必須ではないと思いますが、オプションの頭文字を入力してTABキーを押すことで補完が働くようになるので入れておくのもいいと思います。まあtdはオプションがシンプルなので要らない人は要らないですね。この記事書いといてアレですけど僕も今のオプション数レベルなら別に要らないと結局思いました。まあ今後機能豊富になってくると必要性も増すかなと。

.bash_profileなどに追加

source /usr/local/lib/ruby/gems/2.0.0/gems/td-0.10.89/contrib/completion/td-comletion.bash

td

$ td
apikey:set                 bulk_import:perform        import:auto                import:show                result:delete              schema:add                 table:import
apikey:show                bulk_import:prepare_parts  import:commit              import:unfreeze            result:list                schema:remove              table:list
bulk_import:commit         bulk_import:show           import:create              import:upload              result:show                schema:set                 table:partial_delete
bulk_import:create         bulk_import:unfreeze       import:delete              job:kill                   sample:apache              schema:show                table:show
bulk_import:delete         bulk_import:upload_part    import:error_records       job:list                   sched:create               server:status              table:swap
bulk_import:delete_part    bulk_import:upload_parts   import:freeze              job:show                   sched:delete               status                     table:tail
bulk_import:delete_parts   db:create                  import:java_version        job:status                 sched:history              table:create
bulk_import:error_records  db:delete                  import:list                password:change            sched:list                 table:delete
bulk_import:freeze         db:list                    import:perform             query                      sched:run                  table:expire
bulk_import:list           db:show                    import:prepare             result:create              sched:update               table:export

td s

$ td s
sample:apache  sched:create   sched:delete   sched:history  sched:list     sched:run      sched:update   schema:add     schema:remove  schema:set     schema:show    server:status  status

td sche

$ td sche
sched:create   sched:delete   sched:history  sched:list     sched:run      sched:update   schema:add     schema:remove  schema:set     schema:show

td job

$ td job
job:kill    job:list    job:show    job:status

td job:li まで入力してを押せば td job:list と補完されます。

ちなみに1

completeを入れておくと便利になるツールの一つにawscliがありますが、awscliの場合は入れとくと便利になるというレベルじゃなくコレがないと使う気にならないレベルです。

$ aws
autoscaling         cloudsearch         directconnect       elasticache         elb                 importexport        redshift            s3api               sqs                 support
cloudformation      cloudwatch          dynamodb            elasticbeanstalk    emr                 opsworks            route53             ses                 storagegateway      swf
cloudfront          datapipeline        ec2                 elastictranscoder   iam                 rds                 s3
sns                 sts

第1オプションだけでこんなに・・・

ec2まで入れて第2オプション見てみると

$ aws ec2
Display all 147 possibilities? (y or n)
activate-license                        create-placement-group                  delete-volume                           describe-route-tables                   modify-network-interface-attribute
allocate-address                        create-reserved-instances-listing       delete-vpc                              describe-security-groups                modify-snapshot-attribute
assign-private-ip-addresses             create-route                            delete-vpn-connection                   describe-snapshot-attribute             modify-volume-attribute
associate-address                       create-route-table                      delete-vpn-connection-route             describe-snapshots                      modify-vpc-attribute
associate-dhcp-options                  create-security-group                   delete-vpn-gateway                      describe-spot-datafeed-subscription     monitor-instances
associate-route-table                   create-snapshot                         deregister-image                        describe-spot-instance-requests         purchase-reserved-instances-offering
attach-internet-gateway                 create-spot-datafeed-subscription       describe-account-attributes             describe-spot-price-history             reboot-instances
attach-network-interface                create-subnet                           describe-addresses                      describe-subnets                        register-image
attach-volume                           create-tags                             describe-availability-zones             describe-tags                           release-address
attach-vpn-gateway                      create-volume                           describe-bundle-tasks                   describe-volume-attribute               replace-network-acl-association
authorize-security-group-egress         create-vpc                              describe-conversion-tasks               describe-volume-status                  replace-network-acl-entry
authorize-security-group-ingress        create-vpn-connection                   describe-customer-gateways              describe-volumes                        replace-route
bundle-instance                         create-vpn-connection-route             describe-dhcp-options                   describe-vpc-attribute                  replace-route-table-association
cancel-bundle-task                      create-vpn-gateway                      describe-export-tasks                   describe-vpcs                           report-instance-status
cancel-conversion-task                  deactivate-license                      describe-image-attribute                describe-vpn-connections                request-spot-instances
cancel-export-task                      delete-customer-gateway                 describe-images                         describe-vpn-gateways                   reset-image-attribute
cancel-reserved-instances-listing       delete-dhcp-options                     describe-instance-attribute             detach-internet-gateway                 reset-instance-attribute
cancel-spot-instance-requests           delete-internet-gateway                 describe-instance-status                detach-network-interface                reset-network-interface-attribute
confirm-product-instance                delete-key-pair                         describe-instances                      detach-volume                           reset-snapshot-attribute
copy-image                              delete-network-acl                      describe-internet-gateways              detach-vpn-gateway                      revoke-security-group-egress
copy-snapshot                           delete-network-acl-entry                describe-key-pairs                      disable-vgw-route-propagation           revoke-security-group-ingress
create-customer-gateway                 delete-network-interface                describe-licenses                       disassociate-address                    run-instances
create-dhcp-options                     delete-placement-group                  describe-network-acls                   disassociate-route-table                start-instances
create-image                            delete-route                            describe-network-interface-attribute    enable-vgw-route-propagation            stop-instances
create-instance-export-task             delete-route-table                      describe-network-interfaces             enable-volume-io                        terminate-instances
create-internet-gateway                 delete-security-group                   describe-placement-groups               get-console-output                      unassign-private-ip-addresses
create-key-pair                         delete-snapshot                         describe-regions                        get-password-data                       unmonitor-instances
create-network-acl                      delete-spot-datafeed-subscription       describe-reserved-instances             import-key-pair
create-network-acl-entry                delete-subnet                           describe-reserved-instances-listings    modify-image-attribute
create-network-interface                delete-tags                             describe-reserved-instances-offerings   modify-instance-attribute

すごい量です・・・

ちなみに2

tdコマンドのusageは、必要にして十分な情報が見やすく書かれているのでわかりやすいです。

$ td sched:create
usage:
  $ td sched:create   [sql]

example:
  $ td sched:create sched1 "0 * * * *" -d example_db "select count(*) from table1" -r rset1
  $ td sched:create sched1 "0 * * * *" -d example_db -q query.txt -r rset2

description:
  Create a schedule

options:
  -g, --org ORGANIZATION           create the schedule under this organization
  -d, --database DB_NAME           use the database (required)
  -t, --timezone TZ                name of the timezone (like Asia/Tokyo)
  -D, --delay SECONDS              delay time of the schedule
  -r, --result RESULT_URL          write result to the URL (see also result:create subcommand)
  -u, --user NAME                  set user name for the result URL
  -p, --password                   ask password for the result URL
  -P, --priority PRIORITY          set priority
  -q, --query PATH                 use file instead of inline query
  -R, --retry COUNT                automatic retrying count
  -T, --type TYPE                  set query type (hive or pig)