Giter VIP home page Giter VIP logo

ruby-pwsh's Introduction

ruby-pwsh

The PowerShell gem.

This gem enables you to execute PowerShell from within ruby without having to instantiate and tear down a PowerShell process for each command called. It supports Windows PowerShell as well as PowerShell Core (and, soon, just PowerShell) - if you're running *PowerShell v3+, this gem supports you.

The Manager class enables you to execute and interoperate with PowerShell from within ruby, leveraging the strengths of both languages as needed.

Installation

Add this line to your application's Gemfile:

gem 'ruby-pwsh'

And then execute:

bundle install

Or install it yourself as:

gem install ruby-pwsh

Usage

Instantiating the manager can be done using some defaults:

# Instantiate the manager for Windows PowerShell, using the default path and arguments
# Note that this takes a few seconds to instantiate.
posh = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
# If you try to create another manager with the same arguments it will reuse the existing one.
ps = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
# Note that this time the return is very fast.
# We can also use the defaults for PowerShell Core, though these only work if PowerShell is
# installed to the default paths - if it is installed anywhere else, you'll need to specify
# the full path to the pwsh executable.
pwsh = Pwsh::Manager.instance(Pwsh::Manager.pwsh_path, Pwsh::Manager.pwsh_args)

Execution can be done with relatively little additional work - pass the command string you want executed:

# Instantiate the Manager:
posh = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
# Pretty print the output of `$PSVersionTable` to validate the version of PowerShell running
# Note that the output is a hash with a few different keys, including stdout.
pp(posh.execute('$PSVersionTable'))
# Lets reduce the noise a little and retrieve just the version number:
# Note: We cast to a string because PSVersion is actually a Version object.
pp(posh.execute('[String]$PSVersionTable.PSVersion'))
# We could store this output to a ruby variable if we wanted, for further use:
ps_version = posh.execute('[String]$PSVersionTable.PSVersion')[:stdout].strip
pp("The PowerShell version of the currently running Manager is #{ps_version}")

Reference

You can find the full reference documentation online, here.

Releasing the Gem and Puppet Module

Steps to release an update to the gem and module include:

  1. From main, checkout a new working branch for the release prep (where xyz is the appropriate version, sans periods):

    git checkout -b maint-release_prep_xyz
  2. Update the version in lib/pwsh/version.rb and metadata.json to the appropriate version for the new release.

  3. Run the changelog update task (make sure to verify the changelog, correctly tagging PRs as needed):

    bundle exec rake changelog
    1. Commit your changes with a short, sensible commit message, like:
    git add lib/pwsh/version.rb
    git add metadata.json
    git add CHANGELOG.md
    git commit -m '(MAINT) Prep for x.y.z release'
  4. Push your changes and submit a pull request for review _against main:

    git push -u origin maint_release_prep_xyz
  5. Ensure tests pass and the code is merged to main.

  6. Once the release_prep PR has been merged, checkout main and pull down the latests changes.

    git checkout main
    git pull
  7. Assuming that the release_prep merge commit is at the HEAD of main we can simply create and push a tag as follows (replacing xyz with the appropriate version).

    git tag -a xyx -m "Release xyz"
    git push --follow-tags
  8. Execute the publish workflow. This will:

    • Create a GitHub release
    • Build and publish the Gem
    • Build and publish the Puppet module
  9. Finally check that the expected versions are present on rubygems.org and the Forge.

Known Issues

Supported Operating Systems

The following platforms are supported:

  • Windows
  • CentOS
  • Debian
  • Fedora
  • OSX
  • RedHat
  • Ubuntu

ruby-pwsh's People

Contributors

adrianiurca avatar binford2k avatar bwilcox avatar chelnak avatar da-ar avatar daianamezdrea avatar david22swan avatar davids avatar disha-maker avatar glennsarti avatar gspatton avatar hvid avatar jordanbreen28 avatar jpogran avatar lionce avatar lukasaud avatar michaeltlombardi avatar n3snah avatar pmcmaw avatar randomnoun7 avatar sanfrancrisko avatar sheenaajay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.