File tree Expand file tree Collapse file tree 6 files changed +78
-2
lines changed
Expand file tree Collapse file tree 6 files changed +78
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88
99
10+ ## [ Unreleased]
11+
12+ ## Added
13+
14+ - CLI: Use diffcrypt from command line of any project without requiring ruby integration
15+ - CLI: ` diffcrypt encrypt ` Directly encrypt any file and output the contents
16+ - CLI: ` diffcrypt decrypt ` Directly decrypt any file and output the contents
17+
18+
19+
1020## [ 0.2.0] - 2020-06-28
1121
1222### Added
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env ruby
2+ # frozen_string_literal: true
3+
4+ require 'thor'
5+
6+ require_relative '../lib/diffcrypt/cli'
7+
8+ Diffcrypt ::CLI . start ( ARGV )
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ Gem::Specification.new do |spec|
2525 spec . files = Dir . chdir ( File . expand_path ( __dir__ ) ) do
2626 `git ls-files -z` . split ( "\x0 " ) . reject { |f | f . match ( %r{^(test|spec|features)/} ) }
2727 end
28- spec . bindir = 'exe '
29- spec . executables = spec . files . grep ( %r{^exe/} ) { | f | File . basename ( f ) }
28+ spec . bindir = 'bin '
29+ spec . executables = %w[ diffcrypt ]
3030 spec . require_paths = [ 'lib' ]
3131
3232 spec . add_runtime_dependency 'activesupport' , '~> 6.0.0'
33+ spec . add_runtime_dependency 'thor' , '~> 1.0.1'
3334end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative './encryptor'
4+ require_relative './version'
5+
6+ module Diffcrypt
7+ class CLI < Thor
8+ desc 'decrypt <path>' , 'Decrypt a file'
9+ method_option :key , aliases : %i[ k ] , required : true
10+ def decrypt ( path )
11+ ensure_file_exists ( path )
12+ contents = File . read ( path )
13+ puts encryptor . decrypt ( contents )
14+ end
15+
16+ desc 'encrypt <path>' , 'Encrypt a file'
17+ method_option :key , aliases : %i[ k ] , required : true
18+ def encrypt ( path )
19+ ensure_file_exists ( path )
20+ contents = File . read ( path )
21+ puts encryptor . encrypt ( contents )
22+ end
23+
24+ desc 'version' , 'Show client version'
25+ def version
26+ say Diffcrypt ::VERSION
27+ end
28+
29+ no_commands do
30+ def key
31+ options [ :key ]
32+ end
33+
34+ def encryptor
35+ @encryptor ||= Encryptor . new ( key )
36+ end
37+
38+ def ensure_file_exists ( path )
39+ abort ( '[ERROR] File does not exist' ) unless File . exist? ( path )
40+ end
41+ end
42+ end
43+ end
Original file line number Diff line number Diff line change 88
99require 'active_support/message_encryptor'
1010
11+ require_relative './version'
12+
1113module Diffcrypt
1214 class Encryptor
1315 CIPHER = 'aes-128-gcm'
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'test_helper'
4+ require 'thor'
5+
6+ require_relative '../../lib/diffcrypt/cli'
7+
8+ class Diffcrypt ::CLITest < Minitest ::Test
9+ def test_it_extends_thor
10+ assert Diffcrypt ::CLI < Thor
11+ end
12+ end
You can’t perform that action at this time.
0 commit comments