ap_command 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ap_command.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 sugamasao
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # ApCommand
2
+
3
+ JSON file to awesome print for command line tool.
4
+
5
+ dependency [awesome_print](https://github.com/michaeldv/awesome_print)
6
+
7
+ ※標準出力周りのテストが書けないのでだれか助けて
8
+
9
+ ## Installation
10
+
11
+ install it yourself as:
12
+
13
+ $ gem install ap_command
14
+
15
+ ## Usage
16
+
17
+ using `ap` command.
18
+
19
+ % ap /tmp/hoge.json
20
+ {
21
+ "hoge" => [
22
+ [0] 1,
23
+ [1] 2,
24
+ [2] 3,
25
+ [3] "fuga"
26
+ ]
27
+ }
28
+
29
+
30
+ ## Copyright
31
+ MIT License.
32
+
33
+ See LICENSE.txt file for details.
34
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ap_command/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ap_command"
8
+ gem.version = ApCommand::VERSION
9
+ gem.authors = ["sugamasao"]
10
+ gem.email = ["sugamasao@gmail.com"]
11
+ gem.description = %q{JSON file to awesome print for command line tool.}
12
+ gem.summary = %q{JSON file to awesome print for command line tool.}
13
+ gem.homepage = "https://github.com/sugamasao/ap_command"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('awesome_print')
21
+ gem.add_development_dependency('rspec')
22
+ end
data/bin/ap ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'ap_command')
4
+
5
+ ApCommand::Application.invoke(ARGV)
data/lib/ap_command.rb ADDED
@@ -0,0 +1,48 @@
1
+ # encoding:utf-8
2
+
3
+ require 'json'
4
+
5
+ require 'awesome_print'
6
+ require_relative "ap_command/version"
7
+
8
+ module ApCommand
9
+ class Application
10
+ def run(argv)
11
+ path = argv.first.to_s
12
+ version if(path == '--version' or path == '-v')
13
+ usage if(path == '--help' or path == '-h')
14
+ usage unless(File.exists?(path))
15
+
16
+ begin
17
+ awesome(JSON.parse(File.read(path)))
18
+ rescue JSON::ParserError => e
19
+ puts "Error: #{e.class} message => #{e.message}"
20
+ puts
21
+ usage
22
+ end
23
+
24
+ end
25
+
26
+ def awesome(data)
27
+ ap(data, indent: 2)
28
+ end
29
+
30
+ def usage
31
+ puts "usage:"
32
+ puts "%#{File.basename($0)} /path/to/jsonfile"
33
+ puts "json file awsome print for command line tool."
34
+ exit
35
+ end
36
+
37
+ def version
38
+ puts "#{File.basename($0)} #{VERSION}"
39
+ exit
40
+ end
41
+
42
+
43
+ def self.invoke(argv)
44
+ self.new.run(argv)
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,3 @@
1
+ module ApCommand
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,74 @@
1
+ # encoding:utf-8
2
+ require 'spec_helper'
3
+ require 'tempfile'
4
+
5
+ module ApCommand
6
+ describe Application do
7
+ context 'jsonファイルを受け取る' do
8
+ describe '.invoke' do
9
+ before do
10
+ @file = Tempfile.new('ap')
11
+ @file.puts({hoge:[1, 2, '3']}.to_json)
12
+ @file.close
13
+ end
14
+
15
+ it { expect {Application.invoke([@file.path])}.to_not raise_error }
16
+
17
+ after do
18
+ @file.unlink
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'jsonファイルが壊れている' do
24
+ describe '.invoke' do
25
+ before do
26
+ @file = Tempfile.new('ap')
27
+ @file.puts '{"hoge":[}'
28
+ @file.close
29
+ end
30
+
31
+ it { expect {Application.invoke([@file.path])}.to raise_error(SystemExit) }
32
+
33
+ after do
34
+ @file.unlink
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'ファイルが存在しない' do
40
+ describe '.invoke' do
41
+ specify 'ヘルプが出力される' do
42
+ expect { Application.invoke(['/tmp/hoge/fuga/awesome']) }.to raise_error(SystemExit)
43
+ end
44
+ end
45
+ end
46
+
47
+ context '引数を省略された' do
48
+ describe '.invoke' do
49
+ specify 'ヘルプが出力される' do
50
+ expect { Application.invoke([]) }.to raise_error(SystemExit)
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'ヘルプコマンドを入力された' do
56
+ describe '.invoke' do
57
+ specify 'ヘルプが出力される' do
58
+ expect { Application.invoke(['--help']) }.to raise_error(SystemExit)
59
+ expect { Application.invoke(['-h']) }.to raise_error(SystemExit)
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'versionを入力された' do
65
+ describe '.invoke' do
66
+ specify 'versionが出力される' do
67
+ expect { Application.invoke(['--version']) }.to raise_error(SystemExit)
68
+ expect { Application.invoke(['-v']) }.to raise_error(SystemExit)
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ require 'ap_command'
4
+
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ap_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sugamasao
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: awesome_print
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: JSON file to awesome print for command line tool.
47
+ email:
48
+ - sugamasao@gmail.com
49
+ executables:
50
+ - ap
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - ap_command.gemspec
60
+ - bin/ap
61
+ - lib/ap_command.rb
62
+ - lib/ap_command/version.rb
63
+ - spec/ap_command_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/sugamasao/ap_command
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: JSON file to awesome print for command line tool.
89
+ test_files:
90
+ - spec/ap_command_spec.rb
91
+ - spec/spec_helper.rb
92
+ has_rdoc: