MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / execute

Method execute

ruby/engine/openstudio_cli.rb:743–806  ·  view source on GitHub ↗

Checks to see if it should print the main help, and if not parses the command into a class and executes it

Source from the content-addressed store, hash-verified

741
742 # Checks to see if it should print the main help, and if not parses the command into a class and executes it
743 def execute
744 $logger.debug "Main arguments are #{$main_args}"
745 $logger.debug "Sub-command is #{$sub_command}"
746 $logger.debug "Sub-arguments are #{$sub_args}"
747 if $main_args.include?('-h') || $main_args.include?('--help')
748 # Help is next in short-circuiting everything. Print
749 # the help and exit.
750 help
751 return 0
752 end
753
754 if $main_args.include?('--version')
755 # Version is next in short-circuiting everything. Print it and exit.
756 # This is to have the same behavior as pretty much every CLI, you expect
757 # `<cli> --version` to return the version
758 safe_puts OpenStudio.openStudioLongVersion
759 return 0
760 end
761
762 if !parse_main_args($main_args)
763 help
764 return 1
765 end
766
767 # -e commands detected
768 if !$eval_cmds.empty?
769 $eval_cmds.each do |cmd|
770 $logger.debug "Executing cmd: #{cmd}"
771 eval(cmd, BINDING)
772 end
773 if $sub_command
774 $logger.warn "Evaluate mode detected, ignoring sub_command #{$sub_command}"
775 return 0
776 end
777 return 0
778 end
779
780 # If we reached this far then we must have a command. If not,
781 # then we also just print the help and exit.
782 command_plugin = nil
783 if $sub_command
784 command_plugin = command_list[$sub_command.to_sym]
785 end
786
787 if !command_plugin || !$sub_command
788 help
789 return 1
790 end
791
792 command_class = command_plugin[0].call
793 $logger.debug("Invoking command class: #{command_class} #{$sub_args.inspect}")
794
795 # Initialize and execute the command class, returning the exit status.
796 result = 0
797 begin
798 result = command_class.new.execute($sub_args)
799 rescue Interrupt
800 $logger.error '?'

Callers 2

executeMethod · 0.45
openstudio_cli.rbFile · 0.45

Calls 4

safe_putsFunction · 0.85
parse_main_argsFunction · 0.85
debugMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected