byld-cli 0.0.3 → 0.0.9

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
  SHA256:
3
- metadata.gz: decef90cffd5ac17e6fcfcace023d5d6038c749bca10460c919578821c07761b
4
- data.tar.gz: b9557430faa77e52e94693f60db46bf5ac1f0637fea6dbc0373e06462e24a923
3
+ metadata.gz: 0d850ce35811255d939c37b62814d57d6178ca0cf9853e5f565160602fe2e325
4
+ data.tar.gz: 4b3029fcb988bb369161ffe3499801699d12e3c90b0f5fe7ff3e8821495cb039
5
5
  SHA512:
6
- metadata.gz: 89d433f57987ceecd95d27f9b67e29dfd8b4e0c2d95c7604ce857812940d9fa256fc44e484acc73db06827c4c54238ecf98d649a90462905c2409991a46b59a2
7
- data.tar.gz: 37b7a69725a6f56fe6df57ddc4eef115dd9d38b4164d8a1bd91aa831ed71015f8a4169665a81a65220ca4e1faf8d7f6110838d16dedad04021bf39af93b9bab5
6
+ metadata.gz: 6a949f660056c52fc4892de02cfb748127340bdad3c54ca862f4c61958137f082c22b11297bc7cd3b0413415b5ce88c902fb544767e2af504f2221c04eb732ea
7
+ data.tar.gz: 1c4fcf318a0896e369b21ce45d06028e49e263ac9cd1b08c1ddd5eba166e5536a56010dbf2415237e0ec344e663c6b34138c6305f401d61136e7d974cb328c0a
@@ -1,9 +1,10 @@
1
+ require_relative ('./lib/constants')
1
2
  lib = File.expand_path("../lib", __FILE__)
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
 
4
5
  Gem::Specification.new do |spec|
5
6
  spec.name = 'byld-cli'
6
- spec.version = '0.0.3'
7
+ spec.version = BYLD_VERSION
7
8
 
8
9
  spec.authors = ['the fellowhip co']
9
10
  spec.summary = 'cli for byld'
@@ -11,15 +11,15 @@ class Connect < Thor::Group
11
11
  end
12
12
 
13
13
  def create_client
14
+ namespace_id, project_id = ConfigHelper.get_namespace_and_project
14
15
  puts "☝️ Connecting #{name}..."
15
- namespace_config = Config.load(".byld/config.yml")
16
16
 
17
- success, res = Infra.generate_client(name, namespace_config['namespace']['id'])
17
+ success, res = Infra.generate_client(name, namespace_id)
18
18
  if success
19
19
  create_file ".byld/gen/#{name.underscore}.rb", res.first['content']
20
20
  puts "🔗 #{name} connected successfully!"
21
21
  else
22
- say "⚠️ Error connecting block. Reason: #{res}" unless success
22
+ say "⚠️ Error connecting block. Reason: #{res['error']}" unless success
23
23
  end
24
24
  end
25
25
 
@@ -7,21 +7,18 @@ class CreateBlock < Thor::Group
7
7
  File.dirname(__FILE__)
8
8
  end
9
9
 
10
- def create_directory
10
+ def create_infra
11
11
  say "✍️ Setting up #{name}..."
12
- directory '../templates/block', name
13
- end
12
+ namespace_id = ConfigHelper.get_namespace_id
13
+ success, res = Infra.create_project(namespace_id, name, 'domain')
14
14
 
15
- def create_infra
16
- namespace_config = Config.load(".byld/config.yml")
17
- success, res = Infra.create_project(namespace_config['namespace']['id'], name, 'domain')
18
-
19
15
  if success
20
- block_config = Config.load("#{name}/.byld/config.yml")
21
- block_config.merge!(project: res)
16
+ directory '../templates/block', name
17
+ ConfigHelper.save_config('project', name, res)
18
+
22
19
  say "👍 Block created successfully!"
23
20
  else
24
- say "⚠️ Error creating block. Reason: #{res}" unless success
21
+ say "⚠️ Error creating block. Reason: #{res['error']}" unless success
25
22
  end
26
23
  end
27
24
 
@@ -7,7 +7,7 @@ class RunMigration < Thor::Group
7
7
  class_option :env, :default => 'dev'
8
8
 
9
9
  def run_migrations
10
- db_config = YAML::load(File.open(".byld/config.yml"))['storage']
10
+ db_config = Config.load(".byld/config.yml")['storage']
11
11
  ActiveRecord::Base.establish_connection(db_config)
12
12
  ActiveRecord::MigrationContext.new(".byld/migrations/").migrate
13
13
  end
@@ -22,6 +22,8 @@ require_relative 'gates/gate'
22
22
  require_relative 'gates/expose'
23
23
 
24
24
  class ByldCli < Thor
25
+ map %w[--version -v] => :__print_version
26
+
25
27
  register(LoginUser, 'login', 'login', 'Logins into your account')
26
28
  register(CreateProject, 'new', 'new [NAME]', 'Creates a new project')
27
29
  register(Deploy, 'deploy', 'deploy', 'Deploys the current block or gate')
@@ -37,5 +39,11 @@ class ByldCli < Thor
37
39
 
38
40
  desc 'gate [COMMAND]', 'Gate commands'
39
41
  subcommand 'gate', Gate
42
+
43
+ desc "--version, -v", "Display the version"
44
+ def __print_version
45
+ puts BYLD_VERSION
46
+ end
47
+
40
48
  end
41
49
 
@@ -32,13 +32,16 @@ class AccessConsole < Thor::Group
32
32
  ws = Faye::WebSocket::Client.new("ws://#{BIFROST_HOST}?namespace=#{res['namespace_name']}&pod=#{res['pod_name']}")
33
33
 
34
34
  ws.on :open do |event|
35
- puts "🟢 Connected!"
35
+ puts "🌐 Connecting to IRB Console..."
36
36
  end
37
37
 
38
38
  command = ""
39
+ connected = false
39
40
  ws.on :message do |event|
40
41
  data = Base64.strict_decode64(event.data)
41
42
  if (data.strip.end_with?("#"))
43
+ puts "🟢 Connected!" unless connected
44
+ connected = true
42
45
  command = ask(data)
43
46
  ws.send(command)
44
47
  else
@@ -49,12 +52,13 @@ class AccessConsole < Thor::Group
49
52
  end
50
53
 
51
54
  ws.on :close do |event|
52
- # p [:close, event.code, event.reason]
53
55
  ws = nil
56
+ say "⚠️ Connection lost: #{event.code}: #{event.reason}"
57
+ exit
54
58
  end
55
59
  }
56
60
  else
57
- say "⚠️ Error connecting to the console. Reason: #{res}" unless success
61
+ say "⚠️ Error connecting to the console. Reason: #{res['error']}" unless success
58
62
  end
59
63
  end
60
64
  end
@@ -26,7 +26,7 @@ class AccessLogs < Thor::Group
26
26
  last_since_time = has_new_logs ? since_time : last_since_time
27
27
  say res['logs'] if has_new_logs
28
28
  else
29
- say "⚠️ Error getting logs. Reason: #{res}" unless success
29
+ say "⚠️ Error getting logs. Reason: #{res['error']}" unless success
30
30
  end
31
31
  sleep 2
32
32
  end
@@ -7,22 +7,18 @@ class CreateProject < Thor::Group
7
7
  File.dirname(__FILE__)
8
8
  end
9
9
 
10
- def create_directory
10
+ def create_project
11
11
  say "✍️ Setting up your project..."
12
- empty_directory name
13
- create_file "#{name}/.byld/config.yml"
14
- end
15
-
16
- def create_project
17
12
  success, res = Infra.create_namespace(Config.instance['id'], name)
18
-
13
+
19
14
  if success
20
- namespace_config = Config.load("#{name}/.byld/config.yml")
21
- namespace_config.merge!(namespace: res)
15
+ empty_directory name
16
+ create_file "#{name}/.byld/config.yml"
17
+ ConfigHelper.save_config('namespace', name, res)
22
18
 
23
19
  say "👍 Project created successfully!"
24
20
  else
25
- say "⚠️ Error creating project. Reason: #{res}" unless success
21
+ say "⚠️ Error creating project. Reason: #{res['error']}" unless success
26
22
  end
27
23
  end
28
24
  end
@@ -7,14 +7,14 @@ class Deploy < Thor::Group
7
7
 
8
8
  def deploy
9
9
  name = File.basename(Dir.getwd)
10
- project_config = Config.load(".byld/config.yml")
10
+ _, project_id = ConfigHelper.get_namespace_and_project
11
11
 
12
12
  say "☝️ Deploying #{name}..."
13
- success, res = Infra.deploy(project_config['project']['id'])
13
+ success, res = Infra.deploy(project_id)
14
14
  if success
15
15
  say "👌 Deployment triggered!"
16
16
  else
17
- say "⚠️ Error deploying block or gate. Reason: #{res}" unless success
17
+ say "⚠️ Error deploying block or gate. Reason: #{res['error']}" unless success
18
18
  end
19
19
  end
20
20
 
@@ -17,7 +17,7 @@ class LoginUser < Thor::Group
17
17
 
18
18
  say "👋 You're logged in!"
19
19
  else
20
- say "⚠️ Error signing in. Reason: #{res}" unless success
20
+ say "⚠️ Error signing in. Reason: #{res['error']}" unless success
21
21
  end
22
22
  end
23
23
  end
@@ -8,35 +8,25 @@ class Status < Thor::Group
8
8
  end
9
9
 
10
10
  def print_status
11
- success, res = Infra.get_namespace(namespace_id)
11
+ success, res = Infra.get_namespace(ConfigHelper.get_namespace_id)
12
12
 
13
- say "⚠️ Error fetching project status. Reason: #{res}" unless success
13
+ say "⚠️ Error fetching project status. Reason: #{res['error']}" and return unless success
14
14
 
15
15
  say set_color("\n#{res['name']}\n", :bold)
16
16
  say set_color("gate\n", :bold)
17
17
 
18
18
  gates = res['projects']
19
- .filter { |project| project['projectType'] == 'graph' }
19
+ .select { |project| project['projectType'] == 'graph' }
20
20
  .map { |project| [project['name'], project['status'], project['url'], project['docsUrl']] }
21
21
 
22
22
  say Terminal::Table.new headings: ['name', 'status', 'url', 'docs'], rows: gates
23
23
 
24
24
  say set_color("\nblocks\n", :bold)
25
25
  blocks = res['projects']
26
- .filter { |project| project['projectType'] == 'domain' }
26
+ .select { |project| project['projectType'] == 'domain' }
27
27
  .map { |project| [project['name'], project['status']] }
28
28
 
29
29
  say Terminal::Table.new headings: ['name', 'status'], rows: blocks
30
30
  end
31
31
 
32
- def namespace_id
33
- config = Config.load(".byld/config.yml")
34
-
35
- if config['namespace'].present?
36
- config['namespace']['id']
37
- elsif config['project'].present?
38
- config['project']['namespaceId']
39
- end
40
- end
41
-
42
32
  end
@@ -1,3 +1,4 @@
1
1
  BYLD_CONF = "#{Dir.home}/.byld.yaml"
2
2
  BYLD_HOST = ENV['BYLD_HOST'] || 'api.letsbyld.com'
3
3
  BIFROST_HOST = ENV['BIFROST_HOST'] || 'sockets.letsbyld.com'
4
+ BYLD_VERSION = '0.0.9'
@@ -5,22 +5,19 @@ class CreateGate < Thor::Group
5
5
  File.dirname(__FILE__)
6
6
  end
7
7
 
8
- def create_directory
8
+ def create_infra
9
9
  say "✍️ Setting up your gate..."
10
-
11
- directory "../templates/gate", 'gate'
12
- end
13
10
 
14
- def create_infra
15
- namespace_config = Config.load(".byld/config.yml")
16
- sucess, res = Infra.create_project(namespace_config['namespace']['id'], 'gate', 'graph')
17
-
11
+ namespace_id = ConfigHelper.get_namespace_id
12
+ sucess, res = Infra.create_project(namespace_id, 'gate', 'graph')
13
+
18
14
  if sucess
19
- say "👍 Gate created successfully!"
20
- gate_config = Config.load("gate/.byld/config.yml")
21
- gate_config.merge!(project: res)
15
+ directory "../templates/gate", 'gate'
16
+ ConfigHelper.save_config('project', 'gate', res)
17
+
18
+ say "👍 Gate created successfully!"
22
19
  else
23
- say "⚠️ Error creating gate. Reason: #{res}"
20
+ say "⚠️ Error creating gate. Reason: #{res['error']}"
24
21
  end
25
22
  end
26
23
 
@@ -12,20 +12,20 @@ class Expose < Thor::Group
12
12
  def create_client
13
13
  puts "☝️ Connecting #{name}..."
14
14
 
15
- gate_config = Config.load(".byld/config.yml")
16
- success, res = Infra.generate_client(name, gate_config['project']['namespaceId'])
15
+ namespace_id, gate_id = ConfigHelper.get_namespace_and_project
16
+ success, res = Infra.generate_client(name, namespace_id)
17
17
  if success
18
18
  create_file ".byld/gen/#{name.underscore}.rb", res.first['content']
19
19
  puts "🔗 #{name} connected successfully!"
20
20
  else
21
- puts "⚠️ Error connecting block. Reason: #{res}"
21
+ puts "⚠️ Error connecting block. Reason: #{res['error']}"
22
22
  end
23
23
  end
24
24
 
25
25
  def create_edge
26
26
  puts "☝️ Exposing #{name}..."
27
- gate_config = Config.load(".byld/config.yml")
28
- success, res = Infra.generate_edges(name, gate_config['project']['namespaceId'])
27
+ namespace_id, gate_id = ConfigHelper.get_namespace_and_project
28
+ success, res = Infra.generate_edges(name, namespace_id)
29
29
  if success
30
30
  res.each do |edge|
31
31
  create_file "./edges/#{edge['name']}", edge['content']
@@ -1,3 +1,3 @@
1
- class <%= @model_camel %> < ActiveRecord::Base
1
+ class <%= @model_camel %> < Byld::Model
2
2
  expose allow: [:get, :create, :update, :delete]
3
3
  end
@@ -1,13 +1,19 @@
1
1
  module ConfigHelper
2
+
3
+ def self.save_config(key, dir, config)
4
+ block_config = Config.load("#{dir}/.byld/config.yml")
5
+ block_config.merge!(key => config)
6
+ end
7
+
2
8
  def self.get_namespace_and_project
3
- namespace_path = "../.byld/config.yml"
4
- project_path = ".byld/config.yml"
9
+ namespace_path = '../.byld/config.yml'
10
+ project_path = '.byld/config.yml'
5
11
 
6
- namespace_config = Config.load("../.byld/config.yml") if File.exist?(namespace_path)
7
- project_config = Config.load(".byld/config.yml") if File.exist?(project_path)
12
+ namespace_config = Config.load(namespace_path) if File.exist?(namespace_path)
13
+ project_config = Config.load(project_path) if File.exist?(project_path)
8
14
 
9
15
  if namespace_config.nil? or project_config.nil?
10
- puts "\n 🚫Config is missing! Note: command is valid only within block or gate root folder \n\n"
16
+ puts "\n🚫 Config is missing! Note: This command is valid only within block or gate directory \n\n"
11
17
  exit
12
18
  end
13
19
 
@@ -16,4 +22,21 @@ module ConfigHelper
16
22
 
17
23
  [namespace_id, project_id]
18
24
  end
25
+
26
+ def self.get_namespace_id
27
+ config_path = '.byld/config.yml'
28
+ config = Config.load(config_path) if File.exist?(config_path)
29
+
30
+ if config.nil?
31
+ puts "\n🚫 Config is missing! Note: This command is valid only within block or gate or project directory \n\n"
32
+ exit
33
+ end
34
+
35
+ if config['namespace'].present?
36
+ config['namespace']['id']
37
+ elsif config['project'].present?
38
+ config['project']['namespaceId']
39
+ end
40
+ end
41
+
19
42
  end
@@ -3,5 +3,5 @@ source "https://rubygems.org"
3
3
  gem 'sqlite3'
4
4
 
5
5
  source "https://rubygems.pkg.github.com/the-fellowship-co/" do
6
- gem "byld-framework", "0.1.20"
6
+ gem "byld-framework", "0.1.28"
7
7
  end
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  source "https://rubygems.pkg.github.com/the-fellowship-co/" do
4
- gem "byld-framework", "0.1.20"
4
+ gem "byld-framework", "0.1.28"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byld-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - the fellowhip co
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: 5.2.3
111
111
  description: cli for byld
112
- email:
112
+ email:
113
113
  executables:
114
114
  - byld
115
115
  extensions: []
@@ -162,10 +162,10 @@ files:
162
162
  - lib/templates/gate/.byld/config.yml.tt
163
163
  - lib/templates/gate/Gemfile
164
164
  - lib/templates/gate/edges/.empty_directory
165
- homepage:
165
+ homepage:
166
166
  licenses: []
167
167
  metadata: {}
168
- post_install_message:
168
+ post_install_message:
169
169
  rdoc_options: []
170
170
  require_paths:
171
171
  - lib
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubygems_version: 3.0.3
184
- signing_key:
184
+ signing_key:
185
185
  specification_version: 4
186
186
  summary: cli for byld
187
187
  test_files: []