cafeznik 0.5.5 → 0.5.6
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/lib/cafeznik/cli.rb +13 -8
- data/lib/cafeznik/content.rb +4 -4
- data/lib/cafeznik/sources/base.rb +16 -1
- data/lib/cafeznik/sources/github.rb +2 -3
- data/lib/cafeznik/sources/local.rb +1 -1
- data/lib/cafeznik/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2abff3c957276ec2a1f6940fdc92dad37079041610e61808c2ed1f893f58c98e
|
4
|
+
data.tar.gz: 786bed8ddf8bdb11077ef7c160fd78b44dde0b69cfb448b1643c4719fb04325d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3611ae969829a85bfb121b4dff466ce9dc47deaff50be4f25dc22a7b4ca769f1e4dc1b4398b6d3d23137c8ff5f10b88e0a57c1b38d4528a05da75f34cc2d6a1b
|
7
|
+
data.tar.gz: 81ec059fa02de6149dc46c8f228ee922e205c3bfd94b7f5b1631c504febdb644b2a8610b1f89c650c7b0aafb840083df7359a86f01801d7bd753b60a116cb31e
|
data/lib/cafeznik/cli.rb
CHANGED
@@ -1,19 +1,25 @@
|
|
1
1
|
require "thor"
|
2
|
-
|
3
2
|
module Cafeznik
|
4
3
|
class CLI < Thor
|
5
4
|
def self.exit_on_failure? = true
|
6
5
|
def self.user_agrees? = $stdin.gets.strip.casecmp("y").zero?
|
7
6
|
|
8
|
-
class_option :verbose, type: :boolean, aliases: "
|
7
|
+
class_option :verbose, type: :boolean, aliases: "--debug", default: false, desc: "Run in verbose mode"
|
9
8
|
class_option :no_header, type: :boolean, default: false, desc: "Exclude headers"
|
10
9
|
class_option :with_tree, type: :boolean, aliases: "-t", default: false, desc: "Include file tree"
|
11
10
|
class_option :grep, type: :string, aliases: "-g", desc: "Filter files containing the specified content"
|
12
11
|
class_option :exclude, type: :array, aliases: "-e", desc: "Exclude files/folders matching patterns"
|
13
12
|
|
13
|
+
map %w[-v --version] => :version
|
14
|
+
|
15
|
+
desc "version", "Show version"
|
16
|
+
def version
|
17
|
+
puts "Cafeznik #{Cafeznik::VERSION}"
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
14
21
|
desc "default", "Select files, copy to clipboard; use --repo/-r for GitHub repository"
|
15
22
|
method_option :repo, type: :string, aliases: "-r", desc: "GitHub repository (owner/repo format)"
|
16
|
-
|
17
23
|
default_task :default
|
18
24
|
|
19
25
|
def default
|
@@ -21,12 +27,11 @@ module Cafeznik
|
|
21
27
|
Log.info "Running in #{repo ? 'GitHub' : 'local'} mode"
|
22
28
|
|
23
29
|
source = determine_source
|
30
|
+
file_paths = Selector.new(source).select
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Content.new( # TODO: find better name than Content, perhaps Clipboard?
|
29
|
-
source:, file_paths:,
|
32
|
+
Content.new(
|
33
|
+
source: source,
|
34
|
+
file_paths: file_paths,
|
30
35
|
include_headers: !options[:no_header],
|
31
36
|
include_tree: options[:with_tree]
|
32
37
|
).copy_to_clipboard
|
data/lib/cafeznik/content.rb
CHANGED
@@ -4,7 +4,7 @@ require "memery"
|
|
4
4
|
module Cafeznik
|
5
5
|
class Content
|
6
6
|
include Memery
|
7
|
-
MAX_LINES =
|
7
|
+
MAX_LINES = 10
|
8
8
|
|
9
9
|
def initialize(source:, file_paths:, include_headers:, include_tree:)
|
10
10
|
Log.debug "Initializing Content" do
|
@@ -37,7 +37,7 @@ module Cafeznik
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
|
40
|
+
def build_content = [tree_section, files_contents.join("\n\n")].flatten.compact.join("\n\n")
|
41
41
|
|
42
42
|
memoize def files_contents
|
43
43
|
Log.debug "Processing #{@file_paths.size} files"
|
@@ -50,7 +50,7 @@ module Cafeznik
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
def tree_section = @include_tree ? with_header(@source.tree.drop(1).join("\n"), "Tree") : nil
|
54
54
|
def with_header(content, title) = "==> #{title} <==\n#{content}"
|
55
55
|
|
56
56
|
def confirm_size!
|
@@ -58,7 +58,7 @@ module Cafeznik
|
|
58
58
|
return true if line_count <= MAX_LINES
|
59
59
|
|
60
60
|
if @include_tree && suggest_tree_removal?
|
61
|
-
Log.warn "Content exceeds #{MAX_LINES} lines (#{line_count}). Try cutting out the tree
|
61
|
+
Log.warn "Content exceeds #{MAX_LINES} lines (#{line_count}). Try cutting out the tree?? (y/N)"
|
62
62
|
@include_tree = false
|
63
63
|
@content = build_content
|
64
64
|
return confirm_size! if CLI.user_agrees?
|
@@ -1,11 +1,26 @@
|
|
1
1
|
module Cafeznik
|
2
2
|
module Source
|
3
3
|
class Base
|
4
|
+
BINARY_EXCLUDES = [
|
5
|
+
# Images and media
|
6
|
+
%w[*.png *.jpg *.jpeg *.gif *.svg *.ico],
|
7
|
+
%w[*.pdf *.mov *.mp4 *.mp3 *.wav],
|
8
|
+
# Archives
|
9
|
+
%w[*.zip *.tar.gz *.tgz *.rar *.7z],
|
10
|
+
# Compiled code
|
11
|
+
%w[*.pyc *.pyo *.class *.jar *.dll],
|
12
|
+
%w[*.exe *.so *.dylib *.o *.obj],
|
13
|
+
# Minified files
|
14
|
+
%w[*.min.js *.min.css],
|
15
|
+
# Pesky necessities
|
16
|
+
%w[.git .DS_Store Thumbs.db]
|
17
|
+
].flatten.freeze
|
18
|
+
|
4
19
|
# TODO: change to `root: nil, repo: nil`
|
5
20
|
def initialize(repo: nil, grep: nil, exclude: [])
|
6
21
|
@repo = repo
|
7
22
|
@grep = grep
|
8
|
-
@exclude = exclude
|
23
|
+
@exclude = Array(exclude) + BINARY_EXCLUDES
|
9
24
|
end
|
10
25
|
|
11
26
|
def tree = raise NotImplementedError
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "base"
|
2
2
|
require "octokit"
|
3
3
|
require "base64"
|
4
|
-
require "resolv" # TODO: why is this here?
|
5
4
|
|
6
5
|
module Cafeznik
|
7
6
|
module Source
|
@@ -20,7 +19,7 @@ module Cafeznik
|
|
20
19
|
end
|
21
20
|
rescue Octokit::Error => e
|
22
21
|
Log.error "Error fetching GitHub tree: #{e.message}"
|
23
|
-
|
22
|
+
[]
|
24
23
|
end
|
25
24
|
|
26
25
|
def content(path)
|
@@ -59,7 +58,7 @@ module Cafeznik
|
|
59
58
|
def full_tree
|
60
59
|
branch = @client.repository(@repo).default_branch
|
61
60
|
# get all all paths and add a trailing slash for directories
|
62
|
-
paths = @client.tree(@repo, branch, recursive: true).tree.map { "#{
|
61
|
+
paths = @client.tree(@repo, branch, recursive: true).tree.map { "#{it.path}#{'/' if it.type == 'tree'}" }
|
63
62
|
(["./"] + paths).sort
|
64
63
|
end
|
65
64
|
|
@@ -7,6 +7,7 @@ module Cafeznik
|
|
7
7
|
class Local < Base
|
8
8
|
include Memery
|
9
9
|
def initialize(grep: nil, exclude: [])
|
10
|
+
Log.debug "Local source initialized with grep: #{grep}, exclude: #{exclude}"
|
10
11
|
super
|
11
12
|
Log.fatal "fd not installed. We depend on it. Get it!" unless ToolChecker.fd_available?
|
12
13
|
|
@@ -14,7 +15,6 @@ module Cafeznik
|
|
14
15
|
end
|
15
16
|
|
16
17
|
memoize def tree
|
17
|
-
Log.debug "Building file tree#{@grep ? ' with grep filter' : ''}, #{@exclude ? "excluding: #{@exclude.join(',')}" : ''}"
|
18
18
|
files = @grep ? grepped_files : full_tree
|
19
19
|
files.empty? ? [] : ["./"] + files.sort
|
20
20
|
end
|
data/lib/cafeznik/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafeznik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lem
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: base64
|
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
261
|
- !ruby/object:Gem::Version
|
262
262
|
version: '0'
|
263
263
|
requirements: []
|
264
|
-
rubygems_version: 3.6.
|
264
|
+
rubygems_version: 3.6.4
|
265
265
|
specification_version: 4
|
266
266
|
summary: CLI tool for copying files to your clipboard en masse
|
267
267
|
test_files: []
|