ppcommand
Parse and pp YAML/JSON/XML/CSV/HTML.
Usage
$ pp --help
pp [options] [file|URI]
-c, --csv parse CSV and pp.
-C, --csvtable parse CSV, add labels and pp.
-H, --html parse HTML and pp.
-j, --json parse JSON and pp.
-x, --xml parse XML using REXML and pp.
-X, --xmlsimple parse XML using XMLSimple and pp.
-y, --yaml parse YAML and pp.
-t, --text do not parse. print plain text.
-h, --help show this help.
-v, --version show version.
Examples
Parse YAML and pp.
$ pp ./config/database.yml
{"development"=>
{"encoding"=>"utf8",
"username"=>"root",
"adapter"=>"mysql",
"host"=>"localhost",
"password"=>nil,
"database"=>"appname_test",
"pool"=>5},
:
Parse JSON and pp.
$ pp http://api.twitter.com/1/statuses/public_timeline.json
[{"user"=>
{"name"=>"septiasabatina",
"profile_sidebar_fill_color"=>"FFFFFF",
"profile_sidebar_border_color"=>"FFFFFF",
"profile_background_tile"=>true,
"profile_link_color"=>"000000",
"url"=>"http://example.com",
"contributors_enabled"=>false,
"favourites_count"=>0,
"id"=>123456789,
"description"=>"",
"utc_offset"=>0,
"lang"=>"en",
:
Parse HTML and pp (required nokogiri).
$ pp http://www.google.com/
#(Document:0x96c0ee {
name = "document",
children = [
#(DTD:0x96bb9e { name = "html" }),
#(Element:0x96b5cc {
name = "html",
children = [
#(Element:0x96adb6 {
name = "head",
:
Get URL contents as text, skip 3 lines, convert encoding to UTF-8, parse CSV and pp with labels. When using –csvtable(-C), the first line treated as label.
$ pp -t http://example.com/items.csv | head -n +3 | nkf -w | pp -C
[[[0, "name", "apple"],
[1, "price", "100"],
[2, "amount", "99"],
[3, "label1", "aaa"],
[4, "label2", "bbb"],
[5, "label3", "ccc"]],
[[0, "name", "orange"],
[1, "price", "123"],
[2, "amount", "10"],
[3, "label1", "xxx"],
[4, "label2", "yyy"],
[5, "label3", "zzz"]]]
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 KOSEKI Kengo. See LICENSE for details.