instructions_list 1.0.2.beta → 1.0.3.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf2c7238c6cb5eb05eb8b12f238a189853af5d7d
4
- data.tar.gz: 748a22a30fae82f2a33e1b6bdb6608867b372e44
3
+ metadata.gz: 01f435854efca5c2ef03dbdf2e55b340ee4a000c
4
+ data.tar.gz: 53c3a4202faedec87e6a7e40ae9f1c036c1edb71
5
5
  SHA512:
6
- metadata.gz: 2d1c31d9725f4424d2e39c544180099d4dbb88c16b52e4b31904a0b92bb2c0f059fa972f1d7ef83c10ad24ef79237231e40c3693e0cb78d7f9ad73b710b0772d
7
- data.tar.gz: 4f96b6f5d50b5cff428579ffc24127b38e4bfbc1f1338b5e68093d48c8ec65361045ca6b5cdf40d2aa0a31f7947af2fd88c9173f20a4f90c05a7e97dac80751f
6
+ metadata.gz: ef66f23557dc6ff795a28fbbb63ec3468f7167b77e20ac986ddab7f9f245d7216f63606c8312f75f89cf0f2dcdcdcfca87f1c618afb7c2a677025d6ae062af42
7
+ data.tar.gz: 7e98d832553bd63cc803651ad38ff8fc7ee7736732184e8afcca40ea2adddfdf6f415e18c669e4197293e75ad24a05fc92bafcaba2ea8a879eecf82dcf9d5f62
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /.idea
@@ -0,0 +1,8 @@
1
+ instruction 'install:redis' do
2
+ instructed?{
3
+ It::Is.done? "install:redis"
4
+ }
5
+ instruct{
6
+ system "echo "install redis""
7
+ }
8
+ end
data/.instructions/key ADDED
@@ -0,0 +1 @@
1
+ ILSIKXHMNCF
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ system
data/exe/il CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
  require "thor"
3
3
  require 'pry'
4
4
  require_relative "../lib/instructions_list/version"
@@ -27,63 +27,83 @@ module InstructionsList
27
27
  end
28
28
  desc "init KEY", "initialize a il directory with list key"
29
29
  def init key
30
- `mkdir -p ./.instructions/`
31
- `mkdir -p instructions`
32
- `touch ./.instructions/key`
33
- `echo #{key} > ./.instructions/key`
30
+ `touch #{KEY_PATH}`
31
+ `echo #{key} > #{KEY_PATH}`
34
32
  connect key
35
33
  end
36
34
  desc "reset", "reset state"
37
35
  def reset name=:all
38
36
  instructable do
39
- `rm ./.instructions/state` if name == :all
40
- `ex +g/#{name}/d -cwq ./.instructions/state`
37
+ `rm #{STATE}` if name == :all
38
+ `ex +g/#{name}/d -cwq #{STATE}`
41
39
  end
42
40
  end
43
41
  desc "sync", "synchronize the instructions"
44
42
  option :reset
45
43
  def sync
46
- `mkdir -p /tmp/il/cache`
47
- Dir.chdir ENV['HOME'] do
44
+ if instructable?
45
+
46
+ puts "is instructable!"
47
+
48
+ `mkdir -p #{PROJECT_CACHE}`
49
+ puts "created the project cache"
50
+ `mkdir -p #{PROJECT_CACHE_ARTIFACTS}`
51
+ puts "created the project cache artifacts"
52
+
48
53
  if options[:reset]
49
- `rm -rf #{CACHE}` if Dir.exists? CACHE
54
+ `rm -rf #{PROJECT_CACHE}` if Dir.exists? PROJECT_CACHE
50
55
  return
51
56
  end
52
57
 
53
58
  instructable do
54
59
  begin
55
- CacheBuilder.new(get_key).build
60
+ CacheBuilder.new(get_key,HOST,cache=PROJECT_CACHE,artifact_cache=PROJECT_CACHE_ARTIFACTS).build
61
+ puts "built cache"
56
62
  rescue SocketError
57
-
58
63
  end
59
64
  end
65
+
66
+ else
67
+ return sync_home_instructions
60
68
  end
61
69
  end
62
70
 
71
+
63
72
  desc "instructions", "list all instructions"
64
73
  def instructions
65
- # puts ""
66
- # list_from "Core","#{File.join(File.dirname(__FILE__), "../instructions/")}" do |path|
67
- # say show_command_for path
68
- # end
69
- puts ""
70
- list_from "Instructions", CACHE << "/" do |path|
71
- say show_command_for path
72
- end
73
- puts ""
74
- # list_from "Home Directory","#{ENV['HOME']}/instructions/" do |path|
75
- # say show_command_for path
76
- # end
77
- #
78
- # puts ""
79
- #
80
- # return if `pwd`.chomp == ENV['HOME']
81
- #
82
- # list_from "Current Project","./instructions/" do |path|
83
- # say show_command_for path
84
- # end
85
- #
86
- # puts ""
74
+
75
+ if home?
76
+
77
+ list_from "Instructions", HOME_CACHE << "/" do |path|
78
+ say show_command_for path
79
+ end
80
+
81
+ return
82
+ end
83
+
84
+ if instructable?
85
+ unless home?
86
+
87
+ list_from "Project", PROJECT_CACHE << "/" do |path|
88
+ say show_command_for path
89
+ end
90
+ puts ""
91
+ list_from "Home Directory", HOME_CACHE << "/" do |path|
92
+ say show_command_for path
93
+ end
94
+
95
+ end
96
+ else
97
+ Dir.chdir (ENV['HOME']) do
98
+ list_from "Instructions", HOME_CACHE << "/" do |path|
99
+ say show_command_for path
100
+ end
101
+ end
102
+ end
103
+
104
+
105
+
106
+
87
107
  end
88
108
 
89
109
  desc "info" , "display information"
@@ -96,7 +116,7 @@ module InstructionsList
96
116
  def connect key
97
117
  instructable do
98
118
  disconnect
99
- `echo #{key} > ./.instructions/key`
119
+ `echo #{key} > #{KEY_PATH}`
100
120
  `il sync`
101
121
  end
102
122
 
@@ -106,7 +126,7 @@ module InstructionsList
106
126
  def disconnect
107
127
  instructable do
108
128
  `il sync --reset`
109
- `rm ./.instructions/key`
129
+ `rm #{KEY_PATH}`
110
130
  end
111
131
  end
112
132
 
@@ -119,7 +139,7 @@ module InstructionsList
119
139
  #load_from "Defaults","#{File.join(File.dirname(__FILE__), "../instructions/")}"
120
140
  #load_from "User","#{ENV['HOME']}/instructions/"
121
141
  #load_from "Project","./instructions/"
122
- load_from "Instructions", CACHE << "/"
142
+ load_from "Instructions", HOME_CACHE << "/"
123
143
  handle_instruction name,STACK,options[:force]
124
144
  end
125
145
  end
@@ -127,25 +147,50 @@ module InstructionsList
127
147
  map list: :instructions
128
148
 
129
149
  no_tasks do
150
+ def sync_home_instructions
151
+ `mkdir -p /tmp/il/cache`
152
+ Dir.chdir ENV['HOME'] do
153
+
154
+ if options[:reset]
155
+ `rm -rf #{HOME_CACHE}` if Dir.exists? HOME_CACHE
156
+ return
157
+ end
158
+
159
+ instructable do
160
+ begin
161
+ CacheBuilder.new(get_key).build
162
+ rescue SocketError
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+
169
+
130
170
  def get_key
131
- return "Not connected!" unless File.exists? KEY_PATH
171
+ return "Not connected!" unless File.exists? KEY_PATH
132
172
  File.read(KEY_PATH).chomp
133
173
  end
134
- def instructable
135
-
136
- return false unless home?
137
174
 
175
+ def instructable?
138
176
  if Dir.exists? "./instructions"
139
177
  if Dir.exists? "./.instructions"
140
178
  if File.exists? "./.instructions/key"
141
- yield
142
- return
179
+ return true
143
180
  end
144
181
  end
145
182
  end
183
+ false
184
+ end
146
185
 
186
+ def instructable
187
+ if instructable?
188
+ yield
189
+ return
190
+ else
191
+ return false unless home?
192
+ end
147
193
  say "Ooops! Not a instruction list directory"
148
-
149
194
  end
150
195
 
151
196
  def home?
@@ -1,3 +1,3 @@
1
1
  module InstructionsList
2
- VERSION = "1.0.2.beta"
2
+ VERSION = "1.0.3.beta"
3
3
  end
@@ -7,8 +7,13 @@ module InstructionsList
7
7
  INSTRUCTIONS=[]
8
8
  STACK=[]
9
9
  CHECKED=[]
10
- CACHE = "/tmp/il/cache"
11
- CACHE_ARTIFACTS="#{CACHE}/artifacts"
10
+
11
+ HOME_CACHE = "/tmp/il/cache"
12
+ HOME_CACHE_ARTIFACTS="#{HOME_CACHE}/artifacts"
13
+
14
+ PROJECT_CACHE = "./.instructions/cache"
15
+ PROJECT_CACHE_ARTIFACTS="#{PROJECT_CACHE}/artifacts"
16
+
12
17
  KEY_PATH="./.instructions/key"
13
18
  HOST= ENV.fetch('INSTRUCTIONS_LIST_HOST',"instructionslist.com")
14
19
  class It
@@ -17,8 +22,8 @@ module InstructionsList
17
22
  end
18
23
  class Is
19
24
  def self.done? name
20
- return false unless File.exists? "./.instructions/state"
21
- File.readlines("./.instructions/state").include? "#{name}\n"
25
+ return false unless File.exists? STATE
26
+ File.readlines(STATE).include? "#{name}\n"
22
27
  end
23
28
  def self.running? name
24
29
  !`ps aux | grep #{name} | grep -v grep`.empty?
@@ -73,8 +78,8 @@ module InstructionsList
73
78
 
74
79
  def done(name)
75
80
  `mkdir -p './.instructions/'`
76
- `touch ./.instructions/state`
77
- `echo #{name} >> ./.instructions/state`
81
+ `touch #{STATE}`
82
+ `echo #{name} >> #{STATE}`
78
83
  check name
79
84
  end
80
85
 
@@ -86,47 +91,53 @@ module InstructionsList
86
91
 
87
92
 
88
93
  class CacheItem
89
- def initialize(file_name)
94
+ def initialize(file_name,cache=HOME_CACHE)
90
95
  @file_name = file_name
96
+ @cache = cache
91
97
  end
92
98
  def write content
93
- File.open("#{CACHE}/#{@file_name}","w") do |file|
99
+ File.open("#{@cache}/#{@file_name}", "w") do |file|
94
100
  file.puts content
95
101
  end
96
102
  end
97
103
  end
98
104
 
99
105
  class CacheArtifactItem
100
- def initialize(file_name)
106
+ def initialize(file_name,cache=HOME_CACHE_ARTIFACTS)
101
107
  @file_name = file_name
108
+ @cache = cache
102
109
  end
103
110
  def write content,directory
104
- `mkdir -p #{CACHE_ARTIFACTS}/#{directory}`
105
- File.open("#{CACHE_ARTIFACTS}/#{directory}/#{@file_name}","w") do |file|
111
+ `mkdir -p #{@cache}/#{directory}`
112
+ File.open("#{@cache}/#{directory}/#{@file_name}", "w") do |file|
106
113
  file.puts content
107
114
  end
108
115
  end
109
116
  end
110
117
 
111
118
  class CacheBuilder
112
- def initialize(key,host=HOST)
119
+ def initialize(key,host=HOST,cache=HOME_CACHE,artifact_cache=HOME_CACHE_ARTIFACTS)
113
120
  @key = key
114
121
  @host = host
122
+ @cache = cache
123
+ @artifact_cache =artifact_cache
115
124
  end
116
125
  def build
117
126
  begin
127
+ puts "http://#{@host}/lists/#{@key}.json"
128
+
118
129
  content = JSON.parse open("http://#{@host}/lists/#{@key}.json").read
119
- `mkdir -p #{CACHE}`
130
+ `mkdir -p #{@cache}`
120
131
  content["instructions"].each do |instruction|
121
132
 
122
133
  CacheItem
123
- .new(instruction["file_name"])
134
+ .new(instruction["file_name"],@cache)
124
135
  .write(instruction["file_contents"])
125
136
 
126
137
  instruction["artifacts"].each do |artifact|
127
138
 
128
139
  CacheArtifactItem
129
- .new(artifact["file_name"])
140
+ .new(artifact["file_name"],cache=@artifact_cache)
130
141
  .write(artifact["contents"],content["key"])
131
142
 
132
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instructions_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2.beta
4
+ version: 1.0.3.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coco Coder (aka Delaney Burke)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-31 00:00:00.000000000 Z
11
+ date: 2017-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,9 @@ extra_rdoc_files: []
119
119
  files:
120
120
  - ".byebug_history"
121
121
  - ".gitignore"
122
+ - ".instructions/cache/install:redis.rb"
123
+ - ".instructions/key"
124
+ - ".ruby-version"
122
125
  - CODE_OF_CONDUCT.md
123
126
  - Gemfile
124
127
  - LICENSE.txt
@@ -155,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
158
  version: 1.3.1
156
159
  requirements: []
157
160
  rubyforge_project:
158
- rubygems_version: 2.5.2
161
+ rubygems_version: 2.6.14
159
162
  signing_key:
160
163
  specification_version: 4
161
164
  summary: Instruction List , an automated configuration management tool