bdgtr-cli 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 20569023fb9af1020141d0441447f5a5a590e0296cd975cd14962f173ddc4d7c
4
+ data.tar.gz: d5929692daa4c73f203d75ffa2c221e4620640648a695412acbc9669d933a923
5
+ SHA512:
6
+ metadata.gz: 45f1a71a7b9f6dd0240fc2fd9aec733a763312199e674a8c3fafb91275e60d76a34a3e2f713c4e64527e828776db3fd6f83364af86db63ab935652490325ed42
7
+ data.tar.gz: 8883bee82f9d4f97f636dac4f43e65e6d0dee80be058df668f9587c2e8376b35c2eede6a1efa36c40a141b3ec3af1d538edc70188940f952070997ea9c75fd71
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Antonio Molinari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # bdgtr-cli
2
+
3
+ Command line for bdgtr. The gem keeps `~/.bdgtr/config.yml` and `~/.bdgtr/bdgtr.sqlite`. Installing the gem creates both when they are missing, and leaves an existing ledger file in place.
4
+
5
+ Account, transaction, and ledger commands load the Rails app from `BDGTR_ROOT` or from `bdgtr.root` in the config file.
6
+
7
+ Release from the Rails app root: `bin/release-cli`
data/bin/bdgtr ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bdgtr_cli"
5
+
6
+ Bdgtr::Cli::GemHome.install!
7
+
8
+ if %w[--version -v].include?(ARGV[0]) && defined?(Bdgtr::Version)
9
+ puts "bdgtr-cli #{Bdgtr::Version::VERSION}"
10
+ exit 0
11
+ end
12
+
13
+ if ARGV[0] == "ledger:reset"
14
+ Bdgtr::Cli::GemHome.reset_with_confirmation!
15
+ exit 0
16
+ end
17
+
18
+ root = Bdgtr::Cli::GemHome.app_root
19
+ unless root
20
+ warn "Set BDGTR_ROOT, or bdgtr.root in #{Bdgtr::Cli::GemHome.config_path}, to the bdgtr app."
21
+ exit 1
22
+ end
23
+
24
+ ENV["BUNDLE_GEMFILE"] ||= File.join(root, "Gemfile")
25
+ ENV["BDGTR_ROOT"] ||= root
26
+ require File.join(root, "config/environment")
27
+ Bdgtr::Cli.start(ARGV)
@@ -0,0 +1,15 @@
1
+ bdgtr:
2
+ workspace_id:
3
+ url: https://app.bdgtr.com
4
+ token:
5
+ ledger: bdgtr.sqlite
6
+
7
+ api:
8
+ nordigen:
9
+ secret_id:
10
+ secret_key:
11
+ # enablebanking: /path/to/private-key.pem
12
+ enablebanking:
13
+ app_id:
14
+ private_key:
15
+ redirect_url:
data/data/bdgtr.sqlite ADDED
Binary file
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "yaml"
5
+
6
+ module Bdgtr
7
+ class Cli
8
+ # Files the installed gem keeps in ~/.bdgtr. An existing ledger is left in place.
9
+ module GemHome
10
+ module_function
11
+
12
+ def home_dir
13
+ chosen = ENV["BDGTR_HOME"].to_s.strip
14
+ return chosen unless chosen.empty?
15
+
16
+ File.join(Dir.home, ".bdgtr")
17
+ end
18
+
19
+ def config_path
20
+ File.join(home_dir, "config.yml")
21
+ end
22
+
23
+ def ledger_path
24
+ File.join(home_dir, "bdgtr.sqlite")
25
+ end
26
+
27
+ def install!
28
+ FileUtils.mkdir_p(home_dir)
29
+ sample = sample_path
30
+ FileUtils.cp(sample, config_path) if sample && !File.exist?(config_path)
31
+ return if File.exist?(ledger_path)
32
+
33
+ source = blank_ledger_path
34
+ raise "empty ledger is missing from the bdgtr-cli gem" unless source
35
+
36
+ FileUtils.cp(source, ledger_path)
37
+ end
38
+
39
+ def reset!
40
+ source = blank_ledger_path
41
+ raise "empty ledger is missing from the bdgtr-cli gem" unless source
42
+
43
+ FileUtils.mkdir_p(home_dir)
44
+ FileUtils.rm_f(ledger_path)
45
+ FileUtils.cp(source, ledger_path)
46
+ ledger_path
47
+ end
48
+
49
+ def reset_with_confirmation!(input: $stdin, output: $stdout, error: $stderr)
50
+ path = ledger_path
51
+ output.puts "Replace #{path} with an empty ledger."
52
+ output.print "Type yes to continue: "
53
+ output.flush
54
+ answer = input.gets
55
+ unless answer&.strip == "yes"
56
+ error.puts "Aborted."
57
+ exit 1
58
+ end
59
+
60
+ reset!
61
+ output.puts "Replaced #{path} with an empty ledger."
62
+ end
63
+
64
+ def app_root
65
+ env = ENV["BDGTR_ROOT"].to_s.strip
66
+ return env if rails_app?(env)
67
+
68
+ configured = config_root
69
+ return configured if rails_app?(configured)
70
+
71
+ nil
72
+ end
73
+
74
+ def blank_ledger_path
75
+ packaged("data/bdgtr.sqlite")
76
+ end
77
+
78
+ def sample_path
79
+ packaged("config/config.sample.yml")
80
+ end
81
+
82
+ def packaged(relative)
83
+ candidates = []
84
+ spec = Gem.loaded_specs["bdgtr-cli"] if defined?(Gem) && Gem.respond_to?(:loaded_specs)
85
+ candidates << File.join(spec.full_gem_path, relative) if spec
86
+ candidates << File.expand_path("../../../#{relative}", __dir__)
87
+ found = candidates.find { |path| File.file?(path) }
88
+ return found if found
89
+ return unless relative == "config/config.sample.yml"
90
+
91
+ File.expand_path("../../../../lib/bdgtr/cli/config.sample.yml", __dir__) if File.file?(File.expand_path("../../../../lib/bdgtr/cli/config.sample.yml", __dir__))
92
+ end
93
+
94
+ def rails_app?(path)
95
+ !path.to_s.empty? && File.file?(File.join(path, "config/environment.rb"))
96
+ end
97
+
98
+ def config_root
99
+ return unless File.file?(config_path)
100
+
101
+ data = YAML.safe_load_file(config_path, aliases: false) || {}
102
+ text = data.dig("bdgtr", "root").to_s.strip
103
+ return if text.empty?
104
+
105
+ File.expand_path(text)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bdgtr
4
+ # Kept for Zeitwerk (`lib/bdgtr/version.rb` → Bdgtr::Version).
5
+ module Version
6
+ VERSION = "0.1.0"
7
+
8
+ def self.to_s
9
+ VERSION
10
+ end
11
+ end
12
+ end
data/lib/bdgtr_cli.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bdgtr/cli/gem_home"
4
+
5
+ version = File.expand_path("bdgtr/version.rb", __dir__)
6
+ version = File.expand_path("../../lib/bdgtr/version.rb", __dir__) unless File.file?(version)
7
+ require version if File.file?(version)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Loaded automatically by RubyGems. Keep this file tiny; work happens in the hook.
4
+ Gem.post_install do |installer|
5
+ next unless installer.spec.name == "bdgtr-cli"
6
+
7
+ begin
8
+ require "bdgtr_cli"
9
+ Bdgtr::Cli::GemHome.install!
10
+ rescue LoadError, StandardError => e
11
+ warn "bdgtr-cli post-install: #{e.message}"
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bdgtr-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Molinari
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: bdgtr-cli installs ~/.bdgtr/config.yml and an empty ledger, and runs
13
+ the bdgtr commands.
14
+ email:
15
+ - ''
16
+ executables:
17
+ - bdgtr
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/bdgtr
24
+ - config/config.sample.yml
25
+ - data/bdgtr.sqlite
26
+ - lib/bdgtr/cli/gem_home.rb
27
+ - lib/bdgtr/version.rb
28
+ - lib/bdgtr_cli.rb
29
+ - lib/rubygems_plugin.rb
30
+ homepage: https://github.com/magnum/bdgtr
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://github.com/magnum/bdgtr
35
+ source_code_uri: https://github.com/magnum/bdgtr
36
+ changelog_uri: https://github.com/magnum/bdgtr/blob/main/CHANGELOG.md
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 3.2.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 4.0.20
52
+ specification_version: 4
53
+ summary: Command line for bdgtr ledgers, accounts, and bank sync
54
+ test_files: []