Skip to content

Commit

Permalink
Migrate to jsonnet
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Jan 3, 2023
1 parent f110171 commit c62bef5
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 113 deletions.
11 changes: 0 additions & 11 deletions .env.dhall

This file was deleted.

11 changes: 11 additions & 0 deletions .env.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local some_variable = "some value'";

{
some_string: some_variable,
some_record: {
some_string: some_variable,
some_naturals: [1, 2, 3],
some_doubles: [1.2, 2.3],
some_strings: ['value1', 'value2']
},
}
24 changes: 5 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PATH
remote: .
specs:
dotcrypt (0.1.3)
dotcrypt (0.2.0)
bootsnap (~> 1.15.0)
dhall (~> 0.5.0)
jsonnet (~> 0.5.0)
thor (~> 1.2.0)
zeitwerk (~> 2.6.0)

Expand All @@ -12,35 +12,23 @@ GEM
specs:
ast (2.4.2)
backport (1.2.0)
base32 (0.3.4)
benchmark (0.2.0)
bootsnap (1.15.0)
msgpack (~> 1.2)
cbor (0.5.9.6)
childprocess (4.1.0)
citrus (3.0.2)
dhall (0.5.5)
base32 (~> 0.3.2)
cbor (~> 0.5.9.3)
citrus (~> 3.0)
lazy_object (>= 0.0.1, < 0.2.0)
multihashes (~> 0.2.0)
promise.rb (~> 0.7.4)
value_semantics (~> 3.0)
diff-lcs (1.5.0)
e2mmap (0.1.0)
iniparse (1.5.0)
jaro_winkler (1.5.4)
json (2.6.2)
jsonnet (0.5.2)
mini_portile2 (>= 2.2.0)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
lazy_object (0.1.0)
mini_portile2 (2.8.1)
msgpack (1.6.0)
multicodecs (0.2.1)
multihashes (0.2.0)
multicodecs (>= 0.2.0, < 1)
nokogiri (1.13.10-x86_64-linux)
racc (~> 1.4)
overcommit (0.59.1)
Expand All @@ -50,7 +38,6 @@ GEM
parallel (1.22.1)
parser (3.1.3.0)
ast (~> 2.4.1)
promise.rb (0.7.4)
racc (1.6.2)
rainbow (3.1.1)
rake (13.0.6)
Expand Down Expand Up @@ -107,7 +94,6 @@ GEM
thor (1.2.1)
tilt (2.0.11)
unicode-display_width (2.3.0)
value_semantics (3.6.1)
webrick (1.7.0)
yard (0.9.28)
webrick (~> 1.7.0)
Expand Down
18 changes: 1 addition & 17 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,4 @@ require "rubocop/rake_task"

RuboCop::RakeTask.new

namespace :dhall do
dhall_files = Dir["./**/.*.dhall"] + Dir["./**/*.dhall"]

def dhall(*args)
system("dhall", *args, exception: true)
end

task :check_fmt do
dhall("format", "--check", *dhall_files)
end

task :fmt do
dhall("format", *dhall_files)
end
end

task default: ["dhall:fmt", :spec, :rubocop]
task default: [:spec, :rubocop]
2 changes: 1 addition & 1 deletion dotcrypt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|

# Uncomment to register a new dependency of your gem
spec.add_dependency "bootsnap", "~> 1.15.0"
spec.add_dependency "dhall", "~> 0.5.0"
spec.add_dependency "jsonnet", "~> 0.5.0"
spec.add_dependency "thor", "~> 1.2.0"
spec.add_dependency "zeitwerk", "~> 2.6.0"

Expand Down
8 changes: 4 additions & 4 deletions lib/dotcrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "yaml"

require "zeitwerk"
require "dhall"
require "jsonnet"
require "thor"

loader = Zeitwerk::Loader.for_gem
Expand All @@ -18,13 +18,13 @@
loader.setup

module Dotcrypt
DEFAULT_NAME = ".env.dhall"
DEFAULT_NAME = ".env.jsonnet"

class Error < StandardError
end

def self.setup(path: find_dotcrypt)
Dotcrypt::Dhall.load_from(path).then do |c|
Dotcrypt::Jsonnet.load_from(path).then do |c|
Dotcrypt::Flattener.call(c).then do |f|
ENV.merge!(f)
return f
Expand All @@ -35,7 +35,7 @@ def self.setup(path: find_dotcrypt)
def self.find_dotcrypt
dir = Dir.getwd
loop do
raise ".env.dhall is noot found" if dir == "/"
raise ".env.jsonnet is noot found" if dir == "/"

path = File.join(dir, DEFAULT_NAME)

Expand Down
4 changes: 2 additions & 2 deletions lib/dotcrypt/CLI/commands/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.included(thor)
thor.class_eval do
include Dotcrypt::Cli::Commands::Globals

desc "exec COMMAND", "exec command a command with dhall env"
desc "exec COMMAND", "exec command a command with env"

def exec(*command) = Handler.new(command, **options).call
end
Expand All @@ -24,7 +24,7 @@ def call
private

def env
@env ||= Dotcrypt::Dhall.load_from(@options[:file]).then do |c|
@env ||= Dotcrypt::Jsonnet.load_from(@options[:file]).then do |c|
# TODO: validate variable names
Dotcrypt::Flattener.call(c, separator: @options[:separator])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dotcrypt/CLI/commands/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.included(thor)

option :file, aliases: :f,
type: :string,
default: ".env.dhall",
desc: "Dhall file to read."
default: ".env.jsonnet",
desc: "Jsonnet file to read."
end
end
end
4 changes: 2 additions & 2 deletions lib/dotcrypt/CLI/commands/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.included(thor) # rubocop:disable Metrics/MethodLength
thor.class_eval do
include Dotcrypt::Cli::Commands::Globals

desc "show", "converts a dhall file into various formats"
desc "show", "converts a jsonnet file into various formats"

option :output, aliases: :o,
type: :string,
Expand All @@ -32,7 +32,7 @@ def call = print(serializer.call(config))
private

def config
@config ||= Dotcrypt::Dhall.load_from(@options[:file]).then do |c|
@config ||= Dotcrypt::Jsonnet.load_from(@options[:file]).then do |c|
next Dotcrypt::Flattener.call(c, separator: @options[:separator]) if @options[:flatten]

c
Expand Down
15 changes: 0 additions & 15 deletions lib/dotcrypt/dhall.rb

This file was deleted.

39 changes: 0 additions & 39 deletions lib/dotcrypt/dhall/as_hash.rb

This file was deleted.

9 changes: 9 additions & 0 deletions lib/dotcrypt/jsonnet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Dotcrypt::Jsonnet
class << self
def load(code) = Jsonnet.evaluate(code)

def load_from(file) = load(File.read(file))
end
end
2 changes: 1 addition & 1 deletion lib/dotcrypt/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Dotcrypt
VERSION = "0.1.3"
VERSION = "0.2.0"
end

0 comments on commit c62bef5

Please sign in to comment.