Class: Tuya::Command::Lib::Create

Inherits:
Tuya::Command::Lib show all
Defined in:
lib/tycli/command/lib/create.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



19
20
21
22
# File 'lib/tycli/command/lib/create.rb', line 19

def initialize(argv)
	super
	@name = argv.option('name')
end

Class Method Details

.optionsObject



9
10
11
12
13
# File 'lib/tycli/command/lib/create.rb', line 9

def self.options
	[
		['--name=module_name', '--name to named your module']
	].concat(super)
end

Instance Method Details

#createModuleObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tycli/command/lib/create.rb', line 61

def createModule

	if File.exist? "./#{@name}"
		puts "#{@name} is alerady exits".red
	else
		result = `pod lib create #{@name} --template-url=https://github.com/TuyaInc/pod-template.git`
		result.each_line do |s|
			if s.include?("fatal")
				puts "#{s}".red
			end
		end
	end
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tycli/command/lib/create.rb', line 24

def run
		puts "creating the module named: #{@name}...".yellow

		require 'ruby-progressbar'

		require 'colored'

		file_not_exist = !File.exist?("./#{@name}")
		puts "#{@name} is alerady exits".red unless file_not_exist

		if file_not_exist

			progressbar = ProgressBar.create
			15.times { progressbar.increment; sleep 3 }

			t_c = Thread.new {createModule()}

			t_c.join
			progressbar.finish

			puts "create module: #{@name} successful".green

			puts "\n\n我们默认添加了SDK依赖, 可在Podfile文件中查看\n".green
			puts "SDK文档及使用请参考:https://github.com/TuyaInc/tuyasmart_home_ios_sdk\n".green

			require 'tycli/lib'

			Tuya::TYLib.create_lib @name
		end

end

#showProgressObject



56
57
58
59
# File 'lib/tycli/command/lib/create.rb', line 56

def showProgress
	progressbar = ProgressBar.create
	100.times { progressbar.increment; sleep 3 }
end

#validate!Object



15
16
17
# File 'lib/tycli/command/lib/create.rb', line 15

def validate!
	help! "name need" unless @name
end