cuatlan-devkit 1.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/cdk +114 -0
  3. data/lib/cuatlan_devkit.rb +3 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21408d52be0d81eb8c236db1d6e1868dd072457d6601716f6ff3bf0c2833ec24
4
+ data.tar.gz: cc3062b3ee1e1c764c9b5cc8bcb2640780e7b0bc3234123e9281c8e1a4128f85
5
+ SHA512:
6
+ metadata.gz: 9af1d8dd0d36b16f4f582476b1a7615d3e69a55e669e18939c32eebaf8a881da8be3f96c738552a36c04825b9c2300cbc7ee213b38aa796416e4abe7522048c0
7
+ data.tar.gz: b5a9fac8eaa71bc1fbbb8d46ba56c3043a8468a8dde01db536738f78a6e87ebb7a534c351b28780f64f21410b883b50e9a369334a4839c400ed39978c7f4bce2
data/bin/cdk ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
5
+ require 'cuatlan_devkit'
6
+
7
+ # CUAtLan Development Kit
8
+
9
+ module CDK
10
+ DOTFILE = File.expand_path('~/.cdk.yml')
11
+ TRUSTED_KEY = 'trusted_directories'.freeze
12
+ ROOT_CHECK_FILE = '.cdk-install-root'.freeze
13
+ DEFAULT_INIT_DIRECTORY = File.join(Dir.pwd, 'cuatlan-devkit')
14
+
15
+ def self.launcher_main
16
+ case ARGV.first
17
+ when 'version'
18
+ puts "CUAtLan Development Kit gem version #{CDK::GEM_VERSION}"
19
+ true
20
+ when 'init'
21
+ if ARGV.count > 2
22
+ puts 'Usage: cdk init [DIR]'
23
+ return false
24
+ end
25
+ directory = ARGV.count == 2 ? ARGV[1] : DEFAULT_INIT_DIRECTORY
26
+ cmd = %W[git clone https://gitlab.com/cuatlan/cuatlan-devkit.git #{directory}]
27
+ system(*cmd) && trust!(directory) && remember!(directory)
28
+ when 'trust'
29
+ if ARGV.count != 2
30
+ puts 'Usage: cdk trust DIR'
31
+ return false
32
+ end
33
+ trust!(ARGV[1])
34
+ else
35
+ $cdk_root = find_root(Dir.pwd)
36
+ if $cdk_root.nil?
37
+ puts <<-EOS.gsub(/^\s+\|/, '')
38
+ |
39
+ |The current working directory is not inside a cuatlan-devkit
40
+ |installation. Use 'cd' to go to your cuatlan-devkit or create
41
+ |a new one with 'cdk init'.
42
+ |
43
+ |cdk init [DIRECTORY] # Default: #{DEFAULT_INIT_DIRECTORY}
44
+ |
45
+ EOS
46
+ return false
47
+ end
48
+ puts "(in #{$cdk_root})"
49
+
50
+ unless trusted?($cdk_root)
51
+ puts <<-EOS.gsub(/^\s+\|/, '')
52
+ |
53
+ |This CUatLAN Development Kit root directory is not known to the "cdk"
54
+ |command. To mark it as trusted run:
55
+ |
56
+ |cdk trust #{$cdk_root}
57
+ |
58
+ EOS
59
+ return false
60
+ end
61
+
62
+ load(File.join($cdk_root, 'lib/cdk.rb'))
63
+ CDK.main
64
+ end
65
+ end
66
+
67
+ def self.find_root(current)
68
+ if File.exist?(File.join(current, 'CDK_ROOT'))
69
+ File.realpath(current)
70
+ elsif File.realpath(current) == '/'
71
+ nil
72
+ else
73
+ find_root(File.join(current, '..'))
74
+ end
75
+ end
76
+
77
+ def self.trusted?(directory)
78
+ trusted_directories = load_dotfile[TRUSTED_KEY] || []
79
+ !trusted_directories.include?(File.realpath(directory)).nil?
80
+ end
81
+
82
+ def self.trust!(directory)
83
+ directory = File.realpath(directory)
84
+ config = load_dotfile
85
+ config[TRUSTED_KEY] ||= []
86
+
87
+ if config[TRUSTED_KEY].include?(directory)
88
+ puts "#{directory} is already in #{TRUSTED_KEY} in #{DOTFILE}"
89
+ else
90
+ config[TRUSTED_KEY] << directory
91
+ config[TRUSTED_KEY].uniq!
92
+ puts "Adding #{directory} to #{TRUSTED_KEY} in #{DOTFILE}"
93
+ File.open(DOTFILE, 'w') { |f| YAML.dump(config, f) }
94
+ end
95
+
96
+ true
97
+ end
98
+
99
+ def self.load_dotfile
100
+ File.open(DOTFILE, File::RDONLY | File::CREAT) { |f| YAML.safe_load(f) } || {}
101
+ end
102
+
103
+ def self.remember!(directory)
104
+ open("#{directory}/#{ROOT_CHECK_FILE}", 'w') do |f|
105
+ f.puts File.realpath(directory)
106
+ end
107
+ true
108
+ rescue => ex
109
+ warn ex
110
+ false
111
+ end
112
+ end
113
+
114
+ exit(CDK.launcher_main)
@@ -0,0 +1,3 @@
1
+ module CDK
2
+ GEM_VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuatlan-devkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Karl Shrubb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: CLI for CUatLan Development Kit.
14
+ email:
15
+ - karl@cuatlan.com
16
+ executables:
17
+ - cdk
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/cdk
22
+ - lib/cuatlan_devkit.rb
23
+ homepage: https://gitlab.com/cuatlan/cuatlan-devkit
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.7.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: CLI for CUatLan Development Kit
46
+ test_files: []