-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhf
executable file
·90 lines (80 loc) · 3.29 KB
/
hf
1
2
3
4
5
6
7
8
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
43
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
#!/usr/bin/env ruby
VERSION = '2.0.19'
mac_path = `ls -l /usr/local/bin/`.split("\n").detect{|symlink| symlink.include? 'git-hotfix' }
linux_path = `ls -l /usr/bin/`.split("\n").detect{|symlink| symlink.include? 'git-hotfix' }
ROOT_DIR = (mac_path || linux_path).scan(/\->\s(.*)\/hf/)[0][0]
PROJECT_DIR = `pwd`.gsub("\n", '')
# p ROOT_DIR
# p PROJECT_DIR
require 'yaml'
require ROOT_DIR + '/context.rb'
require ROOT_DIR + '/config.rb'
require ROOT_DIR + '/remote.rb'
require ROOT_DIR + '/exec_cli.rb'
require ROOT_DIR + '/actions/deploy_action.rb'
require ROOT_DIR + '/actions/checkout_action.rb'
require ROOT_DIR + '/actions/delete_merged_action.rb'
require ROOT_DIR + '/actions/config_action.rb'
require ROOT_DIR + '/actions/sync_action.rb'
require ROOT_DIR + '/actions/reset_action.rb'
require ROOT_DIR + '/actions/get_action.rb'
require ROOT_DIR + '/actions/st_action.rb'
require ROOT_DIR + '/actions/save_action.rb'
require ROOT_DIR + '/actions/help_action.rb'
require ROOT_DIR + '/actions/init_action.rb'
require ROOT_DIR + '/actions/my_action.rb'
require ROOT_DIR + '/actions/self_update_action.rb'
require ROOT_DIR + '/actions/run_action.rb'
require ROOT_DIR + '/lib/string.rb'
def run_actions(args, options)
action = args[0]
return RunAction.(args, options) if action == 'run' || action == 'r'
return SaveAction.(args, options) if action == 'save'
return DeployAction.(args, options) if action == 'deploy'
return ConfigAction.(args, options) if action == 'config'
return SyncAction.(args, options) if action == 'resolve'
return DeleteMergedAction.(args, options) if action == 'delete-merged'
return ResetAction.(args, options) if action == 'reset'
return GetAction.(args, options) if action == 'get'
return StAction.(args, options) if action == 'st'
return SelfUpdateAction.(args, options) if action == 'self-update'
return InitAction.(args, options) if action == 'init'
return MyAction.(args, options) if action == 'my'
return CheckoutAction.(args, options) if args.count == 1
return HelpAction.(args, options) if args.count == 0
end
def main
args = ARGV.select{|arg| arg[0] != '-' || arg.include?(' ') }
flags = ARGV.select{|arg| arg[0] == '-' && !arg.include?(' ') }
options = {}
options[:no_push] = flags.include?('--local') || flags.include?('--l')
options[:always_commit] = flags.include?('--ac') || flags.include?('--always-commit')
options[:quiet] = flags.include?('--quiet') || flags.include?('--q')
options[:yes] = flags.include?('--yes') || flags.include?('--y')
options[:echo] = flags.include?('--echo')
options[:skip_staging] = flags.include?('--skip-add')
options[:mode] = flag_value(flags, 'mode', 'm')
options[:project_name] = flag_value(flags, 'project_name', 'p')
options[:clean] = flag_value(flags, 'clean', 'c')
# TODO refactor updating of config
if options[:mode]
Config.write({
'mode' => options[:mode]
})
end
if options[:project_name]
Config.write({
'project_name' => options[:project_name]
})
end
#
response = run_actions(args, options)
ExecCli.(response, args, options)
end
def flag_value(flags, *names)
searched_flag = flags.find do |flag|
!!names.find{|name| flag.start_with?('--' + name) }
end
searched_flag ? searched_flag.split('=').last : nil
end
main()