amyf 0.1.0 → 0.2.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 +4 -4
- data/bin/amyf +1 -1
- data/lib/amyf.rb +33 -2
- data/lib/battlestation.rb +39 -0
- data/lib/git_cloner.rb +47 -0
- data/lib/log.rb +19 -0
- data/lib/roadrunner.rb +15 -0
- data/lib/specs/git_cloner_spec.rb +20 -0
- data/lib/specs/version_parser_spec.rb +7 -5
- data/lib/specs/version_spec.rb +65 -0
- data/lib/version.rb +16 -0
- data/lib/version_parser.rb +2 -3
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a8535163e2016b9ccfa2669ff2b424c5ce1c52f3180a80bdda673c5c7b3744
|
4
|
+
data.tar.gz: 0bd48d7cec14acf97dcaae34ffe202aaf5869d8a3b4b60ded9db816cb5094f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2cdda31fa1f1531dff35fbcfc6a4f4f6a1db34fc05661926f0b1dc10e43490ea2a7d37b3ccfd2af19fb0d2139cca800dfc8b74b7f271781728cf480804192f
|
7
|
+
data.tar.gz: 56cc70ff66e14f1ef83e26e385d75d625e8066cbd817c596cd06ae344031702f0351854da73ebaf6f43bf759fb41cbc1c0ccfd010dabaf1f4ee36f552cae1769
|
data/bin/amyf
CHANGED
data/lib/amyf.rb
CHANGED
@@ -1,8 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'optparse'
|
4
|
+
require_relative 'battlestation'
|
5
|
+
require_relative 'roadrunner'
|
6
|
+
|
3
7
|
# Stops to smells the roses
|
4
8
|
module Amy
|
5
|
-
|
6
|
-
|
9
|
+
# Meditate.
|
10
|
+
# Medicate.
|
11
|
+
# Meditate.
|
12
|
+
def self.meditate
|
13
|
+
options = {}
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = cat_art
|
16
|
+
opts.on('--battleship', 'Laptop setup') { |o| options[:battleship] = o }
|
17
|
+
opts.on('-r', '--roadrunner URLS', 'Comma-separated list of GitHub repository URLs') do |github_urls|
|
18
|
+
options[:github_urls] = github_urls.split(',')
|
19
|
+
end
|
20
|
+
opts.on('-h', '--help', 'I need somebody (not just anybody)') do
|
21
|
+
puts opts
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
end.parse!
|
25
|
+
|
26
|
+
Battlestation.new.setup if options[:battleship] == true
|
27
|
+
RoadRunner.new(options[:github_urls]).run if options[:github_urls]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.cat_art
|
31
|
+
<<~CAT
|
32
|
+
-----------------------
|
33
|
+
/\\_/\\
|
34
|
+
( o.o ) dance
|
35
|
+
> ^ < break ?
|
36
|
+
-----------------------
|
37
|
+
CAT
|
7
38
|
end
|
8
39
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
require_relative 'log'
|
5
|
+
|
6
|
+
# Responsible of handling all the command line interface logic.
|
7
|
+
# Inspired by https://github.com/bachand/battlestation
|
8
|
+
class Battlestation
|
9
|
+
# Entry point for the application logic. Here we do the command line arguments processing and
|
10
|
+
# inspect the target files.
|
11
|
+
#
|
12
|
+
# @param args [Array<String>] command line arguments
|
13
|
+
# @return [Integer] UNIX exit code
|
14
|
+
def setup(_args = ARGV)
|
15
|
+
Log.info 'installing homebrew'
|
16
|
+
system '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
|
17
|
+
|
18
|
+
Log.info 'installing Rbenv'
|
19
|
+
system 'brew install rbenv'
|
20
|
+
system 'rbenv init'
|
21
|
+
|
22
|
+
Log.ingo 'installing oh-my-zsh'
|
23
|
+
system 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"'
|
24
|
+
|
25
|
+
Log.success(cat_art)
|
26
|
+
|
27
|
+
$CHILD_STATUS.exitstatus
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.cat_art
|
31
|
+
<<~CAT
|
32
|
+
----------------------------------
|
33
|
+
/\\_/\\
|
34
|
+
( o.o ) reopen your terminal
|
35
|
+
> ^ < bai !
|
36
|
+
----------------------------------
|
37
|
+
CAT
|
38
|
+
end
|
39
|
+
end
|
data/lib/git_cloner.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'git'
|
5
|
+
require 'log'
|
6
|
+
|
7
|
+
# Clones git repositories locally
|
8
|
+
class GitCloner
|
9
|
+
# @param base_dir The directory to which the repositories will be copied locally
|
10
|
+
def initialize(base_dir = '.')
|
11
|
+
@base_dir = base_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
# Accepts an array of GitHub repository URLs (either HTTPS or SSH links) and clones
|
15
|
+
# them locally if they have not already been cloned.
|
16
|
+
#
|
17
|
+
# @param repo_urls An array of URLs pointing to GitHub repositories
|
18
|
+
def clone_repos(repo_urls)
|
19
|
+
repo_urls.each do |url|
|
20
|
+
clone_repo(url)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def clone_repo(url)
|
25
|
+
repo_path = extract_repo_path(url)
|
26
|
+
local_path = File.join(@base_dir, repo_path)
|
27
|
+
|
28
|
+
if Dir.exist?(local_path)
|
29
|
+
Log.info "Repository already exists at #{local_path}. Skipping..."
|
30
|
+
else
|
31
|
+
Log.info "Cloning #{url} into #{local_path}..."
|
32
|
+
FileUtils.mkdir_p(local_path)
|
33
|
+
Git.clone(url, local_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract_repo_path(url)
|
38
|
+
# Extract the username and repository name from the GitHub URL
|
39
|
+
# Don't ask me what's in this monstruosity
|
40
|
+
match = url.match(%r{github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$})
|
41
|
+
raise "Invalid GitHub URL: #{url}" unless match
|
42
|
+
|
43
|
+
username = match[1]
|
44
|
+
repo_name = match[2]
|
45
|
+
"#{username}/#{repo_name}"
|
46
|
+
end
|
47
|
+
end
|
data/lib/log.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Sends a message to the terminal
|
4
|
+
module Log
|
5
|
+
# Sends a decorated message to standard output in red
|
6
|
+
def self.success(text)
|
7
|
+
$stdout.puts "SUCCESS: \e[0;32m#{text}\e[0m"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Sends a decorated message to standard error
|
11
|
+
def self.error(text)
|
12
|
+
warn "ERR: \e[0;31m#{text}\e[0m"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Sends a decorated message to standard output in blue
|
16
|
+
def self.info(text)
|
17
|
+
$stdout.puts "INFO: \e[0m#{text}\e[0m"
|
18
|
+
end
|
19
|
+
end
|
data/lib/roadrunner.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'git_cloner'
|
4
|
+
|
5
|
+
# Runs around your computer. Does things. Tries to escape the coyote.
|
6
|
+
class RoadRunner
|
7
|
+
# @param github_repos An array of URLs pointing to GitHub repositories
|
8
|
+
def initialize(github_repos)
|
9
|
+
@github_repos = github_repos
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
GitCloner.new.clone_repos(@github_repos)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require_relative '../git_cloner'
|
5
|
+
|
6
|
+
RSpec.describe GitCloner do
|
7
|
+
subject(:cloner) { described_class.new }
|
8
|
+
|
9
|
+
describe '#extract_repo_path' do
|
10
|
+
it 'with a github URL with https' do
|
11
|
+
result = cloner.extract_repo_path('https://github.com/fdiaz/fdiaz.github.io.git')
|
12
|
+
expect(result).to eq 'fdiaz/fdiaz.github.io'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'with a github URL with ssh' do
|
16
|
+
result = cloner.extract_repo_path('git@github.com:fdiaz/amy.git')
|
17
|
+
expect(result).to eq 'fdiaz/amy'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,31 +4,33 @@ require 'rspec'
|
|
4
4
|
require_relative '../version_parser'
|
5
5
|
|
6
6
|
RSpec.describe VersionParser do
|
7
|
+
subject(:parser) { described_class }
|
8
|
+
|
7
9
|
let(:dummy_class) { Class.new { include VersionParser } }
|
8
10
|
|
9
11
|
describe '#prerelease_version' do
|
10
12
|
it 'with major, minor, patch - it returns nil for prerelease name and version' do
|
11
|
-
result =
|
13
|
+
result = parser.parse('1.2.3')
|
12
14
|
expect(result).to eq Version.new(1, 2, 3, nil, nil)
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'with major, minor, patch, prerelease and no prerelease version - it assigns it a 0' do
|
16
|
-
result =
|
18
|
+
result = parser.parse('99.2.3-beta')
|
17
19
|
expect(result).to eq Version.new(99, 2, 3, 'beta', 0)
|
18
20
|
end
|
19
21
|
|
20
22
|
it "with major, minor, patch, prerelease and prerelease version'" do
|
21
|
-
result =
|
23
|
+
result = parser.parse('1.02.3-alpha.238')
|
22
24
|
expect(result).to eq Version.new(1, 2, 3, 'alpha', 238)
|
23
25
|
end
|
24
26
|
|
25
27
|
it 'with no patch version - it assign it a 0' do
|
26
|
-
result =
|
28
|
+
result = parser.parse('1.2-rc')
|
27
29
|
expect(result).to eq Version.new(1, 2, 0, 'rc', 0)
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'with no minor version - it assigns 0 to minor and patch' do
|
31
|
-
result =
|
33
|
+
result = parser.parse('874-random')
|
32
34
|
expect(result).to eq Version.new(874, 0, 0, 'random', 0)
|
33
35
|
end
|
34
36
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require_relative '../version'
|
5
|
+
|
6
|
+
RSpec.describe Version do
|
7
|
+
describe '#to_s' do
|
8
|
+
it 'converts a simple version without prerelease info' do
|
9
|
+
version = described_class.new(1, 2, 3)
|
10
|
+
expect(version.to_s).to eq('1.2.3')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'handles a pre-release without a numeric prerelease version' do
|
14
|
+
version = described_class.new(2, 3, 4, 'rc')
|
15
|
+
expect(version.to_s).to eq('2.3.4-rc')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'handles a complex pre-release version' do
|
19
|
+
version = described_class.new(1, 0, 0, 'alpha', 42)
|
20
|
+
expect(version.to_s).to eq('1.0.0-alpha.42')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'handles a version with zero values correctly' do
|
24
|
+
version = described_class.new(0, 0, 1)
|
25
|
+
expect(version.to_s).to eq('0.0.1')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'handles a version with large numbers correctly' do
|
29
|
+
version = described_class.new(10, 99, 100)
|
30
|
+
expect(version.to_s).to eq('10.99.100')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'handles a version with no patch correctly' do
|
34
|
+
version = described_class.new(10, 99)
|
35
|
+
expect(version.to_s).to eq('10.99')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'handles a version with no minor correctly' do
|
39
|
+
version = described_class.new(30)
|
40
|
+
expect(version.to_s).to eq('30')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#bump_minor' do
|
45
|
+
it 'increments the minor version by 1' do
|
46
|
+
version = described_class.new(1, 2, 3).bump_minor
|
47
|
+
expect(version.to_h).to eq described_class.new(1, 3, 3).to_h
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'handles single-digit minor versions correctly' do
|
51
|
+
version = described_class.new(2, 0, 5).bump_minor
|
52
|
+
expect(version.to_h).to eq described_class.new(2, 1, 5).to_h
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'handles larger minor numbers correctly' do
|
56
|
+
version = described_class.new(5, 99, 10).bump_minor
|
57
|
+
expect(version.to_h).to eq described_class.new(5, 100, 10).to_h
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'works with prerelease version' do
|
61
|
+
version = described_class.new(5, 99, 10, 'beta', 2).bump_minor
|
62
|
+
expect(version.to_h).to eq described_class.new(5, 100, 10, 'beta', 2).to_h
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Version = Struct.new(:major, :minor, :patch, :prerelease_name, :prerelease_version) do
|
4
|
+
def to_s
|
5
|
+
return "#{major}.#{minor}.#{patch}-#{prerelease_name}.#{prerelease_version}" if prerelease_name && prerelease_version
|
6
|
+
return "#{major}.#{minor}.#{patch}-#{prerelease_name}" if prerelease_name && !prerelease_version
|
7
|
+
return "#{major}.#{minor}.#{patch}" if patch
|
8
|
+
return "#{major}.#{minor}" if minor
|
9
|
+
|
10
|
+
major.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def bump_minor
|
14
|
+
Version.new(major, minor + 1, patch, prerelease_name, prerelease_version)
|
15
|
+
end
|
16
|
+
end
|
data/lib/version_parser.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'version'
|
4
4
|
|
5
|
+
# Parses a module semantic version
|
5
6
|
module VersionParser
|
6
7
|
def self.parse(version)
|
7
|
-
_ = 0
|
8
|
-
|
9
8
|
main_version, prerelease = version.split('-')
|
10
9
|
|
11
10
|
main_parts = main_version.split('.').map(&:to_i)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amyf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fdiaz
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Impossible to live without it
|
13
13
|
email:
|
@@ -19,12 +19,20 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/amyf
|
21
21
|
- lib/amyf.rb
|
22
|
+
- lib/battlestation.rb
|
23
|
+
- lib/git_cloner.rb
|
24
|
+
- lib/log.rb
|
25
|
+
- lib/roadrunner.rb
|
26
|
+
- lib/specs/git_cloner_spec.rb
|
22
27
|
- lib/specs/version_parser_spec.rb
|
28
|
+
- lib/specs/version_spec.rb
|
29
|
+
- lib/version.rb
|
23
30
|
- lib/version_parser.rb
|
24
31
|
homepage: https://twoheartedyoga.com
|
25
32
|
licenses:
|
26
33
|
- MIT
|
27
|
-
metadata:
|
34
|
+
metadata:
|
35
|
+
rubygems_mfa_required: 'false'
|
28
36
|
rdoc_options: []
|
29
37
|
require_paths:
|
30
38
|
- lib
|