ruby-pwsh 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45a4e8fcc1b0bf5eba64fc3798038898f082e1f2306523e197de6c801f61c872
4
- data.tar.gz: 31817197b1a07056dd1f4e6d9296eec1ceb4a39380244a9d00aa937a4ac76aa6
3
+ metadata.gz: 461a867f01c932c2baaaee8211f32cec09921d1e1b8f706fc7abe9dba7489d7b
4
+ data.tar.gz: 9086a7408096976b332b8b1fe97771de8d86788d3ac2a87421493b89b9215311
5
5
  SHA512:
6
- metadata.gz: 5fd66bd52888d7a52bc262d2f977f6100b723531ee283aff31aec7e95ab9b0605e3fce7dcb94e34d13de4b01d0236a56b49ca60e55148e7df4a7dfee63cd8f2d
7
- data.tar.gz: 98668a759b733ddc17651011709c1070ae0b407afb84f4de356ec2b181d8353db0d5b57f1cdc64cf67039c994fb6811c679140a3177ba9e489ba72a3874032d0
6
+ metadata.gz: ed6bff68ed27bcb1db20103cf7105bea51776456073f457177c029251aa0c2c0b9d7aec1085f86141b1c88ce0c06da4e7cf5ac6a3375b7aca5684c06c575b2fb
7
+ data.tar.gz: 29a9c33098583b09e10ed5c18f706da954e5ce1d1b1f5fdf24ba086128da851d1e24e954ae9b0735abc3cd95d9bc4faaec61d327c78595fac04c50c9123b4d5c
@@ -0,0 +1,19 @@
1
+ .bundle
2
+ .yardoc
3
+ doc
4
+ .git
5
+ spec
6
+ .gitattributes
7
+ .gitignore
8
+ .rspec
9
+ .rspec_status
10
+ .rubocop.yml
11
+ .travis.yml
12
+ CODEOWNERS
13
+ CONTRIBUTING.md
14
+ design-comms.png
15
+ DESIGN.md
16
+ Gemfile
17
+ Gemfile.lock
18
+ Rakefile
19
+ ruby-pwsh.gemspec
@@ -0,0 +1,16 @@
1
+ # Change log
2
+
3
+ All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
4
+
5
+ ## [0.2.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.2.0) (2019-11-25)
6
+
7
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.1.0...0.2.0)
8
+
9
+ ### Added
10
+
11
+ - \(FEAT\) Add quality of life utilities [\#11](https://github.com/puppetlabs/ruby-pwsh/pull/11) ([michaeltlombardi](https://github.com/michaeltlombardi))
12
+ - \(FM-8422\) Make library releasable as a Puppet module [\#8](https://github.com/puppetlabs/ruby-pwsh/pull/8) ([michaeltlombardi](https://github.com/michaeltlombardi))
13
+
14
+
15
+
16
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -0,0 +1,155 @@
1
+ # Contributing to ruby-pwsh
2
+
3
+ So you want to contribute to the ruby-pwsh gem: Great! Below are some instructions to get you started doing
4
+ that very thing while setting expectations around code quality as well as a few tips for making the
5
+ process as easy as possible.
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Getting Started](#getting-started)
10
+ 1. [Commit Checklist](#commit-checklist)
11
+ 1. [Submission](#submission)
12
+ 1. [More about commits](#more-about-commits)
13
+ 1. [Testing](#testing)
14
+ - [Running Tests](#running-tests)
15
+ - [Writing Tests](#writing-tests)
16
+ 1. [Get Help](#get-help)
17
+
18
+ ## Getting Started
19
+
20
+ - Fork the module repository on GitHub and clone to your workspace
21
+ - Make your changes!
22
+
23
+ ## Commit Checklist
24
+
25
+ ### The Basics
26
+
27
+ - [x] my commit is a single logical unit of work
28
+ - [x] I have checked for unnecessary whitespace with "git diff --check"
29
+ - [x] my commit does not include commented out code or unneeded files
30
+
31
+ ### The Content
32
+
33
+ - [x] my commit includes tests for the bug I fixed or feature I added
34
+ - [x] my commit includes appropriate documentation changes if it is introducing a new feature or changing existing functionality
35
+ - [x] my code passes existing test suites
36
+
37
+ ### The Commit Message
38
+
39
+ - [x] the first line of my commit message includes:
40
+ - [x] an issue number (if applicable), e.g. "(GH-xxxx) This is the first line"
41
+ - [x] a short description (50 characters is the soft limit, excluding issue number(s))
42
+ - [x] the body of my commit message:
43
+ - [x] is meaningful
44
+ - [x] uses the imperative, present tense: "change", not "changed" or "changes"
45
+ - [x] includes motivation for the change, and contrasts its implementation with the previous behavior
46
+
47
+ ## Submission
48
+
49
+ ### Pre-requisites
50
+
51
+ - Make sure you have a [GitHub account](https://github.com/join)
52
+ - [Create an issue](https://github.com/puppetlabs/ruby-pwsh/issues/new/choose), or [watch the issue](https://github.com/puppetlabs/ruby-pwsh/issues) you are patching for.
53
+
54
+ ### Push and PR
55
+
56
+ - Push your changes to your fork
57
+ - [Open a Pull Request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) against the repository in the puppetlabs organization
58
+
59
+ ## More about commits
60
+
61
+ 1. Make separate commits for logically separate changes.
62
+
63
+ Please break your commits down into logically consistent units which include new or changed tests relevant to the rest of the change.
64
+ The goal of doing this is to make the diff easier to read for whoever is reviewing your code.
65
+ In general, the easier your diff is to read, the more likely someone will be happy to review it and get it into the code base.
66
+
67
+ If you are going to refactor a piece of code, please do so as a separate commit from your feature or bug fix changes.
68
+
69
+ We also really appreciate changes that include tests to make sure the bug is not re-introduced, and that the feature is not accidentally broken.
70
+
71
+ Describe the technical detail of the change(s).
72
+ If your description starts to get too long, that is a good sign that you probably need to split up your commit into more finely grained pieces.
73
+
74
+ Commits which plainly describe the things which help reviewers check the patch and future developers understand the code are much more likely to be merged in with a minimum of bike-shedding or requested changes.
75
+ Ideally, the commit message would include information, and be in a form suitable for inclusion in the release notes for the version of Puppet that includes them.
76
+
77
+ Please also check that you are not introducing any trailing whitespace or other "whitespace errors".
78
+ You can do this by running `git diff --check` on your changes before you commit.
79
+
80
+ 2. Sending your patches
81
+
82
+ To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of directly on "master".
83
+ It makes things much easier to keep track of, especially if you decide to work on another thing before your first change is merged in.
84
+
85
+ GitHub has some pretty good [general documentation](http://help.github.com/) on using their site.
86
+ They also have documentation on [creating pull requests](https://help.github.com/articles/creating-a-pull-request-from-a-fork/).
87
+
88
+ In general, after pushing your topic branch up to your repository on GitHub, you can switch to the branch in the GitHub UI and click "Pull Request" towards the top of the page in order to open a pull request.
89
+
90
+ 3. Update the related GitHub issue.
91
+
92
+ If there is a GitHub issue associated with the change you submitted, then you should update the issue to include the location of your branch, along with any other commentary you may wish to make.
93
+
94
+ # Testing
95
+
96
+ ## Getting Started
97
+
98
+ Our Puppet modules provide [`Gemfile`](./Gemfile)s, which can tell a Ruby package manager such as [bundler](http://bundler.io/) what Ruby packages,
99
+ or Gems, are required to build, develop, and test this software.
100
+
101
+ Please make sure you have [bundler installed](http://bundler.io/#getting-started) on your system, and then use it to
102
+ install all dependencies needed for this project in the project root by running
103
+
104
+ ```shell
105
+ # Unless you're doing a release, you don't need the puppet gem group
106
+ % bundle install --path .bundle/gems --without puppet
107
+ Fetching gem metadata from https://rubygems.org/........
108
+ Fetching gem metadata from https://rubygems.org/..
109
+ Using rake (10.1.0)
110
+ Using builder (3.2.2)
111
+ -- 8><-- many more --><8 --
112
+ Your bundle is complete!
113
+ Use `bundle show [gemname]` to see where a bundled gem is installed.
114
+ ```
115
+
116
+ NOTE: some systems may require you to run this command with sudo.
117
+
118
+ If you already have those gems installed, make sure they are up-to-date:
119
+
120
+ ```shell
121
+ % bundle update
122
+ ```
123
+
124
+ ## Running Tests
125
+
126
+ With all dependencies in place and up-to-date, run the tests:
127
+
128
+ ### Unit Tests
129
+
130
+ ```shell
131
+ % bundle exec rake spec
132
+ ```
133
+
134
+ This executes all the [rspec tests](https://rspec.info/) in the `spec` directory.
135
+
136
+ ## If you have commit access to the repository
137
+
138
+ Even if you have commit access to the repository, you still need to go through the process above, and have someone else review and merge
139
+ in your changes.
140
+ The rule is that **all changes must be reviewed by a project developer that did not write the code to ensure that all changes go through a code review process.**
141
+
142
+ The record of someone performing the merge is the record that they performed the code review.
143
+ Again, this should be someone other than the author of the topic branch.
144
+
145
+ ## Get Help
146
+
147
+ ### On the web
148
+
149
+ - [General GitHub documentation](http://help.github.com/)
150
+ - [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
151
+
152
+ ### On chat
153
+
154
+ - Slack (slack.puppet.com) #forge-modules, #puppet-dev, #windows, #voxpupuli
155
+ - IRC (freenode) #puppet-dev, #voxpupuli
data/Gemfile CHANGED
@@ -22,6 +22,10 @@ group :development do
22
22
  gem 'yard'
23
23
  end
24
24
 
25
+ group :puppet do
26
+ gem 'pdk', '~> 1.0'
27
+ end
28
+
25
29
  group :pry do
26
30
  gem 'fuubar'
27
31
 
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rubocop/rake_task'
4
+ require 'fileutils'
4
5
  require 'github_changelog_generator/task'
6
+ require 'open3'
5
7
  require 'pwsh/version'
6
8
  require 'rspec/core/rake_task'
7
9
  require 'yard'
@@ -10,8 +12,8 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
10
12
  config.user = 'puppetlabs'
11
13
  config.project = 'ruby-pwsh'
12
14
  config.future_release = Pwsh::VERSION
13
- config.since_tag = '0.0.1'
14
- config.exclude_labels = ['maintenance']
15
+ config.since_tag = '0.1.0'
16
+ config.exclude_labels = ['maint']
15
17
  config.header = "# Change log\n\nAll notable changes to this project will be documented in this file." \
16
18
  'The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).'
17
19
  config.add_pr_wo_labels = true
@@ -42,3 +44,59 @@ task default: :spec
42
44
 
43
45
  YARD::Rake::YardocTask.new do |t|
44
46
  end
47
+
48
+ # Executes a command locally.
49
+ #
50
+ # @param command [String] command to execute.
51
+ # @return [Object] the standard out stream.
52
+ def run_local_command(command)
53
+ stdout, stderr, status = Open3.capture3(command)
54
+ error_message = "Attempted to run\ncommand:'#{command}'\nstdout:#{stdout}\nstderr:#{stderr}"
55
+ raise error_message unless status.to_i.zero?
56
+
57
+ stdout
58
+ end
59
+
60
+ # Build the gem
61
+ desc 'Build the gem'
62
+ task :build do
63
+ gemspec_path = File.join(Dir.pwd, 'ruby-pwsh.gemspec')
64
+ # Delete the puppet-specific code if it exists
65
+ FileUtils.rm_r('lib/puppet') if File.exist?('lib/puppet')
66
+ run_local_command("bundle exec gem build '#{gemspec_path}'")
67
+ end
68
+
69
+ # Tag the repo with a version in preparation for the release
70
+ #
71
+ # @param :version [String] a semantic version to tag the code with
72
+ # @param :sha [String] the sha at which to apply the version tag
73
+ desc 'Tag the repo with a version in preparation for release'
74
+ task :tag, [:version, :sha] do |_task, args|
75
+ raise "Invalid version #{args[:version]} - must be like '1.2.3'" unless args[:version] =~ /^\d+\.\d+\.\d+$/
76
+
77
+ run_local_command('git fetch upstream')
78
+ run_local_command("git tag -a version -m #{args[:version]} #{args[:sha]}")
79
+ run_local_command('git push upstream --tags')
80
+ end
81
+
82
+ # Push the built gem to RubyGems
83
+ #
84
+ # @param :path [String] optional, the full or relative path to the built gem to be pushed
85
+ desc 'Push to RubyGems'
86
+ task :push, [:path] do |_task, args|
87
+ raise 'No discoverable gem for pushing' if Dir.glob("ruby-pwsh*\.gem").empty? && args[:path].nil?
88
+ raise "No file found at specified path: '#{args[:path]}'" unless File.exist?(args[:path])
89
+
90
+ path = args[:path] || File.join(Dir.pwd, Dir.glob("ruby-pwsh*\.gem")[0])
91
+ run_local_command("bundle exec gem push #{path}")
92
+ end
93
+
94
+ desc 'Build for Puppet'
95
+ task :build_module do
96
+ actual_readme_content = File.read('README.md')
97
+ FileUtils.copy_file('pwshlib.md', 'README.md')
98
+ # Build
99
+ run_local_command('pdk build --force')
100
+ # Cleanup
101
+ File.open('README.md', 'wb') { |file| file.write(actual_readme_content) }
102
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Manage PowerShell and Windows PowerShell via ruby
3
4
  module Pwsh
4
5
  # Various helper methods
5
6
  module Util
@@ -29,6 +30,94 @@ module Pwsh
29
30
 
30
31
  invalid_paths
31
32
  end
33
+
34
+ # Return a string converted to snake_case
35
+ #
36
+ # @return [String] snake_cased string
37
+ def snake_case(string)
38
+ # Implementation copied from: https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
39
+ # gsub(/::/, '/').
40
+ string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
41
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
42
+ .tr('-', '_')
43
+ .gsub(/\s/, '_')
44
+ .gsub(/__+/, '_')
45
+ .downcase
46
+ end
47
+
48
+ # Iterate through a hashes keys, snake_casing them
49
+ #
50
+ # @return [Hash] Hash with all keys snake_cased
51
+ def snake_case_hash_keys(hash)
52
+ modified_hash = {}
53
+ hash.each do |key, value|
54
+ value = snake_case_hash_keys(value) if value.is_a?(Hash)
55
+ modified_hash[snake_case(key.to_s).to_sym] = value
56
+ end
57
+ modified_hash
58
+ end
59
+
60
+ # Return a string converted to PascalCase
61
+ #
62
+ # @return [String] PascalCased string
63
+ def pascal_case(string)
64
+ # Break word boundaries to snake case first
65
+ snake_case(string).split('_').collect(&:capitalize).join
66
+ end
67
+
68
+ # Iterate through a hashes keys, PascalCasing them
69
+ #
70
+ # @return [Hash] Hash with all keys PascalCased
71
+ def pascal_case_hash_keys(hash)
72
+ modified_hash = {}
73
+ hash.each do |key, value|
74
+ value = pascal_case_hash_keys(value) if value.is_a?(Hash)
75
+ modified_hash[pascal_case(key.to_s).to_sym] = value
76
+ end
77
+ modified_hash
78
+ end
79
+
80
+ # Ensure that quotes inside a passed string will continue to be passed
81
+ #
82
+ # @return [String] the string with quotes escaped
83
+ def escape_quotes(text)
84
+ text.gsub("'", "''")
85
+ end
86
+
87
+ # Convert a ruby value into a string to be passed along to PowerShell for interpolation in a command
88
+ # Handles:
89
+ # - Strings
90
+ # - Numbers
91
+ # - Booleans
92
+ # - Symbols
93
+ # - Arrays
94
+ # - Hashes
95
+ #
96
+ # @return [String] representation of the value for interpolation
97
+ def format_powershell_value(object)
98
+ if %i[true false].include?(object) || %w[trueclass falseclass].include?(object.class.name.downcase) # rubocop:disable Lint/BooleanSymbol
99
+ "$#{object}"
100
+ elsif object.class.name == 'Symbol' || object.class.ancestors.include?(Numeric)
101
+ object.to_s
102
+ elsif object.class.name == 'String'
103
+ "'#{escape_quotes(object)}'"
104
+ elsif object.class.name == 'Array'
105
+ '@(' + object.collect { |item| format_powershell_value(item) }.join(', ') + ')'
106
+ elsif object.class.name == 'Hash'
107
+ '@{' + object.collect { |k, v| format_powershell_value(k) + ' = ' + format_powershell_value(v) }.join('; ') + '}'
108
+ else
109
+ raise "unsupported type #{object.class} of value '#{object}'"
110
+ end
111
+ end
112
+
113
+ # Return the representative string of a PowerShell hash for a custom object property to be used in selecting or filtering.
114
+ # The script block for the expression must be passed as the string you want interpolated into the hash; this method does
115
+ # not do any of the additional work of interpolation for you as the type sits inside a code block inside a hash.
116
+ #
117
+ # @return [String] representation of a PowerShell hash with the keys 'Name' and 'Expression'
118
+ def custom_powershell_property(name, expression)
119
+ "@{Name = '#{name}'; Expression = {#{expression}}}"
120
+ end
32
121
  end
33
122
  end
34
123
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Pwsh
4
4
  # The version of the ruby-pwsh gem
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "puppetlabs-pwshlib",
3
+ "version": "0.2.0",
4
+ "author": "puppetlabs",
5
+ "summary": "Provide library code for interoperating with PowerShell.",
6
+ "license": "MIT",
7
+ "source": "https://github.com/puppetlabs/ruby-pwsh",
8
+ "project_page": "https://github.com/puppetlabs/ruby-pwsh/pwshlib.md",
9
+ "issues_url": "https://github.com/puppetlabs/ruby-pwsh/issues",
10
+ "dependencies": [
11
+
12
+ ],
13
+ "operatingsystem_support": [
14
+ {
15
+ "operatingsystem": "CentOS",
16
+ "operatingsystemrelease": [
17
+ "7"
18
+ ]
19
+ },
20
+ {
21
+ "operatingsystem": "OracleLinux",
22
+ "operatingsystemrelease": [
23
+ "7"
24
+ ]
25
+ },
26
+ {
27
+ "operatingsystem": "RedHat",
28
+ "operatingsystemrelease": [
29
+ "8"
30
+ ]
31
+ },
32
+ {
33
+ "operatingsystem": "Scientific",
34
+ "operatingsystemrelease": [
35
+ "7"
36
+ ]
37
+ },
38
+ {
39
+ "operatingsystem": "Debian",
40
+ "operatingsystemrelease": [
41
+ "9"
42
+ ]
43
+ },
44
+ {
45
+ "operatingsystem": "Ubuntu",
46
+ "operatingsystemrelease": [
47
+ "18.04"
48
+ ]
49
+ },
50
+ {
51
+ "operatingsystem": "windows",
52
+ "operatingsystemrelease": [
53
+ "2019",
54
+ "10"
55
+ ]
56
+ },
57
+ {
58
+ "operatingsystem": "SLES",
59
+ "operatingsystemrelease": [
60
+ "15"
61
+ ]
62
+ },
63
+ {
64
+ "operatingsystem": "Darwin",
65
+ "operatingsystemrelease": [
66
+ "16"
67
+ ]
68
+ },
69
+ {
70
+ "operatingsystem": "Fedora",
71
+ "operatingsystemrelease": [
72
+ "29"
73
+ ]
74
+ }
75
+ ],
76
+ "requirements": [
77
+ {
78
+ "name": "puppet",
79
+ "version_requirement": ">= 4.10.0 < 7.0.0"
80
+ }
81
+ ],
82
+ "pdk-version": "1.13.0",
83
+ "template-url": "pdk-default#1.13.0",
84
+ "template-ref": "1.13.0-0-g66e1443"
85
+ }
@@ -0,0 +1,90 @@
1
+ # pwshlib
2
+
3
+ This module enables you to leverage the `ruby-pwsh` gem to execute PowerShell from within your Puppet providers without having to instantiate and tear down a PowerShell process for each command called.
4
+ It supports Windows PowerShell as well as PowerShell Core - if you're running **PowerShell v3+**, this gem supports you.
5
+
6
+ The `Manager` class enables you to execute and interoperate with PowerShell from within ruby, leveraging the strengths of both languages as needed.
7
+
8
+ ## Prerequisites
9
+
10
+ Include `puppetlabs-pwshlib` as a dependency in your module and you can leverage it in your providers by using a requires statement, such as in this example:
11
+
12
+ ```ruby
13
+ require 'puppet/resource_api/simple_provider'
14
+ begin
15
+ require 'ruby-pwsh'
16
+ rescue LoadError
17
+ raise 'Could not load the "ruby-pwsh" library; is the dependency module puppetlabs-pwshlib installed in this environment?'
18
+ end
19
+
20
+ # Implementation for the foo type using the Resource API.
21
+ class Puppet::Provider::Foo::Foo < Puppet::ResourceApi::SimpleProvider
22
+ def get(context)
23
+ context.debug("PowerShell Path: #{Pwsh::Manager.powershell_path}")
24
+ context.debug('Returning pre-canned example data')
25
+ [
26
+ {
27
+ name: 'foo',
28
+ ensure: 'present',
29
+ },
30
+ {
31
+ name: 'bar',
32
+ ensure: 'present',
33
+ },
34
+ ]
35
+ end
36
+
37
+ def create(context, name, should)
38
+ context.notice("Creating '#{name}' with #{should.inspect}")
39
+ end
40
+
41
+ def update(context, name, should)
42
+ context.notice("Updating '#{name}' with #{should.inspect}")
43
+ end
44
+
45
+ def delete(context, name)
46
+ context.notice("Deleting '#{name}'")
47
+ end
48
+ end
49
+ ```
50
+
51
+ Aside from adding it as a dependency to your module metadata, you will probably also want to include it in your `.fixtures.yml` file:
52
+
53
+ ```yaml
54
+ fixtures:
55
+ forge_modules:
56
+ pwshlib: "puppetlabs/pwshlib"
57
+ ```
58
+
59
+ ## Using the Library
60
+
61
+ Instantiating the manager can be done using some defaults:
62
+
63
+ ```ruby
64
+ # Instantiate the manager for Windows PowerShell, using the default path and arguments
65
+ # Note that this takes a few seconds to instantiate.
66
+ posh = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
67
+ # If you try to create another manager with the same arguments it will reuse the existing one.
68
+ ps = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
69
+ # Note that this time the return is very fast.
70
+ # We can also use the defaults for PowerShell Core, though these only work if PowerShell is
71
+ # installed to the default paths - if it is installed anywhere else, you'll need to specify
72
+ # the full path to the pwsh executable.
73
+ pwsh = Pwsh::Manager.instance(Pwsh::Manager.pwsh_path, Pwsh::Manager.pwsh_args)
74
+ ```
75
+
76
+ Execution can be done with relatively little additional work - pass the command string you want executed:
77
+
78
+ ```ruby
79
+ # Instantiate the Manager:
80
+ posh = Pwsh::Manager.instance(Pwsh::Manager.powershell_path, Pwsh::Manager.powershell_args)
81
+ # Pretty print the output of `$PSVersionTable` to validate the version of PowerShell running
82
+ # Note that the output is a hash with a few different keys, including stdout.
83
+ Puppet.debug(posh.execute('$PSVersionTable'))
84
+ # Lets reduce the noise a little and retrieve just the version number:
85
+ # Note: We cast to a string because PSVersion is actually a Version object.
86
+ Puppet.debug(posh.execute('[String]$PSVersionTable.PSVersion'))
87
+ # We could store this output to a ruby variable if we wanted, for further use:
88
+ ps_version = posh.execute('[String]$PSVersionTable.PSVersion')[:stdout].strip
89
+ Puppet.debug("The PowerShell version of the currently running Manager is #{ps_version}")
90
+ ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pwsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-25 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email:
@@ -19,10 +19,13 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitattributes"
21
21
  - ".gitignore"
22
+ - ".pmtignore"
22
23
  - ".rspec"
23
24
  - ".rubocop.yml"
24
25
  - ".travis.yml"
26
+ - CHANGELOG.md
25
27
  - CODEOWNERS
28
+ - CONTRIBUTING.md
26
29
  - DESIGN.md
27
30
  - Gemfile
28
31
  - LICENSE.txt
@@ -35,6 +38,8 @@ files:
35
38
  - lib/pwsh/windows_powershell.rb
36
39
  - lib/ruby-pwsh.rb
37
40
  - lib/templates/init.ps1
41
+ - metadata.json
42
+ - pwshlib.md
38
43
  - ruby-pwsh.gemspec
39
44
  homepage: https://github.com/puppetlabs/ruby-pwsh
40
45
  licenses: