Kobold 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/kobold +17 -12
- data/lib/Kobold/first_time_setup.rb +14 -0
- data/lib/Kobold/init.rb +20 -0
- data/lib/Kobold/invoke.rb +123 -0
- data/lib/Kobold/read_config.rb +15 -0
- data/lib/Kobold/vars.rb +10 -0
- data/lib/Kobold/version.rb +2 -2
- data/lib/Kobold.rb +6 -98
- data/prototyping/.gitignore +2 -0
- data/prototyping/.kobold +11 -3
- metadata +64 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95561edd1b18544bfc735599c499a2b0d415a2b1638a30a56257fda2175adbbc
|
4
|
+
data.tar.gz: a87c0b8575ea4abf21acf6325b32d8f4c371db5c6f0f9e0b7df97edb8a196021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e5df73b29da03d20e409b39d4752011bd56e38d5e1bef5132f09bd732a9ee4ac73e71043c2d7048f8e66b7ae36e5b5a77cff91bf15fa1ffbc6a433f7b34c340
|
7
|
+
data.tar.gz: 430e6ad01c0d0c89853811362b6e51cb7ce0e62d424bcd3e8cd1a875e11de3cc85f4b72bf680ea0e5529d12aee030afe8e74b0a1a0d2b863ede06543bd65601b
|
data/exe/kobold
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'Kobold'
|
4
4
|
require 'tty-option'
|
5
|
-
require 'pry'
|
5
|
+
#require 'pry'
|
6
6
|
|
7
7
|
module Kobold
|
8
8
|
class Command
|
@@ -11,24 +11,19 @@ module Kobold
|
|
11
11
|
usage do
|
12
12
|
program "kobold"
|
13
13
|
|
14
|
-
|
14
|
+
commands "init", "invoke"
|
15
15
|
|
16
|
-
desc "Initializes empty Kobold configuration file"
|
17
16
|
end
|
18
17
|
|
19
18
|
argument :command do
|
20
19
|
optional
|
21
|
-
desc "
|
20
|
+
desc "Accepts commands for Kobold to execute."
|
22
21
|
end
|
23
22
|
|
24
23
|
flag :help do
|
25
24
|
short "-h"
|
26
25
|
long "--help"
|
27
|
-
desc "Print usage"
|
28
|
-
end
|
29
|
-
|
30
|
-
flag :init do
|
31
|
-
desc "initialize"
|
26
|
+
desc "Print usage."
|
32
27
|
end
|
33
28
|
|
34
29
|
def run
|
@@ -37,7 +32,7 @@ module Kobold
|
|
37
32
|
elsif params.errors.any?
|
38
33
|
puts params.errors.summary
|
39
34
|
else
|
40
|
-
pp params.to_h
|
35
|
+
#pp params.to_h
|
41
36
|
end
|
42
37
|
end
|
43
38
|
end
|
@@ -50,6 +45,16 @@ run = cmd.run
|
|
50
45
|
|
51
46
|
if cmd.params[:command] == nil || cmd.params == "invoke"
|
52
47
|
Kobold.invoke
|
53
|
-
|
54
|
-
|
48
|
+
else
|
49
|
+
case cmd.params[:command]
|
50
|
+
when "add"
|
51
|
+
when "remove"
|
52
|
+
when "update"
|
53
|
+
when "list"
|
54
|
+
Kobold.list
|
55
|
+
when "init"
|
56
|
+
Kobold.init
|
57
|
+
else
|
58
|
+
print cmd.help
|
59
|
+
end
|
55
60
|
end
|
data/lib/Kobold/init.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tty-config"
|
4
|
+
require 'fileutils'
|
5
|
+
require 'git'
|
6
|
+
|
7
|
+
module Kobold
|
8
|
+
class << self
|
9
|
+
# create empty file with current
|
10
|
+
# file version in current dir
|
11
|
+
def init
|
12
|
+
kobold_config = TTY::Config.new
|
13
|
+
kobold_config.filename = ".kobold"
|
14
|
+
kobold_config.extname = ".ini"
|
15
|
+
kobold_config.set "kobold_config", "format_version", value: Kobold::FORMAT_VERSION
|
16
|
+
kobold_config.write
|
17
|
+
File.rename ".kobold.ini", ".kobold"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tty-config"
|
4
|
+
require 'fileutils'
|
5
|
+
require 'git'
|
6
|
+
|
7
|
+
#require_relative "Kobold/vars.rb"
|
8
|
+
|
9
|
+
module Kobold
|
10
|
+
class << self
|
11
|
+
def invoke
|
12
|
+
Kobold.first_time_setup if !File.directory? "#{KOBOLD_DIR}/repo_cache"
|
13
|
+
if !File.file? "#{Dir.pwd}/.kobold"
|
14
|
+
puts "ERROR: Kobold file not found at '#{Dir.pwd}'"
|
15
|
+
return
|
16
|
+
end
|
17
|
+
settings = Kobold.read_config(Dir.pwd)
|
18
|
+
|
19
|
+
#puts Kobold::FORMAT_VERSION + " " + settings["kobold_config"]["format_version"]
|
20
|
+
if Kobold::FORMAT_VERSION == settings["_kobold_config"]["format_version"]
|
21
|
+
#settings.delete "kobold_config"
|
22
|
+
|
23
|
+
# iterate over all dependencies
|
24
|
+
settings.each do |key, value|
|
25
|
+
if Kobold::CONFIG_TITLES.include? key
|
26
|
+
#puts "skipping #{key}"
|
27
|
+
next
|
28
|
+
end
|
29
|
+
repo_dir = "#{KOBOLD_DIR}/repo_cache/#{key.gsub('/', '-')}"
|
30
|
+
|
31
|
+
source_repo = nil;
|
32
|
+
# check if source exists
|
33
|
+
if !Dir.exist? "#{repo_dir}/source" # TODO: make this properly check for git repo
|
34
|
+
# if it doesnt, make it
|
35
|
+
FileUtils.mkdir_p "#{repo_dir}/source"
|
36
|
+
FileUtils.mkdir_p "#{repo_dir}/worktrees"
|
37
|
+
FileUtils.mkdir_p "#{repo_dir}/branches" # these are also worktrees, but just for the branch specifically if possible. TODO for later
|
38
|
+
#puts "#{value["source"]}/#{key}.git", "#{repo_dir}/source"
|
39
|
+
source_repo = Git.clone "#{value["source"]}/#{key}.git", "#{repo_dir}/source"
|
40
|
+
else
|
41
|
+
source_repo = Git.open("#{repo_dir}/source")
|
42
|
+
end
|
43
|
+
|
44
|
+
target_symlink = nil
|
45
|
+
# check if requested version exists
|
46
|
+
if value["tag"]
|
47
|
+
dir_name = value["tag"].to_s.gsub("/","-")
|
48
|
+
# TODO make the thing
|
49
|
+
else # use hash as name
|
50
|
+
if value["commit"]
|
51
|
+
# use given commit name, also check it exists
|
52
|
+
begin # git errors when it does not find the hash
|
53
|
+
#if value["commit"].is_a? Float
|
54
|
+
# value["commit"] = value["commit"].to_i.to_s
|
55
|
+
#end
|
56
|
+
commit_val = value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")
|
57
|
+
if commit_val == 'latest'
|
58
|
+
# TODO just use source git repo
|
59
|
+
target_symlink = "#{repo_dir}/source"
|
60
|
+
elsif commit_sha
|
61
|
+
commit_sha = source_repo.object(commit_val).sha;
|
62
|
+
target_symlink = "#{repo_dir}/worktrees/#{commit_sha}"
|
63
|
+
if !Dir.exist? target_symlink
|
64
|
+
# make it
|
65
|
+
source_repo.worktree(target_symlink, commit_sha).add
|
66
|
+
end
|
67
|
+
else
|
68
|
+
raise "Cannot find commit"
|
69
|
+
end
|
70
|
+
rescue # we catch this error here
|
71
|
+
raise "Cannot find commit"
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise "No commit given for #{key}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# build the symlink
|
79
|
+
if value["dir"].end_with? "/"
|
80
|
+
FileUtils.mkdir_p value["dir"]
|
81
|
+
#puts "value: " + value["dir"] + key.split('/').last
|
82
|
+
#puts !File.symlink?(value["dir"] + key.split('/').last)
|
83
|
+
|
84
|
+
symlink1 = File.symlink?(value["dir"] + key.split('/').last)
|
85
|
+
symlink2 = File.symlink? value["dir"]
|
86
|
+
|
87
|
+
if !(symlink1 || symlink2)
|
88
|
+
File.symlink(target_symlink, "#{value['dir']}/#{key.split('/').last}")
|
89
|
+
end
|
90
|
+
#File.symlink(target_symlink, "#{value['dir']}/#{key.split('/').last}")
|
91
|
+
|
92
|
+
else
|
93
|
+
dir_components = value["dir"].split "/"
|
94
|
+
dir_components.pop
|
95
|
+
dir_components = dir_components.join "/"
|
96
|
+
FileUtils.mkdir_p dir_components
|
97
|
+
File.symlink(target_symlink, value["dir"]) if !File.symlink? value["dir"]
|
98
|
+
|
99
|
+
symlink1 = File.symlink?(value["dir"] + key.split('/').last)
|
100
|
+
symlink2 = File.symlink? value["dir"]
|
101
|
+
|
102
|
+
if !(symlink1 || symlink2)
|
103
|
+
File.symlink(target_symlink, value["dir"])
|
104
|
+
end
|
105
|
+
#File.symlink(target_symlink, value["dir"])
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
# iterate over all sub kobold files
|
111
|
+
sub_kobolds = if settings["_kobold_include"] then settings["_kobold_include"]["files"].strip.split("\n") else [] end
|
112
|
+
sub_kobolds.each do |path|
|
113
|
+
Dir.chdir(path.strip) do
|
114
|
+
invoke
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
else
|
119
|
+
raise "Wrong format version"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tty-config"
|
4
|
+
#require 'fileutils'
|
5
|
+
|
6
|
+
module Kobold
|
7
|
+
class << self
|
8
|
+
def read_config(dir)
|
9
|
+
config = TTY::Config.new
|
10
|
+
config.append_path dir
|
11
|
+
settings = config.read ".kobold", format: :ini
|
12
|
+
return settings
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/Kobold/vars.rb
ADDED
data/lib/Kobold/version.rb
CHANGED
data/lib/Kobold.rb
CHANGED
@@ -5,106 +5,14 @@ require "tty-config"
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'git'
|
7
7
|
|
8
|
+
require_relative "Kobold/vars.rb"
|
9
|
+
require_relative "Kobold/read_config.rb"
|
10
|
+
require_relative "Kobold/first_time_setup.rb"
|
11
|
+
require_relative "Kobold/invoke.rb"
|
12
|
+
require_relative "Kobold/init.rb"
|
13
|
+
|
8
14
|
module Kobold
|
9
15
|
KOBOLD_DIR = "#{Dir.home}/.local/share/Kobold"
|
10
16
|
class << self
|
11
|
-
|
12
|
-
# read configuration file
|
13
|
-
# for each item:
|
14
|
-
# 1. check if repo exists
|
15
|
-
# ~2. check if correct version exists~
|
16
|
-
# 3. check if symlink is correct
|
17
|
-
|
18
|
-
def invoke
|
19
|
-
first_time_setup if !File.directory? "#{KOBOLD_DIR}/repo_cache"
|
20
|
-
config = TTY::Config.new
|
21
|
-
config.append_path Dir.pwd
|
22
|
-
settings = config.read ".kobold", format: :ini
|
23
|
-
|
24
|
-
puts Kobold::FORMAT_VERSION + " " + settings["kobold_config"]["format_version"]
|
25
|
-
if Kobold::FORMAT_VERSION == settings["kobold_config"]["format_version"]
|
26
|
-
settings.delete "kobold_config"
|
27
|
-
|
28
|
-
# iterate over all dependencies
|
29
|
-
settings.each do |key, value|
|
30
|
-
puts "key:#{key}"
|
31
|
-
repo_dir = "#{KOBOLD_DIR}/repo_cache/#{key.gsub('/', '-')}"
|
32
|
-
|
33
|
-
master_repo = nil;
|
34
|
-
# check if master exists
|
35
|
-
if !Dir.exist? "#{repo_dir}/master" # TODO: make this properly check for git repo
|
36
|
-
# if it doesnt, make it
|
37
|
-
FileUtils.mkdir_p "#{repo_dir}/master"
|
38
|
-
FileUtils.mkdir_p "#{repo_dir}/worktrees"
|
39
|
-
puts "#{value["source"]}/#{key}.git", "#{repo_dir}/master"
|
40
|
-
master_repo = Git.clone "#{value["source"]}/#{key}.git", "#{repo_dir}/master"
|
41
|
-
else
|
42
|
-
master_repo = Git.open("#{repo_dir}/master")
|
43
|
-
end
|
44
|
-
|
45
|
-
target_symlink = nil
|
46
|
-
# check if requested version exists
|
47
|
-
if value["tag"]
|
48
|
-
dir_name = value["tag"].to_s.gsub("/","-")
|
49
|
-
# TODO make the thing
|
50
|
-
else # use hash as name
|
51
|
-
if value["commit"]
|
52
|
-
# use given commit name, also check it exists
|
53
|
-
begin # git errors when it does not find the hash
|
54
|
-
if value["commit"].is_a? Float
|
55
|
-
value["commit"] = value["commit"].to_i.to_s
|
56
|
-
end
|
57
|
-
commit_sha = master_repo.object(value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")).sha;
|
58
|
-
if commit_sha
|
59
|
-
target_symlink = "#{repo_dir}/worktrees/#{commit_sha}"
|
60
|
-
if !Dir.exist? target_symlink
|
61
|
-
# make it
|
62
|
-
master_repo.worktree(target_symlink, commit_sha).add
|
63
|
-
end
|
64
|
-
else
|
65
|
-
raise "Cannot find commit"
|
66
|
-
end
|
67
|
-
rescue # we catch this error here
|
68
|
-
raise "Cannot find commit"
|
69
|
-
end
|
70
|
-
else
|
71
|
-
raise "No commit given for #{key}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# build the symlink
|
76
|
-
if value["dir"].end_with? "/"
|
77
|
-
FileUtils.mkdir_p value["dir"]
|
78
|
-
File.symlink target_symlink, "#{value['dir']}/#{key.split('/').last}"
|
79
|
-
else
|
80
|
-
dir_components = value["dir"].split "/"
|
81
|
-
dir_components.pop
|
82
|
-
dir_components = dir_components.join "/"
|
83
|
-
FileUtils.mkdir_p dir_components
|
84
|
-
File.symlink target_symlink, value["dir"]
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
else
|
90
|
-
raise "Wrong format version"
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def first_time_setup
|
96
|
-
FileUtils.mkdir_p "#{KOBOLD_DIR}/repo_cache"
|
97
|
-
end
|
98
|
-
|
99
|
-
# create empty file with current
|
100
|
-
# file version in current dir
|
101
|
-
def init
|
102
|
-
kobold_config = TTY::Config.new
|
103
|
-
kobold_config.filename = ".kobold"
|
104
|
-
kobold_config.extname = ".ini"
|
105
|
-
kobold_config.set "kobold_config", "format_version", value: Kobold::FORMAT_VERSION
|
106
|
-
kobold_config.write
|
107
|
-
File.rename ".kobold.ini", ".kobold"
|
108
|
-
end
|
109
17
|
end
|
110
18
|
end
|
data/prototyping/.gitignore
CHANGED
data/prototyping/.kobold
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
[
|
2
|
-
format_version = 0.
|
1
|
+
[_kobold_config]
|
2
|
+
format_version = 0.2.0
|
3
|
+
|
4
|
+
[_kobold_include]
|
5
|
+
files = "
|
6
|
+
dir1/
|
7
|
+
dir2/
|
8
|
+
"
|
3
9
|
|
4
10
|
[raysan5/raylib]
|
5
11
|
source = https://github.com
|
6
12
|
dir = external/
|
7
|
-
commit = '
|
13
|
+
commit = 'latest'
|
14
|
+
|
15
|
+
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Kobold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CatsAtTheRodeo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tty-option
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tty-config
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: inifile
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: git
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.18.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.18.0
|
13
69
|
description:
|
14
70
|
email:
|
15
71
|
- contact@tradam.dev
|
@@ -33,6 +89,11 @@ files:
|
|
33
89
|
- Rakefile
|
34
90
|
- exe/kobold
|
35
91
|
- lib/Kobold.rb
|
92
|
+
- lib/Kobold/first_time_setup.rb
|
93
|
+
- lib/Kobold/init.rb
|
94
|
+
- lib/Kobold/invoke.rb
|
95
|
+
- lib/Kobold/read_config.rb
|
96
|
+
- lib/Kobold/vars.rb
|
36
97
|
- lib/Kobold/version.rb
|
37
98
|
- prototyping/.gitignore
|
38
99
|
- prototyping/.kobold
|