Class: Phoenx::Cli::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/phoenx/cli/cli_factory.rb

Instance Method Summary collapse

Instance Method Details

#cliObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/phoenx/cli/cli_factory.rb', line 99

def cli
	# Build cli
	cli = Phoenx::Cli::Command.new "root", "" do |c|
		c.print
	end
	cli.base_command = "phoenx"
	# Add version and help options
	version_option = Phoenx::Cli::Option.new("--version","-v","Shows version information",false) do
		puts "phoenx version " + Phoenx::VERSION.bold
		exit
	end
	help_option = Phoenx::Cli::Option.new("--help","-h","Shows this help",false) do
		cli.print
		exit
	end
	cli.add_option version_option
	cli.add_option help_option
	cli.add_command self.workspace_command
	cli.add_command self.project_command
	return cli
end

#project_commandObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/phoenx/cli/cli_factory.rb', line 44

def project_command
	command = Phoenx::Cli::Command.new "project", "Builds the project" do
		command.print
		exit
	end
	command.base_command = "phoenx project"
	command.usage = "Generates the xcodeproj file from the pxproject specification."
	# Add project build command
	build_command = Phoenx::Cli::Command.new "build", "Builds the project" do
		projects = Dir["*." + Phoenx::PROJECT_EXTENSION]
		if projects.count < 1
			puts "Error: No project spec found!".red
			exit
		end
		project = eval File.read(projects.first)
		if !project
			puts "Error: No project spec found!".red
			exit
		end
		puts "\r\nGenerating project ".green + project.project_name.bold + ".xcodeproj".bold
		generator = Phoenx::GenerateProject.new project
		generator.build
		exit
	end
	build_command.base_command = "phoenx project"
	build_command.usage = "Generates the xcodeproj file."
	build_help_option = Phoenx::Cli::Option.new("--help", "-h","Shows this help",false) do
		build_command.print
		exit
	end
	build_command.add_option build_help_option
	command.add_command build_command
	# Add project extract command
	extract_command = Phoenx::Cli::Command.new "extract", "Extracts all build settings." do
		projects = Dir["*.xcodeproj"]
		if projects.length < 1
			puts "No Xcode project found.".red
			exit
		end
		project = Xcodeproj::Project::open(projects[0])
		extractor = Phoenx::ExtractBuildSettings.new project
		extractor.extract
		exit
	end
	extract_command.base_command = "phoenx project"
	extract_command.usage = "Extracts all project and scheme build settings to separate xcconfig files"
	extract_help_option = Phoenx::Cli::Option.new("--help", "-h","Shows this help",false) do
		extract_command.print
		exit
	end
	extract_command.add_option extract_help_option
	command.add_command extract_command
	return command
end

#workspace_commandObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/phoenx/cli/cli_factory.rb', line 9

def workspace_command
	command = Phoenx::Cli::Command.new "workspace", "Builds the workspace and projects" do
		command.print
		exit
	end
	command.base_command = "phoenx workspace"
	command.usage = "Initializes the workspace by generating the xcodeproj and xcworkspace files."
	# Add workspace build command
	build_command = Phoenx::Cli::Command.new "build", "Builds the workspace and projects" do
		workspaces = Dir["*." + Phoenx::WORKSPACE_EXTENSION]
		if workspaces.count < 1
			puts "Error: No workspace spec found!".red
			exit
		end
		workspace = eval File.read(workspaces.first)
		if !workspace
			puts "Error: No workspace spec found!".red
			exit
		end
		puts "\r\nWorkspace ".green + workspace.name.bold
		generator = Phoenx::GenerateWorkspace.new workspace
		generator.generate
		exit
	end
	build_command.base_command = "phoenx workspace"
	build_command.usage = "Initializes the workspace by generating the xcodeproj and xcworkspace files."
	build_help_option = Phoenx::Cli::Option.new("--help", "-h","Shows this help",false) do
		build_command.print
		exit
	end
	build_command.add_option build_help_option
	command.add_command build_command
	return command
end