From 39dd82eb7eb7c67df9fe2ecdb2709b6a3db32cc4 Mon Sep 17 00:00:00 2001 From: Alexander Schaber Date: Mon, 24 Apr 2023 14:08:19 +0200 Subject: [PATCH 1/3] ci: add ruby and dependabot configuration --- .github/PULL_REQUEST_TEMPLATE.md | 12 +++++ .github/dependabot.yml | 31 ++++++++++++ .github/workflows/codeql.yml | 76 +++++++++++++++++++++++++++++ .github/workflows/publishdocker.yml | 22 +++++++++ .github/workflows/ruby.yml | 42 ++++++++++++++++ .github/workflows/stale.yml | 16 ++++++ 6 files changed, 199 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/publishdocker.yml create mode 100644 .github/workflows/ruby.yml create mode 100644 .github/workflows/stale.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..869b4a9 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## Pre-Request Checklist + + +- [ ] Passes rubocop code analysis (try `rubocop --auto-correct`) +- [ ] Tests added or adapted (try `rake test`) +- [ ] Changes are reflected in the documentation +- [ ] User-visible changes appended to [CHANGELOG.md](/CHANGELOG.md) + +## Description + + + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..68ef615 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,31 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + target-branch: "master" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + labels: + - dependencies + - package-ecosystem: "bundler" + target-branch: "master" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + labels: + - dependencies + - package-ecosystem: "docker" + target-branch: "master" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + labels: + - dependencies diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..09643e8 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,76 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '44 21 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'ruby' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/publishdocker.yml b/.github/workflows/publishdocker.yml new file mode 100644 index 0000000..25000e1 --- /dev/null +++ b/.github/workflows/publishdocker.yml @@ -0,0 +1,22 @@ +name: Publish Docker +on: + push: + branches: [ "master" ] +jobs: + build: + if: github.repository_owner == 'ytti' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + fetch-depth: 0 + - name: Get Release Version + id: get_version + run: echo "release-version=$(git describe --tags)" >> $GITHUB_OUTPUT + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: oxidized/oxidized + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + tags: "latest,${{ steps.get_version.outputs.release-version }}" diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..b4e80dc --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,42 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: CI + +on: [ push, pull_request ] +# push: +# branches: [ master ] +# pull_request: +# branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.7', '3.0', '3.1', '3.2'] + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: rubocop + uses: reviewdog/action-rubocop@v2 + with: + rubocop_version: gemfile + rubocop_extensions: rubocop-minitest:gemfile rubocop-rake:gemfile + reporter: github-pr-review + - name: Run tests + run: bundle exec rake + - uses: codecov/codecov-action@v3 + if: ${{ always() }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..d6b9073 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,16 @@ +name: "Stale Issue/PR cleanup" +on: + schedule: + - cron: "30 1 * * *" + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v8 + with: + operations-per-run: 500 From 298bbc2fff185a55357afaac37023552214040c7 Mon Sep 17 00:00:00 2001 From: Alexander Schaber Date: Mon, 24 Apr 2023 14:09:34 +0200 Subject: [PATCH 2/3] build: align rakefile with `oxidized` as much as possible --- .gitignore | 2 +- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 7 ------- Rakefile | 2 +- oxidized-script.gemspec | 18 ++++++++++++++---- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 58ceadc..aca9077 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ Gemfile.lock -gems +pkg *.swp diff --git a/.rubocop.yml b/.rubocop.yml index 28cedcc..5664ea0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,9 @@ inherit_from: .rubocop_todo.yml +AllCops: + NewCops: enable + TargetRubyVersion: 2.7 + Lint/RaiseException: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a5d335f..37abc89 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -60,13 +60,6 @@ Layout/SpaceAroundOperators: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -Layout/Tab: - Exclude: - - 'lib/oxidized/script/script.rb' - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/Rakefile b/Rakefile index 9586ca6..2e27c9c 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ end desc 'Install gem' task install: :build do - system "sudo -Es sh -c \'umask 022; gem install gems/#{gemfile}\'" + system "sudo -Es sh -c 'umask 022; gem install gems/#{gemfile}'" end task build: :chmod diff --git a/oxidized-script.gemspec b/oxidized-script.gemspec index ebd7ab5..a4afc6d 100644 --- a/oxidized-script.gemspec +++ b/oxidized-script.gemspec @@ -8,13 +8,23 @@ Gem::Specification.new do |s| s.homepage = 'http://github.com/ytti/oxidized-script' s.summary = 'cli + library for scripting network devices' s.description = 'rancid clogin-like script to push configs to devices + library interface to do same' - s.files = `git ls-files`.split("\n") + s.files = `git ls-files -z`.split("\x0") s.executables = %w[oxs] s.require_path = 'lib' + s.metadata['rubygems_mfa_required'] = 'true' + + s.required_ruby_version = '>= 2.7' + s.add_runtime_dependency 'oxidized', '~> 0.28' s.add_runtime_dependency 'slop', '~> 4.6' - s.add_development_dependency 'bundler', '~> 2.0' - s.add_development_dependency 'rake', '~> 10.0' - s.add_development_dependency 'rubocop', '~> 0.81.0' + + s.add_development_dependency 'bundler', '~> 2.2' + s.add_development_dependency 'rake', '~> 13.0' + s.add_development_dependency 'rubocop', '~> 1.48.0' + s.add_development_dependency 'rubocop-minitest', '~> 0.29.0' + s.add_development_dependency 'rubocop-rake', '~> 0.6.0' + s.add_development_dependency 'simplecov', '~> 0.22.0' + s.add_development_dependency 'simplecov-cobertura', '~> 2.1.0' + s.add_development_dependency 'simplecov-html', '~> 0.12.3' end From 7237ebbf3dacf754fa163c93105d876146c054e0 Mon Sep 17 00:00:00 2001 From: Alexander Schaber Date: Mon, 24 Apr 2023 14:10:52 +0200 Subject: [PATCH 3/3] refactor: fix rubocop warnings --- .rubocop.yml | 3 + .rubocop_todo.yml | 161 +++++++++++++++++++++------------- lib/oxidized/script/cli.rb | 21 ++--- lib/oxidized/script/script.rb | 14 ++- 4 files changed, 118 insertions(+), 81 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5664ea0..6d8afd4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,3 +19,6 @@ Style/HashTransformKeys: Style/HashTransformValues: Enabled: true +require: + - rubocop-rake + - rubocop-minitest diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37abc89..7bb4154 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,27 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-05-18 14:23:29 +0200 using RuboCop version 0.81.0. +# on 2023-04-24 12:11:41 UTC using RuboCop version 1.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 5 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterGuardClause: Exclude: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/commands/list-nodes.rb' - 'lib/oxidized/script/script.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'lib/oxidized/script/script.rb' - # Offense count: 3 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only Layout/EmptyLinesAroundClassBody: @@ -30,8 +24,8 @@ Layout/EmptyLinesAroundClassBody: - 'lib/oxidized/script/commands/list-models.rb' - 'lib/oxidized/script/commands/list-nodes.rb' -# Offense count: 2 -# Cop supports --auto-correct. +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. Layout/ExtraSpacing: Exclude: @@ -39,20 +33,20 @@ Layout/ExtraSpacing: - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Layout/SpaceAfterComma: Exclude: - 'lib/oxidized/script/cli.rb' # Offense count: 4 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: . # SupportedStyles: space, no_space Layout/SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space -# Offense count: 13 -# Cop supports --auto-correct. +# Offense count: 12 +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. # SupportedStylesForExponentOperator: space, no_space Layout/SpaceAroundOperators: @@ -60,29 +54,32 @@ Layout/SpaceAroundOperators: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: runtime_error, standard_error -Lint/InheritException: +# Offense count: 1 +# Configuration parameters: AllowComments. +Lint/EmptyClass: Exclude: - - 'lib/oxidized/script/cli.rb' - - 'lib/oxidized/script/script.rb' + - 'lib/oxidized/script/command.rb' + +# Offense count: 2 +Lint/MissingSuper: + Exclude: + - 'lib/oxidized/script/commands/list-models.rb' + - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Lint/RedundantStringCoercion: Exclude: - 'lib/oxidized/script/cli.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Lint/ScriptPermission: Exclude: - 'lib/oxidized/script/script.rb' # Offense count: 2 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: @@ -94,30 +91,36 @@ Lint/UselessAssignment: Exclude: - 'lib/oxidized/script/script.rb' -# Offense count: 5 -# Configuration parameters: IgnoredMethods. +# Offense count: 6 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 48 + Max: 54 # Offense count: 1 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 31 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 163 + Max: 168 # Offense count: 4 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: - Max: 17 + Max: 18 # Offense count: 8 -# Configuration parameters: CountComments, ExcludedMethods. +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 44 # Offense count: 4 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 17 + Max: 18 # Offense count: 1 Naming/AccessorMethodName: @@ -131,7 +134,8 @@ Naming/ConstantName: - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 2 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: Exclude: @@ -139,7 +143,7 @@ Naming/FileName: - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 3 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredName. Naming/RescuedExceptionsVariableName: Exclude: @@ -147,13 +151,19 @@ Naming/RescuedExceptionsVariableName: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Rake/Desc: + Exclude: + - 'Rakefile' + # Offense count: 1 Security/Eval: Exclude: - 'Rakefile' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: prefer_alias, prefer_alias_method Style/Alias: @@ -161,7 +171,7 @@ Style/Alias: - 'lib/oxidized/script/script.rb' # Offense count: 8 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals Style/AndOr: @@ -169,12 +179,12 @@ Style/AndOr: - 'lib/oxidized/script/cli.rb' # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object # FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it +# AllowedMethods: lambda, proc, it Style/BlockDelimiters: Exclude: - 'lib/oxidized/script/cli.rb' @@ -185,7 +195,7 @@ Style/ClassVars: - 'lib/oxidized/script/script.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerBackticks. # SupportedStyles: backticks, percent_x, mixed Style/CommandLiteral: @@ -193,6 +203,7 @@ Style/CommandLiteral: - 'Rakefile' # Offense count: 7 +# Configuration parameters: AllowedConstants. Style/Documentation: Exclude: - 'spec/**/*' @@ -203,7 +214,7 @@ Style/Documentation: - 'lib/oxidized/script/script.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: @@ -211,7 +222,7 @@ Style/EmptyMethod: - 'lib/oxidized/script/commands/list-models.rb' # Offense count: 2 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: format, sprintf, percent Style/FormatString: @@ -220,13 +231,14 @@ Style/FormatString: - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 4 -# Configuration parameters: . +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: EnforcedStyle: unannotated # Offense count: 10 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: @@ -243,28 +255,30 @@ Style/FrozenStringLiteralComment: - 'oxidized-script.gemspec' # Offense count: 1 -# Configuration parameters: MinBodyLength. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: Exclude: - 'lib/oxidized/script/script.rb' # Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# SupportedShorthandSyntax: always, never, either, consistent Style/HashSyntax: Exclude: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' -# Offense count: 1 -# Cop supports --auto-correct. +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: Exclude: - 'lib/oxidized/script/cli.rb' # Offense count: 9 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline Style/MethodDefParentheses: @@ -275,7 +289,7 @@ Style/MethodDefParentheses: - 'lib/oxidized/script/script.rb' # Offense count: 4 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: literals, strict Style/MutableConstant: @@ -284,7 +298,7 @@ Style/MutableConstant: - 'lib/oxidized/script/commands/list-nodes.rb' # Offense count: 2 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: both, prefix, postfix Style/NegatedIf: @@ -292,20 +306,27 @@ Style/NegatedIf: - 'lib/oxidized/script/script.rb' # Offense count: 8 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). Style/Not: Exclude: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowComments. +Style/RedundantInitialize: + Exclude: + - 'lib/oxidized/script/commands/list-models.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: Exclude: - 'bin/oxs' # Offense count: 3 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit Style/RescueStandardError: @@ -314,8 +335,22 @@ Style/RescueStandardError: - 'lib/oxidized/script/cli.rb' - 'lib/oxidized/script/script.rb' +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/SlicingWithRange: + Exclude: + - 'lib/oxidized/script/commands/list-nodes.rb' + # Offense count: 3 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'Rakefile' + - 'lib/oxidized/script/cli.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: @@ -323,15 +358,15 @@ Style/StringLiterals: - 'lib/oxidized/script/cli.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets -# Offense count: 18 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https Layout/LineLength: Max: 128 diff --git a/lib/oxidized/script/cli.rb b/lib/oxidized/script/cli.rb index 2b30796..519de12 100644 --- a/lib/oxidized/script/cli.rb +++ b/lib/oxidized/script/cli.rb @@ -5,6 +5,7 @@ module Oxidized class Script class CLI attr_accessor :cmd_class + class CLIError < ScriptError; end class NothingToDo < ScriptError; end @@ -92,10 +93,10 @@ def opts_parse cmds opt.string '-c', '--community', 'snmp community to use for discovery' opt.string '-g', '--group', 'group to run commands on (ios, junos, etc), specified in oxidized db' opt.int '-r', '--threads', 'specify ammount of threads to use for running group', default: '1' - opt.string '--regex', 'run on all hosts that match the regexp' - opt.on '--dryrun', 'do a dry run on either groups or regexp to find matching hosts' - opt.string '--protocols','protocols to use, default "ssh, telnet"' - opt.on '--no-trim', 'Dont trim newlines and whitespace when running commands' + opt.string '--regex', 'run on all hosts that match the regexp' + opt.on '--dryrun', 'do a dry run on either groups or regexp to find matching hosts' + opt.string '--protocols','protocols to use, default "ssh, telnet"' + opt.on '--no-trim', 'Dont trim newlines and whitespace when running commands' opt.on '-v', '--verbose', 'verbose output, e.g. show commands sent' opt.on '-d', '--debug', 'turn on debugging' opt.on :terse, 'display clean output' @@ -157,14 +158,14 @@ def load_dynamic def get_hosts puts "running list for hosts" if @verbose - if @group - puts " - in group: #{@group}" if @verbose + if @group && @verbose + puts " - in group: #{@group}" end - if @ostype - puts " - (and) matching ostype: #{@ostype}" if @verbose + if @ostype && @verbose + puts " - (and) matching ostype: #{@ostype}" end - if @regex - puts " - (and) matching: #{@regex}" if @verbose + if @regex && @verbose + puts " - (and) matching: #{@regex}" end Oxidized.mgr = Manager.new out = [] diff --git a/lib/oxidized/script/script.rb b/lib/oxidized/script/script.rb index ef736f1..cde2aab 100644 --- a/lib/oxidized/script/script.rb +++ b/lib/oxidized/script/script.rb @@ -9,11 +9,11 @@ class Script class ScriptError < OxidizedError; end class NoNode < ScriptError; end class InvalidOption < ScriptError; end + class NoConnection < ScriptError attr_accessor :node_error end - # @param [String] command command to be sent # @return [String] output for command def cmd command @@ -99,13 +99,11 @@ def initialize opts, &block def connect node_error = {} @node.input.each do |input| - begin - @node.model.input = input.new - @node.model.input.connect @node - break - rescue => error - node_error[input] = error - end + @node.model.input = input.new + @node.model.input.connect @node + break + rescue => error + node_error[input] = error end @input = @node.model.input err = NoConnection.new