Sha256: 0eefb1551efc6fa1aa9ca74db8f896de6eec2b3d3806018ecb258ee7a0d1bb88

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# Execute a shell command.
#

module Gloo
  module Verbs
    class Execute < Gloo::Core::Verb

      KEYWORD = 'execute'.freeze
      KEYWORD_SHORT = 'exec'.freeze
      MISSING_EXPR_ERR = 'Missing Expression!'.freeze

      #
      # Run the verb.
      #
      def run
        if @tokens.token_count < 2
          @engine.err MISSING_EXPR_ERR
          return
        end

        expr = Gloo::Expr::Expression.new( @engine, @tokens.params )
        cmd = expr.evaluate
        @engine.log.debug "starting cmd: #{cmd}"

        if OS.mac?
          pid = fork { exec( cmd ) }
          Process.wait pid
        else
          exec cmd
        end

        # pid = spawn cmd
        # Process.wait pid
        @engine.log.debug "done executing cmd: #{cmd}"

        # system expr.evaluate  #, chdir: Dir.pwd
        # `#{expr.evaluate}`
        # exec expr.evaluate
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gloo-3.5.0 lib/gloo/verbs/execute.rb
gloo-3.4.1 lib/gloo/verbs/execute.rb
gloo-3.4.0 lib/gloo/verbs/execute.rb
gloo-3.3.0 lib/gloo/verbs/execute.rb
gloo-3.2.0 lib/gloo/verbs/execute.rb
gloo-3.1.1 lib/gloo/verbs/execute.rb
gloo-3.1.0 lib/gloo/verbs/execute.rb
gloo-3.0.1 lib/gloo/verbs/execute.rb
gloo-3.0.0 lib/gloo/verbs/execute.rb
gloo-2.5.0 lib/gloo/verbs/execute.rb
gloo-2.4.3 lib/gloo/verbs/execute.rb
gloo-2.4.2 lib/gloo/verbs/execute.rb