| 
									
										
										
										
											2016-02-03 02:54:36 +08:00
										 |  |  | defmodule Parser do | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def parse(command) do | 
					
						
							|  |  |  |     {options, cmd, _} = OptionParser.parse( | 
					
						
							|  |  |  |       command, | 
					
						
							| 
									
										
										
										
											2016-02-03 06:11:54 +08:00
										 |  |  |       switches: [node: :atom, quiet: :boolean], | 
					
						
							|  |  |  |       aliases: [n: :node, q: :quiet] | 
					
						
							| 
									
										
										
										
											2016-02-03 02:54:36 +08:00
										 |  |  |     ) | 
					
						
							|  |  |  |     {clear_on_empty_command(cmd), options} | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 05:26:10 +08:00
										 |  |  |   # Discards entire command if first command term is empty. | 
					
						
							| 
									
										
										
										
											2016-02-03 02:54:36 +08:00
										 |  |  |   defp clear_on_empty_command(command_args) do | 
					
						
							|  |  |  |     case command_args do | 
					
						
							|  |  |  |       [] -> [] | 
					
						
							|  |  |  |       [""|_] -> [] | 
					
						
							|  |  |  |       [head|_] -> command_args | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |