shell-lite 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c914ac1049a2318b40d79ed5185095c30ffcfb0
4
+ data.tar.gz: c73473f778d47775bf793bdeaed87bfa66c1cd94
5
+ SHA512:
6
+ metadata.gz: 1d0b8d2d7b4e674f8f526d93a996f2762ac0c75495ca14a047280ecbb23fda6c1feb6f2d2279be57e41c79b47e88395214f57f5968a73a84d229a07a3d4bc1da
7
+ data.tar.gz: 924816787421c3f8681b78d826b7b71c5286e6b155752b85873a561dceeb3ebd39fc2b058b392522e31ffbc855e5b31d35729e9e4b806a8436145664eb9f7f64
@@ -0,0 +1,4 @@
1
+ ### 0.0.1 / 2020-10-19
2
+
3
+ * Everything is new. First release.
4
+
@@ -0,0 +1,9 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/shell-lite.rb
6
+ lib/shell-lite/shell.rb
7
+ lib/shell-lite/version.rb
8
+ test/helper.rb
9
+ test/test_shell.rb
@@ -0,0 +1,23 @@
1
+ # shell-lite
2
+
3
+ shell-lite gem - shell command line helper / wrapper 'n' more for your computer
4
+
5
+ * home :: [github.com/rubycoco/git](https://github.com/rubycoco/git)
6
+ * bugs :: [github.com/rubycoco/git/issues](https://github.com/rubycoco/git/issues)
7
+ * gem :: [rubygems.org/gems/shell-lite](https://rubygems.org/gems/shell-lite)
8
+ * rdoc :: [rubydoc.info/gems/shell-lite](http://rubydoc.info/gems/shell-lite)
9
+
10
+
11
+
12
+ ## Usage
13
+
14
+ To be done
15
+
16
+
17
+
18
+
19
+ ## License
20
+
21
+ The `shell-lite` scripts are dedicated to the public domain.
22
+ Use it as you please with no restrictions whatsoever.
23
+
@@ -0,0 +1,28 @@
1
+ require 'hoe'
2
+ require './lib/shell-lite/version.rb'
3
+
4
+ Hoe.spec 'shell-lite' do
5
+
6
+ self.version = ShellLite::VERSION
7
+
8
+ self.summary = "shell-lite gem - shell command line helper / wrapper 'n' more for your computer"
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/rubycoco/git' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'ruby-talk@ruby-lang.org'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = []
21
+
22
+ self.licenses = ['Public Domain']
23
+
24
+ self.spec_extras = {
25
+ required_ruby_version: '>= 2.2.2'
26
+ }
27
+
28
+ end
@@ -0,0 +1,84 @@
1
+ require 'pp'
2
+ require 'time'
3
+ require 'date' ## e.g. Date.today etc.
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'uri'
7
+ require 'net/http'
8
+ require "net/https"
9
+ require 'open3'
10
+ require 'fileutils' ## e.g. FileUtils.mkdir_p etc.
11
+
12
+ ##########################
13
+ # more defaults ("prolog/prelude") always pre-loaded
14
+ require 'optparse'
15
+ require 'rbconfig'
16
+
17
+ #####################
18
+ # our own code
19
+ require 'shell-lite/version' # note: let version always go first
20
+ require 'shell-lite/shell'
21
+
22
+
23
+
24
+
25
+ ## add some system info from/via rbconfig - why? why not?
26
+ module Computer
27
+
28
+ OS = case RbConfig::CONFIG['host_os'].downcase
29
+ when /linux/
30
+ "linux"
31
+ when /darwin/
32
+ "darwin"
33
+ when /freebsd/
34
+ "freebsd"
35
+ when /netbsd/
36
+ "netbsd"
37
+ when /openbsd/
38
+ "openbsd"
39
+ when /dragonfly/
40
+ "dragonflybsd"
41
+ when /sunos|solaris/
42
+ "solaris"
43
+ when /mingw|mswin/
44
+ "windows"
45
+ else
46
+ RbConfig::CONFIG['host_os'].downcase
47
+ end
48
+
49
+ CPU = RbConfig::CONFIG['host_cpu'] ## todo/check: always use downcase - why? why not?
50
+
51
+ ARCH = case CPU.downcase
52
+ when /amd64|x86_64|x64/
53
+ "x86_64"
54
+ when /i?86|x86|i86pc/
55
+ "i386"
56
+ when /ppc64|powerpc64/
57
+ "powerpc64"
58
+ when /ppc|powerpc/
59
+ "powerpc"
60
+ when /sparcv9|sparc64/
61
+ "sparcv9"
62
+ when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64"
63
+ "aarch64"
64
+ when /^arm/
65
+ "arm"
66
+ else
67
+ RbConfig::CONFIG['host_cpu'] ## todo/check: always use downcase - why? why not?
68
+ end
69
+
70
+ def self.os() OS; end
71
+ def self.cpu() CPU; end
72
+ def self.arch() ARCH; end
73
+
74
+
75
+ end # module Computer
76
+
77
+
78
+ ######################
79
+ # add convenience shortcuts - why? why not?
80
+ Compu = Computer
81
+
82
+
83
+ # say hello
84
+ puts ShellLite.banner
@@ -0,0 +1,57 @@
1
+ module Computer
2
+
3
+
4
+ ## raised / thrown by Shell.run if exit status non-zero
5
+ ## todo/check: (re)use an already existing error - why? why not?
6
+ class ShellError < StandardError
7
+ end
8
+
9
+
10
+ ###
11
+ # use nested class for "base" for running commands - why? why not?
12
+ class Shell
13
+
14
+ ## use call for the "to-the-metal" command execution
15
+ def self.call( cmd )
16
+ stdout, stderr, status = Open3.capture3( cmd )
17
+ [stdout, stderr, status]
18
+ end
19
+
20
+
21
+ ## use run for "porcelain / high-level" command execution
22
+ def self.run( cmd )
23
+ ## add pwd (print working directory to output?) - why? why not?
24
+ print "---> (shell run) >#{cmd}<..."
25
+ stdout, stderr, status = Open3.capture3( cmd )
26
+
27
+ ## todo: add colors (red, green) - why? why not?
28
+ if status.success?
29
+ print " OK" ## todo/check: use OK (0) - why? why not?
30
+ print "\n"
31
+ else
32
+ print " FAIL (#{status.exitstatus})"
33
+ print "\n"
34
+ end
35
+
36
+ unless stdout.empty?
37
+ puts stdout
38
+ end
39
+
40
+ unless stderr.empty?
41
+ ## todo/check: or use >2: or &2: or such
42
+ ## stderr output not always an error (that is, exit status might be 0)
43
+ STDERR.puts "2>"
44
+ STDERR.puts stderr
45
+ end
46
+
47
+ if status.success?
48
+ stdout # return stdout string
49
+ else
50
+ STDERR.puts "!! ERROR: Shell.run >#{cmd}< failed with exit status #{status.exitstatus}:"
51
+ STDERR.puts stderr
52
+
53
+ raise ShellError, "Shell.run >#{cmd}< failed with exit status #{status.exitstatus}<: #{stderr}"
54
+ end
55
+ end
56
+ end # class Shell
57
+ end # module Computer
@@ -0,0 +1,21 @@
1
+ module ShellLite
2
+
3
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
+ MINOR = 0
5
+ PATCH = 1
6
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
7
+
8
+ def self.version
9
+ VERSION
10
+ end
11
+
12
+ def self.banner
13
+ "shell-lite/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
14
+ end
15
+
16
+ def self.root
17
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
18
+ end
19
+
20
+ end # module ShellLite
21
+
@@ -0,0 +1,9 @@
1
+ ## minitest setup
2
+ require 'minitest/autorun'
3
+
4
+
5
+ ## our own code
6
+ require 'shell-lite'
7
+
8
+
9
+
@@ -0,0 +1,33 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_shell.rb
4
+
5
+ require 'helper'
6
+
7
+ class TestShell < MiniTest::Test
8
+
9
+ Shell = Computer::Shell
10
+
11
+ def test_run
12
+ Shell.run( 'git config user.name' )
13
+ Shell.run( 'git config --show-origin user.name' )
14
+ # Shell.run( 'git config xxxx' )
15
+ # Shell.run( 'xxxx' )
16
+ end
17
+
18
+ def test_call
19
+ stdout1, stderr1, status1 = Shell.call( 'git config user.name' )
20
+ stdout2, stderr2, status2 = Shell.call( 'git config --show-origin user.name' )
21
+ # stdout3, stderr3, status3 = Shell.call( 'xxxx' )
22
+
23
+ pp stdout1
24
+ pp stderr1
25
+ pp status1
26
+ puts "---"
27
+ pp stdout2
28
+ pp stderr2
29
+ pp status2
30
+ end
31
+
32
+ end # class TestShell
33
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shell-lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.22'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.22'
47
+ description: shell-lite gem - shell command line helper / wrapper 'n' more for your
48
+ computer
49
+ email: ruby-talk@ruby-lang.org
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - CHANGELOG.md
54
+ - Manifest.txt
55
+ - README.md
56
+ files:
57
+ - CHANGELOG.md
58
+ - Manifest.txt
59
+ - README.md
60
+ - Rakefile
61
+ - lib/shell-lite.rb
62
+ - lib/shell-lite/shell.rb
63
+ - lib/shell-lite/version.rb
64
+ - test/helper.rb
65
+ - test/test_shell.rb
66
+ homepage: https://github.com/rubycoco/git
67
+ licenses:
68
+ - Public Domain
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options:
72
+ - "--main"
73
+ - README.md
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.2.2
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.5.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: shell-lite gem - shell command line helper / wrapper 'n' more for your
92
+ computer
93
+ test_files: []