pomegranate-cli 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77d5ddd1df776e10e8495a6869b55c24858af4a3
4
+ data.tar.gz: ba21b85f544d95368f6d65d2b8a630cb06791f39
5
+ SHA512:
6
+ metadata.gz: 66737f46c046b8da4ecd19105229b385d5ee769c0f568d026a0c7596ce107f836df13444bfa9c0fd3a3b399a2c74871dc32acb5e79d71c9541184093cb6ac55d
7
+ data.tar.gz: d803a38cb3689810a210e86d208b748facf51fa43df58c33e444bc62dcc6bd43ef6989825f16795d56601c1b034e2c54f2f0dd0b2a4ef72c8f7e15fc349844de
data/.DS_Store ADDED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pomegranate-cli.gemspec
4
+ gemspec
5
+
6
+ gem 'commander'
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pomegranate-cli (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ commander (4.2.1)
10
+ highline (~> 1.6.11)
11
+ highline (1.6.21)
12
+ rake (10.3.2)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.7)
19
+ commander
20
+ pomegranate-cli!
21
+ rake (~> 10.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 jpatel531
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,31 @@
1
+ # Pomegranate::Cli
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pomegranate-cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pomegranate-cli
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/pomegranate-cli/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/pomegranate ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'pomegranate/cli'
6
+
7
+ program :version, '0.0.1'
8
+ program :description, 'A tool for creating a json file to represent your tutorials'
9
+
10
+ command :init do |c|
11
+ c.syntax = 'pomegranate init, [options]'
12
+ c.summary = 'Pomegranate initializer'
13
+ c.description = 'Create tutorial steps from commits and give your user instructions'
14
+ c.example 'description', 'command example'
15
+ c.option '--some-switch', 'Some switch that does something'
16
+ c.action do |args, options|
17
+ Pomegranate::Cli::Executor.new_file
18
+ end
19
+ end
20
+
21
+ command :edit do |c|
22
+ c.syntax = 'pomegranate edit [options]'
23
+ c.summary = 'Update your pomegranate file'
24
+ c.description = 'Edit your tutorial steps'
25
+ c.example 'description', 'command example'
26
+ c.option '--some-switch', 'Some switch that does something'
27
+ c.action do |args, options|
28
+ Pomegranate::Cli::Executor.edit_file
29
+ end
30
+ end
31
+
@@ -0,0 +1,138 @@
1
+ require "pomegranate/cli/version"
2
+ require 'io/console'
3
+ require 'colorize'
4
+ require 'json'
5
+ require_relative 'read_character'
6
+
7
+ module Pomegranate
8
+ module Cli
9
+ class Executor
10
+
11
+ extend Pomegranate::Cli::ReadCharacter
12
+
13
+ def self.commits
14
+ log = `git log --pretty=oneline`
15
+ log.split("\n").reverse
16
+ end
17
+
18
+ def self.get_source_and_spec
19
+ puts "Name of source file:"
20
+ source = STDIN.gets.chomp
21
+
22
+ puts "Name of test file:"
23
+ spec = STDIN.gets.chomp
24
+ return [source, spec]
25
+ end
26
+
27
+
28
+ def self.new_file result = [], selection = 0, array = self.commits
29
+ source, spec = self.get_source_and_spec
30
+
31
+
32
+
33
+ loop do
34
+ puts "\033c"
35
+ puts "\n Press space to choose a commit and fill in your instructions to the user, or 'q' to exit \n \n"
36
+
37
+ array.map! { |i| i == array[selection] ? i.green : i.black }
38
+ puts array
39
+ c = self.read_char
40
+ case c
41
+ when "\e[A"
42
+ selection -= 1 unless selection == 0
43
+ when "\e[B"
44
+ selection += 1 unless selection == (array.length - 1)
45
+ when " "
46
+ sha = array[selection].uncolorize.split(" ").first
47
+ puts "\n \n Instructions: \n \n"
48
+ instruction = STDIN.gets.chomp
49
+ result << {commit: sha, instruction: instruction, source: source, spec: spec}
50
+ array.delete array[selection]
51
+ when "\r"
52
+ break unless result.empty?
53
+ when 'q'
54
+ exit
55
+ end
56
+ end
57
+
58
+ self.write_to_file result
59
+ end
60
+
61
+ def self.write_to_file hash
62
+ File.open("pomegranate.json", 'w') do |file|
63
+ file.write JSON.pretty_generate hash
64
+ puts "\n \n Your tutorial steps have been written to the file! \n \n"
65
+ end
66
+ end
67
+
68
+
69
+
70
+ def self.edit_file
71
+ file_hash = JSON.parse( IO.read('pomegranate.json') )
72
+ selection = 0
73
+ steps = file_hash.map { |step| [step["commit"], step["instruction"]] }.map {|step| step.join " " }
74
+
75
+ loop do
76
+ puts "\033c"
77
+ puts "\n Press space to choose a commit to edit, or press 'q' to exit \n \n"
78
+ steps = file_hash.map { |step| [step["commit"], step["instruction"]] }.map {|step| step.join " " }
79
+ steps.map! {|step| step == steps[selection] ? step.green : step.black}
80
+ puts steps
81
+ c = self.read_char
82
+ case c
83
+ when "\e[A"
84
+ selection -= 1 unless selection == 0
85
+ when "\e[B"
86
+ selection += 1 unless selection == (steps.length - 1)
87
+ when " "
88
+ puts "Do you want to change your commit? y/n"
89
+ change_commit = STDIN.gets.chomp
90
+ if change_commit == 'y'
91
+ commit_selection = 0
92
+ loop do
93
+ puts "\033c"
94
+ puts "\n Press space to choose a commit or 'q' to exit \n \n"
95
+ array = self.commits
96
+ array.map! { |i| i == array[commit_selection] ? i.green : i.black }
97
+ puts array
98
+ choice = self.read_char
99
+ case choice
100
+ when "\e[A"
101
+ commit_selection -= 1 unless commit_selection == 0
102
+ when "\e[B"
103
+ commit_selection += 1 unless commit_selection == (array.length - 1)
104
+ when " "
105
+ sha = array[commit_selection].uncolorize.split(" ").first
106
+ file_hash[selection]["commit"] = sha
107
+ break
108
+ when 'q'
109
+ break
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ puts "\n Do you wish to change your instructions? y/n"
116
+ change_instructions = STDIN.gets.chomp
117
+ if change_instructions == 'y'
118
+ puts "Your previous instructions:"
119
+ puts file_hash[selection]["instruction"]
120
+ puts "\n"
121
+
122
+ puts "Write your new instructions below:"
123
+ new_instructions = STDIN.gets.chomp
124
+ file_hash[selection]["instruction"] = new_instructions
125
+ end
126
+ when "\r"
127
+ break
128
+ when 'q'
129
+ exit
130
+ end
131
+ end
132
+
133
+ self.write_to_file file_hash
134
+
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,5 @@
1
+ module Pomegranate
2
+ module Cli
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module Pomegranate
2
+ module Cli
3
+ module ReadCharacter
4
+
5
+ def read_char
6
+ begin
7
+ old_state = `stty -g`
8
+ system "stty raw -echo"
9
+ c = STDIN.getc.chr
10
+ if(c=="\e")
11
+ extra_thread = Thread.new{
12
+ c = c + STDIN.getc.chr
13
+ c = c + STDIN.getc.chr
14
+ }
15
+ extra_thread.join(0.00001)
16
+ extra_thread.kill
17
+ end
18
+ rescue => ex
19
+ puts "#{ex.class}: #{ex.message}"
20
+ puts ex.backtrace
21
+ ensure
22
+ system "stty #{old_state}"
23
+ end
24
+ return c
25
+ end
26
+ end
27
+ end
28
+ end
Binary file
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pomegranate/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pomegranate-cli"
8
+ spec.version = Pomegranate::Cli::VERSION
9
+ spec.authors = ["jpatel531"]
10
+ spec.email = ["jamie@notespublication.com"]
11
+ spec.summary = %q{Part of the Pomegranate project}
12
+ spec.description = %q{A command-line interface for creating a pomegranate.json file}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["pomegranate"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pomegranate-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jpatel531
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A command-line interface for creating a pomegranate.json file
42
+ email:
43
+ - jamie@notespublication.com
44
+ executables:
45
+ - pomegranate
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".DS_Store"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/pomegranate
56
+ - lib/pomegranate/cli.rb
57
+ - lib/pomegranate/cli/version.rb
58
+ - lib/pomegranate/read_character.rb
59
+ - pkg/pomegranate-cli-0.0.1.gem
60
+ - pomegranate-cli.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Part of the Pomegranate project
85
+ test_files: []