New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspec-init plugin: generate inspec plugins #3629

Merged
merged 18 commits into from Feb 6, 2019

Conversation

Projects
None yet
4 participants
@clintoncwolfe
Copy link
Contributor

clintoncwolfe commented Nov 26, 2018

This PR introduces a new subcommand to inspec init: plugin.

inspec init plugin features a broad suite of CLI options that are used to parameterize the generated plugin. Additionally, this PR relies on the UI functionality introduced in #3618 to provide a sleek interactive experience, in which the parameters are entered interactively.

The generated plugin may be generated at three levels of detail:

  • 'full' - typical for an external project; includes things like a Rakefile, Gemspec, etc.
  • 'core' - typical for an InSpec core plugin; includes tests, but omits gemspec, etc.
  • 'test-fixture' - typical for a test-fixture plugin - omits all topmatter and all tests.

This PR extends the code generator in several ways:

  • Don't assume we're generating a profile
  • Allow files to be renamed during the templating process
  • Allow files to be omitted during the templating process

Modest functional tests are included.

Note about diff size: This PR appears large, but a lot of that is due to it containing templates for the plugin files. Those files are actually copies of the plugin example, which had already been reviewed and merged; the only modification is that they are now parameterized with ERB blocks.

@jerryaldrichiii
Copy link
Contributor

jerryaldrichiii left a comment

Looks great @clintoncwolfe just a few changes! Let me know if the suggestion feature is too cumbersome. Thanks for demoing this and making the review easier.

Show resolved Hide resolved lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb Outdated
Show resolved Hide resolved lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb Outdated
Show resolved Hide resolved lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb
Show resolved Hide resolved lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb
Show resolved Hide resolved lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb
# a PR that creates a failing functional test is a great way to
# capture the reproduction case.
# The simplest case:
describe "when run without an argument" do

This comment has been minimized.

@jerryaldrichiii

jerryaldrichiii Dec 26, 2018

Contributor

Mixing of double and single quotes throughout makes me 😢...but I'll just make a mental note and fix it at some other date.

This comment has been minimized.

@clintoncwolfe

clintoncwolfe Dec 28, 2018

Author Contributor

As rubocop did not complain, the team has agreed it is not worth maintaining a set standard. Please do not put time into it.

Show resolved Hide resolved ...gins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb Outdated
Show resolved Hide resolved lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb
Show resolved Hide resolved lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb
Show resolved Hide resolved lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb

Whitespace and capitalization feedback, non-blocker

@clintoncwolfe clintoncwolfe force-pushed the cw/init-plugin branch 2 times, most recently from 43493c7 to f7556d7 Jan 5, 2019

option :author_name, type: :string, default: 'Your Name', desc: 'Author Name for gemspec'
option :description, type: :string, default: '', desc: 'Multi-line description of the plugin'
option :summary, type: :string, default: 'A plugin with a default summary', desc: 'One-line summary of your plugin'
option :license_name, type: :string, default: 'Apache-2.0', desc: 'The name of a license'

This comment has been minimized.

@marcparadise

marcparadise Feb 4, 2019

When the user provides --license-name we don't restrict it to the licenses we have text for. That will let them supply their own license, but if they typo the license name they won't necessarily know that their generated LICENSE file contains a friendly message telling them to supply text.

To provide a better UX, could we emit something to the UI indicating that the license $name was not found, and they'd need to update license.md with their own license?

This comment has been minimized.

@clintoncwolfe

clintoncwolfe Feb 6, 2019

Author Contributor

OK, I've added a reminder if the user chooses Other:

screen shot 2019-02-06 at 12 10 14
screen shot 2019-02-06 at 12 10 24

clintoncwolfe added some commits Nov 16, 2018

Move templates dir outside of lib
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Make UI not print emphasis by default
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Allow no args to plain_line
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Adapt to new UI module
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Split the CLI implementation file
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Basic template, not parameterized
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Add ability to remap filenames
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Enough options to cover gemspec
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
support for LICENSE
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
All templates work, but need to decide on hooks
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Templatize everything for InSpec plugins
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Add interactive prompting
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Add detail option, to make stripped-down plugins
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Exempt inspec-init template file from rubocop, and enable DisplayCopN…
…ames by default

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
linting
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
PR feedback on product capitalization
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Correct functional test
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Add a UX reminder to update the license
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>

@clintoncwolfe clintoncwolfe force-pushed the cw/init-plugin branch from f7556d7 to b831083 Feb 6, 2019

@jerryaldrichiii
Copy link
Contributor

jerryaldrichiii left a comment

Looks good to me @clintoncwolfe. I did find a grammar error in one of the generated files, but I won't block the PR over it.


The generated plugin contains everything a real-world, industrial grade plugin would have, including:

* an (possibly incomplete) implementation of one or more InSpec Plugin Types

This comment has been minimized.

@jerryaldrichiii

jerryaldrichiii Feb 6, 2019

Contributor

Should be a (possibly

@clintoncwolfe clintoncwolfe merged commit 05a011f into master Feb 6, 2019

4 checks passed

DCO This commit has a DCO Signed-off-by
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
expeditor/config-validation Validated your Expeditor config file
Details

@clintoncwolfe clintoncwolfe deleted the cw/init-plugin branch Feb 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment