system_command 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17d5804e3398846f17e91e8b17810c4eec250075f778323d7720248ff1989de9
4
+ data.tar.gz: d501f75ca3bc25fcc8cd6af226e8e02149258746513b5fae58f182e866c475e1
5
+ SHA512:
6
+ metadata.gz: 14634afaced6e4009b35bc1eb4d8e167b7db2a068ddfa2563a8518a786e4e90b39b28258860fdfcf20100290fbc7c31adfa8adf505da43ff599c0db2c22ca46e
7
+ data.tar.gz: 6eb7d58bc91aac42861f5368f026bfece3279e8bcbd4ce31249048224cd1e06d0220a4cd85ac11b6a71c8f20a9f3c59e8f2de3979cc19463657440c336d7c695
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_from: .rubocop_coldwater.yml
2
+ require:
3
+ - rubocop-rspec
@@ -0,0 +1,92 @@
1
+ ### Coldwater Systems Style Guide ##############################################
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+ TargetRubyVersion: 3.2.0
6
+
7
+ # The default of special_inside_parentheses involves too much indentation in
8
+ # many cases.
9
+ Layout/FirstArrayElementIndentation:
10
+ EnforcedStyle: consistent
11
+ Layout/FirstHashElementIndentation:
12
+ EnforcedStyle: consistent
13
+
14
+ # Stylistic preference that we think improves readability of complex hashes.
15
+ Layout/HashAlignment:
16
+ EnforcedHashRocketStyle: table
17
+ EnforcedColonStyle: table
18
+
19
+ # Trailing comma makes editing multi-line literals slightly easier since lines
20
+ # can be re-ordered, added, or removed without touching commas.
21
+ Style/TrailingCommaInArrayLiteral:
22
+ EnforcedStyleForMultiline: comma
23
+ Style/TrailingCommaInHashLiteral:
24
+ EnforcedStyleForMultiline: comma
25
+
26
+ # Space inside braces is reserved for single line blocks.
27
+ Layout/SpaceInsideHashLiteralBraces:
28
+ EnforcedStyle: no_space
29
+
30
+ # I like the way it looks for block params to be attached to the opening brace.
31
+ Layout/SpaceInsideBlockBraces:
32
+ SpaceBeforeBlockParameters: false
33
+
34
+ # It feels safer and easier to read if math operators are preferred.
35
+ Style/NumericPredicate:
36
+ EnforcedStyle: comparison
37
+
38
+ # %i[] is rarely seen and I think obfuscates the fact that symbols are involved.
39
+ Style/SymbolArray:
40
+ EnforcedStyle: brackets
41
+
42
+ # It pays to be direct, and oftentimes module names are shorter than "described_class"
43
+ RSpec/DescribedClass:
44
+ EnforcedStyle: explicit
45
+
46
+ # It feels more consistent with `be false` and `be true`
47
+ RSpec/BeNil:
48
+ EnforcedStyle: be
49
+
50
+ ### Opt-ins ####################################################################
51
+
52
+ Layout/EmptyLineAfterMultilineCondition:
53
+ Enabled: true
54
+ Layout/HeredocArgumentClosingParenthesis:
55
+ Enabled: true
56
+ Lint/NumberConversion:
57
+ Enabled: true
58
+ Lint/HeredocMethodCallPosition:
59
+ Enabled: true
60
+ Style/AutoResourceCleanup:
61
+ Enabled: true
62
+ Style/RequireOrder:
63
+ Enabled: true
64
+ Lint/Void:
65
+ CheckForMethodsWithNoSideEffects: true
66
+
67
+ ### Opt-outs ###################################################################
68
+
69
+ # Can be useful as a guideline but most of these just contribute to noise.
70
+ Metrics:
71
+ Enabled: false
72
+
73
+ # Would be nice if this caught uncommon operator combinations but this also
74
+ # lints PEMDAS operators.
75
+ Lint/AmbiguousOperatorPrecedence:
76
+ Enabled: false
77
+
78
+ # Oftentimes there's a whole block of oneline getters, and it looks weird to
79
+ # have them double spaced.
80
+ Layout/EmptyLineBetweenDefs:
81
+ AllowAdjacentOneLineDefs: true
82
+
83
+ # Don't flag single statement bodies because these often guards, and reworking
84
+ # the code to not trigger this cop usually produces worse results in that case.
85
+ Style/GuardClause:
86
+ MinBodyLength: 2
87
+
88
+ # Don't flag numbers below 1 million because often times numbers below this are
89
+ # often port numbers, which look weird when underscored. Above 1 million, the
90
+ # underscore separators become very important for readability.
91
+ Style/NumericLiterals:
92
+ MinDigits: 7
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "rdbg",
6
+ "name": "rspec",
7
+ "request": "launch",
8
+ "cwd": "${workspaceFolder}",
9
+ "script": "bin/rspec",
10
+ },
11
+ ]
12
+ }
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in system_command.gemspec
6
+ gemspec
7
+
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rubocop', '~> 1.21'
10
+ gem 'rubocop-rspec', '~> 2.23'
11
+ gem 'simplecov', '~> 0.22.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ system_command (2.0.2)
5
+ colorize (~> 1.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ base64 (0.1.1)
12
+ colorize (1.1.0)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ json (2.6.3)
16
+ language_server-protocol (3.17.0.3)
17
+ parallel (1.23.0)
18
+ parser (3.2.2.3)
19
+ ast (~> 2.4.1)
20
+ racc
21
+ racc (1.7.1)
22
+ rainbow (3.1.1)
23
+ regexp_parser (2.8.1)
24
+ rexml (3.2.6)
25
+ rspec (3.12.0)
26
+ rspec-core (~> 3.12.0)
27
+ rspec-expectations (~> 3.12.0)
28
+ rspec-mocks (~> 3.12.0)
29
+ rspec-core (3.12.2)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-expectations (3.12.3)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-mocks (3.12.6)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-support (3.12.1)
38
+ rubocop (1.56.2)
39
+ base64 (~> 0.1.1)
40
+ json (~> 2.3)
41
+ language_server-protocol (>= 3.17.0)
42
+ parallel (~> 1.10)
43
+ parser (>= 3.2.2.3)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ regexp_parser (>= 1.8, < 3.0)
46
+ rexml (>= 3.2.5, < 4.0)
47
+ rubocop-ast (>= 1.28.1, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 2.4.0, < 3.0)
50
+ rubocop-ast (1.29.0)
51
+ parser (>= 3.2.1.0)
52
+ rubocop-capybara (2.18.0)
53
+ rubocop (~> 1.41)
54
+ rubocop-factory_bot (2.23.1)
55
+ rubocop (~> 1.33)
56
+ rubocop-rspec (2.23.2)
57
+ rubocop (~> 1.33)
58
+ rubocop-capybara (~> 2.17)
59
+ rubocop-factory_bot (~> 2.22)
60
+ ruby-progressbar (1.13.0)
61
+ simplecov (0.22.0)
62
+ docile (~> 1.1)
63
+ simplecov-html (~> 0.11)
64
+ simplecov_json_formatter (~> 0.1)
65
+ simplecov-html (0.12.3)
66
+ simplecov_json_formatter (0.1.4)
67
+ unicode-display_width (2.4.2)
68
+
69
+ PLATFORMS
70
+ x86_64-linux
71
+
72
+ DEPENDENCIES
73
+ rspec (~> 3.0)
74
+ rubocop (~> 1.21)
75
+ rubocop-rspec (~> 2.23)
76
+ simplecov (~> 0.22.0)
77
+ system_command!
78
+
79
+ BUNDLED WITH
80
+ 2.4.22
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SystemCommand
2
+
3
+ `SystemCommand` allows you to run external process as if they were functions.
4
+
5
+ ## Usage
6
+
7
+ TODO: Write usage instructions here
8
+
9
+ ## Development
10
+
11
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests.
12
+
13
+ To install this gem onto your local machine, run `rake install`.
14
+
15
+ To release a new version:
16
+
17
+ - Switch to the `main` branch.
18
+ - Bump `lib/system_command/version.rb`, run `bundle install`, then commit the result.
19
+ - Switch to the `v2` branch.
20
+ - Run `git merge main`
21
+ - Run `rake release`, which will create/push a git tag and publish the `.gem`
22
+ file to [rubygems.org].
23
+
24
+ [rubygems.org]: https://rubygems.org
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitLab at <https://gitlab.com/coldwater-systems/system_command>.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'bundler/gem_tasks'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SystemCommand
4
+ VERSION = '2.0.2'
5
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorized_string'
4
+ require 'shellwords'
5
+
6
+ # Allows you to run external process with syntax a little bit more polished than
7
+ # the ruby built-ins.
8
+ #
9
+ # Turn an external process into a class:
10
+ #
11
+ # git = SystemCommand.new('git')
12
+ # git.run('status')
13
+ class SystemCommand
14
+ Error = Class.new(StandardError)
15
+
16
+ class << self
17
+ def verbose?
18
+ @verbose ||= false
19
+ end
20
+
21
+ attr_writer :verbose
22
+
23
+ def run?(*, **)
24
+ argv0, *argv = coerce_argv(*)
25
+
26
+ puts_command argv0, argv
27
+ system([argv0, argv0], *argv, **)
28
+ end
29
+
30
+ def run(*, **)
31
+ argv0, *argv = coerce_argv(*)
32
+
33
+ puts_command argv0, argv
34
+ system([argv0, argv0], *argv, **)
35
+ raise SystemCommand::Error, "#{argv0} failed (#{Process.last_status})" unless Process.last_status.success?
36
+
37
+ nil
38
+ end
39
+
40
+ def gets(*, **)
41
+ argv0, *argv = coerce_argv(*)
42
+
43
+ puts_command argv0, argv
44
+ result = IO.popen([argv0, *argv], **, &:read)
45
+ raise SystemCommand::Error, "#{argv0} failed (#{Process.last_status})" unless Process.last_status.success?
46
+
47
+ result
48
+ end
49
+
50
+ def lines(*, chomp: false, **) = gets(*, **).lines(chomp:)
51
+
52
+ def each_line(*, chomp: false, **, &)
53
+ argv0, *argv = coerce_argv(*)
54
+ raise LocalJumpError, 'no block given' unless block_given?
55
+
56
+ puts_command argv0, argv
57
+ IO.popen([argv0, *argv], **) do |io|
58
+ io.each_line(chomp:, &)
59
+ end
60
+ raise SystemCommand::Error, "#{argv0} failed (#{Process.last_status})" unless Process.last_status.success?
61
+
62
+ nil
63
+ end
64
+
65
+ private
66
+
67
+ def coerce_argv(*args)
68
+ args = Array(args.first) if args.length == 1
69
+ raise ArgumentError, 'Must specify one or more argument' if args.empty?
70
+
71
+ args.map do |arg|
72
+ arg = arg.to_path if arg.respond_to?(:to_path)
73
+ arg
74
+ end
75
+ end
76
+
77
+ def puts_command(argv0, argv)
78
+ puts ColorizedString["$ #{[argv0, *argv].shelljoin}"].light_black if verbose?
79
+ end
80
+ end
81
+
82
+ def initialize(path, *options)
83
+ @path = path
84
+ @options = options
85
+ end
86
+
87
+ def run?(...) = SystemCommand.run?(@path, *@options, ...)
88
+ def run(...) = SystemCommand.run(@path, *@options, ...)
89
+ def gets(...) = SystemCommand.gets(@path, *@options, ...)
90
+ def lines(...) = SystemCommand.lines(@path, *@options, ...)
91
+ def each_line(...) = SystemCommand.each_line(@path, *@options, ...)
92
+ end
93
+
94
+ require_relative 'system_command/version'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: system_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alex Gittemeier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description:
28
+ email:
29
+ - me@a.lexg.dev
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".rubocop_coldwater.yml"
37
+ - ".vscode/launch.json"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - README.md
41
+ - Rakefile
42
+ - lib/system_command.rb
43
+ - lib/system_command/version.rb
44
+ homepage: https://gitlab.com/coldwater-systems/system_command
45
+ licenses: []
46
+ metadata:
47
+ homepage_uri: https://gitlab.com/coldwater-systems/system_command
48
+ source_code_uri: https://gitlab.com/coldwater-systems/system_command
49
+ allowed_push_host: https://rubygems.org
50
+ rubygems_mfa_required: 'true'
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.2.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.4.22
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Run external process as if they were functions.
70
+ test_files: []