computer 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23ede6f396272db6056b8c8797f1f5efa0b9829a
4
- data.tar.gz: 2a251db14f1dba7f5d930b07f9b8f1bed4b3e134
3
+ metadata.gz: 5607ed6cb5688ad020b7c5f3908e12f88a828084
4
+ data.tar.gz: 2746b122b2e927f729b26d28af7b27bc7729a13b
5
5
  SHA512:
6
- metadata.gz: 634fd8cfc53d7e64f9a65d4290fdbcd9838442764906ee7206f500d92a7a3e8c823d2ade0cfaa8ec2065cec8f48bf43492377b75f11f99565825acbf2fd8169a
7
- data.tar.gz: 6aac2b5f87a69362d4e2b43331686f931ada4c012eacc63f7766946b23e05e1368b8ab4a195a17ba9179ea5e1a43f8f387d33c8adf25b7866f1346767eac3bd9
6
+ metadata.gz: 53be4c3d03aaf38bda90fbb482c4862be247e037503a3ef35e72ed8b767d43de52cd605831fb161a8374d22eaa41c66057814a99142aa7f0ab2ed470d46191b1
7
+ data.tar.gz: 8ea309ab1de096aafb509f6722031dd87172f572ba491cf64f7424cb99e08dc6abf33f27e8366fced3a18271a6e71347631dda408a7f06c00e351a3521c0ea97
@@ -1,4 +1,4 @@
1
- ### 0.0.1 / 2020-10-20
1
+ ### 0.0.1 / 2020-10-19
2
2
 
3
3
  * Everything is new. First release.
4
4
 
@@ -3,3 +3,7 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/computer.rb
6
+ lib/computer/shell.rb
7
+ lib/computer/version.rb
8
+ test/helper.rb
9
+ test/test_shell.rb
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # computer
2
2
 
3
- computer gem - command line helpers / wrappers
3
+ computer gem - shell command line helper / wrapper 'n' more for your computer
4
4
 
5
5
  * home :: [github.com/rubycoco/git](https://github.com/rubycoco/git)
6
6
  * bugs :: [github.com/rubycoco/git/issues](https://github.com/rubycoco/git/issues)
7
- * gem :: [rubygems.org/gems/yorobot](https://rubygems.org/gems/yorobot)
8
- * rdoc :: [rubydoc.info/gems/yorobot](http://rubydoc.info/gems/yorobot)
7
+ * gem :: [rubygems.org/gems/computer](https://rubygems.org/gems/computer)
8
+ * rdoc :: [rubydoc.info/gems/computer](http://rubydoc.info/gems/computer)
9
9
 
10
10
 
11
11
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'hoe'
2
- require './lib/computer.rb'
2
+ require './lib/computer/version.rb'
3
3
 
4
4
  Hoe.spec 'computer' do
5
5
 
6
6
  self.version = Computer::VERSION
7
7
 
8
- self.summary = "computer gem - command line helpers / wrappers"
8
+ self.summary = "computer gem - shell command line helper / wrapper 'n' more for your computer"
9
9
  self.description = summary
10
10
 
11
11
  self.urls = { home: 'https://github.com/rubycoco/git' }
@@ -1,4 +1,30 @@
1
- module Computer
2
- VERSION = '0.0.1'
3
- end
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.
4
11
 
12
+ ##########################
13
+ # more defaults ("prolog/prelude") always pre-loaded
14
+ require 'optparse'
15
+
16
+
17
+ #####################
18
+ # our own code
19
+ require 'computer/version' # note: let version always go first
20
+ require 'computer/shell'
21
+
22
+
23
+
24
+ ######################
25
+ # add convenience shortcuts - why? why not?
26
+ Compu = Computer
27
+
28
+
29
+ # say hello
30
+ puts Computer.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 Computer
2
+
3
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
+ MINOR = 1
5
+ PATCH = 0
6
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
7
+
8
+ def self.version
9
+ VERSION
10
+ end
11
+
12
+ def self.banner
13
+ "computer/#{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 Computer
21
+
@@ -0,0 +1,9 @@
1
+ ## minitest setup
2
+ require 'minitest/autorun'
3
+
4
+
5
+ ## our own code
6
+ require 'computer'
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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: computer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -44,7 +44,8 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.22'
47
- description: computer gem - command line helpers / wrappers
47
+ description: computer gem - shell command line helper / wrapper 'n' more for your
48
+ computer
48
49
  email: ruby-talk@ruby-lang.org
49
50
  executables: []
50
51
  extensions: []
@@ -58,6 +59,10 @@ files:
58
59
  - README.md
59
60
  - Rakefile
60
61
  - lib/computer.rb
62
+ - lib/computer/shell.rb
63
+ - lib/computer/version.rb
64
+ - test/helper.rb
65
+ - test/test_shell.rb
61
66
  homepage: https://github.com/rubycoco/git
62
67
  licenses:
63
68
  - Public Domain
@@ -83,5 +88,5 @@ rubyforge_project:
83
88
  rubygems_version: 2.5.2
84
89
  signing_key:
85
90
  specification_version: 4
86
- summary: computer gem - command line helpers / wrappers
91
+ summary: computer gem - shell command line helper / wrapper 'n' more for your computer
87
92
  test_files: []