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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/atk/commands/project.rb', line 4
def self.project(args)
if args.length == 0
puts "if you don't know how to use #{"project".blue} just run #{"project help".blue}"
puts ""
begin
commands = Info.project_commands
if commands.is_a?(Hash) && commands.keys.size > 0
puts "commands for current project:"
puts `project commands`
end
rescue => exception
end
else
case args[0]
when 'help', '--help', '-h'
puts " \#{\"help\".yellow}\n \#{\"info:\".green} displays the avalible tools\n \#{\"examples:\".green} \#{'project help'.blue}\n \n \#{\"initialize\".yellow}\n \#{\"examples:\".green}\n \#{'project init'.blue}\n \#{'project initialize'.blue}\n \#{\"info:\".green}\n This will create an info.yaml in your current directory\n The info.yaml will contain all the standard project managment tools\n In the future this command will be more interactive\n\n \#{\"synchronize\".yellow}\n \#{\"examples:\".green}\n \#{'project sync'.blue}\n \#{'project synchronize'.blue}\n \#{'project synchronize --message=\\'updated the readme\\''.blue}\n \#{\"info:\".green}\n Adds, commits, and then pulls/pushes all git changes\n If there is merge conflict, it will show up as normal\n \#{\"format:\".green}\n \#{\"project\".blue} \#{\"synchronize\".yellow} \#{\"<package>\".cyan} \#{\"--message='your message'\".light_magenta}\n \n \#{\"execute\".yellow} \n \#{\"examples:\".green}\n \#{'project execute compile'.blue}\n \#{'project exec compile'.blue}\n \#{'project exec main'.blue}\n \#{'project exec server'.blue}\n \#{\"info:\".green}\n This will look at the info.yaml file in your project to find commands\n You can use the `project init` command to generate an info.yaml which \n has example commands. Commands can be CMD/terminal/console commands, or ruby code.\n \#{\"format:\".green}\n \#{\"project\".blue} \#{\"execute\".yellow} \#{\"<name-of-command>\".cyan} \#{\"<arg1-for-command>\".light_magenta} \#{\"<arg2-for-command>\".light_magenta} \#{\"<...etc>\".light_magenta}\n\n \#{\"commands\".yellow}\n \#{\"examples:\".green} \#{'project commands'.blue}\n \#{\"info:\".green}\n This will read the local info.yaml of your project to find commands\n then it will list out each command with a short preview of the contents of that command\n HEREDOC\n when 'initialize', 'init'\n Info.init\n when 'synchronize', 'sync'\n # if there is an argument\n git_folder_path = FS.dirname(Info.source_path)/\".git\"\n if not FS.is_folder(git_folder_path)\n raise <<-HEREDOC.remove_indent\n \n \n The `project sync` command was called inside of \#{FS.dirname(Info.source_path)}\n However, there doesn't seem to be a git repository in this folder\n (and changes can't be saved/synced without a git repository)\n HEREDOC\n end\n message = args[1]\n if message == nil\n message = \"\"\n else\n if not message.start_with?('--message=')\n raise \"\\n\\nWhen giving arguments to the sync command, please give your message as:\\n\\n project sync --message='whatever you wanted to say'\"\n else\n # remove the begining of the message\n message = args[1].sub(/^--message=/,\"\")\n # remove leading/trailing whitespace\n message.strip!\n end\n end\n if message.size == 0\n message = '-'\n end\n \n # add everything\n system('git add -A')\n # commit everything\n system('git', 'commit', '-m', message)\n # pull down everything\n system('git pull --no-edit')\n # push up everything\n system('git push')\n \n when 'mix'\n not_yet_implemented()\n structure_name = args[1]\n # use this to mix a structure into the project\n # TODO:\n # get the context\n # if there is a --context='something' command line option, then use that\n # otherwise use the default(--context) speficied in the info.yaml\n # re-iterate through the info.yaml (advanced_setup) keys\n # find all of the \"when(--context = 'something')\" keys\n # find the (dependencies) sub-key for them, create one if the key doesn't exist\n # add the project and version to the \n when 'add'\n not_yet_implemented()\n package = args[1]\n # check if there is an info.yaml\n # check if there is an local_package_manager in the info.yaml\n # if there is only 1, then use it\n # if there is more than one, ask which one the user wants to use\n when 'remove'\n not_yet_implemented()\n package = args[1]\n # check if there is an local_package_manager in the info.yaml\n # if it does use it to remove the package\n when 'execute', 'exec'\n # extract the (project_commands) section from the info.yaml, \n # then find the command with the same name as args[1] and run it\n # TODO: use https://github.com/piotrmurach/tty-markdown#ttymarkdown- to highlight the ruby code \n _, command_name, *command_args = args\n command = Info.project_commands[command_name]\n # temporairly set the dir to be the same as the info.yaml \n FS.in_dir(Info.folder()) do\n if command.is_a?(String)\n -(command+' '+command_args.join(' '))\n elsif command.is_a?(Code)\n command.run(*command_args)\n elsif command == nil\n puts \"I don't think that command is in the info.yaml file\"\n end\n end\n when 'commands'\n max_number_of_chars_to_show = 80\n commands = Info.project_commands\n if commands.keys.size == 0\n puts \"0 avalible commands\".cyan\n else\n for each_key, each_value in commands\n puts \" \#{each_key.to_s.yellow}: \#{each_value.to_s.strip[0..max_number_of_chars_to_show].sub(/(.*)[\\s\\S]*/,'\\1')}\"\n end\n end\n else\n puts \"I don't recognized that command\\nhere's the `project --help` which might get you what you're looking for:\"\n Atk.project([\"help\"])\n end\n end\nend\n".remove_indent
|