class Specinfra::Command::Smartos::Base::Package < Specinfra::Command::Solaris::Base::Package
  class << self
    def check_is_installed(package, version=nil)
      cmd = "/opt/local/bin/pkgin list 2> /dev/null | grep -qw ^#{escape(package)}"
      if version
        cmd = "#{cmd}-#{escape(version)}"
      end
      cmd
    end

    def get_version(package, opts=nil)
      "pkgin list | cut -f 1 -d ' ' | grep -E '^#{escape(package)}-([^-])+$' | grep -Eo '(\\.|\\w)+$'"
    end
  end
end

class Specinfra::Command::Smartos::Base::Package < Specinfra::Command::Solaris::Base::Package
  class << self
    def check_is_installed(package, version=nil)
      cmd = "pkg_info -qE #{escape(package)}"
      if version
        cmd = "#{cmd}-#{escape(version)}"
      end
      cmd
    end

    def get_version(package, opts=nil)
      "pkg_info -E #{escape(package)} | awk -F '-' '{print $NF}'"
    end
  end
end

Use pkg_info for check_is_installed and get_version
Use pkg_info for check_is_installed and get_version

Previous version assumed GNU grep is installed which may not always be
the case
