sublime_text_kit 10.0.2 → 11.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +18 -48
- data/bin/sublime_text_kit +1 -3
- data/lib/sublime_text_kit/cli/actions/config.rb +35 -0
- data/lib/sublime_text_kit/cli/actions/metadata.rb +63 -0
- data/lib/sublime_text_kit/cli/actions/session.rb +26 -0
- data/lib/sublime_text_kit/cli/actions/snippets.rb +35 -0
- data/lib/sublime_text_kit/cli/actions/update.rb +42 -0
- data/lib/sublime_text_kit/cli/configuration/content.rb +45 -0
- data/lib/sublime_text_kit/cli/configuration/defaults.yml +3 -0
- data/lib/sublime_text_kit/cli/configuration/loader.rb +37 -0
- data/lib/sublime_text_kit/cli/parsers/assembler.rb +32 -0
- data/lib/sublime_text_kit/cli/parsers/core.rb +96 -0
- data/lib/sublime_text_kit/cli/parsers.rb +11 -0
- data/lib/sublime_text_kit/cli/shell.rb +58 -0
- data/lib/sublime_text_kit/container.rb +37 -0
- data/lib/sublime_text_kit/identity.rb +3 -2
- data/lib/sublime_text_kit/metadata/handler.rb +43 -0
- data/lib/sublime_text_kit/metadata/pathway.rb +19 -0
- data/lib/sublime_text_kit/metadata/serializers/project.rb +24 -0
- data/lib/sublime_text_kit/metadata/serializers/workspace.rb +27 -0
- data/lib/sublime_text_kit/sessions/rebuilder.rb +44 -0
- data/lib/sublime_text_kit/snippets/collector.rb +13 -19
- data/lib/sublime_text_kit/snippets/model.rb +31 -0
- data/lib/sublime_text_kit/snippets/printers/ascii_doc.rb +7 -5
- data/lib/sublime_text_kit/snippets/printers/markdown.rb +7 -3
- data/lib/sublime_text_kit/snippets/reader.rb +21 -0
- data/lib/sublime_text_kit.rb +11 -10
- data.tar.gz.sig +0 -0
- metadata +56 -14
- metadata.gz.sig +0 -0
- data/lib/sublime_text_kit/cli.rb +0 -182
- data/lib/sublime_text_kit/metadata/base.rb +0 -60
- data/lib/sublime_text_kit/metadata/project_metadata.rb +0 -20
- data/lib/sublime_text_kit/metadata/workspace_metadata.rb +0 -23
- data/lib/sublime_text_kit/session.rb +0 -44
- data/lib/sublime_text_kit/snippets/snippet.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1edd436349eaa5af3d9a56ba765ba547e42d2a50f512e0e2e58b27fe0727a652
|
4
|
+
data.tar.gz: 76c23a4bfc6aa007d0a2f09c7c2ce374d9080ca6c714799a624d22a2aebffbf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b72e4c50adce16c70a3d08f2004afe3bca0e2e617127277829990fd666a506c5b89436a46bc64cc697cf4fae9d72502565a04102f9cbbc7787d0c9b790e1fcd
|
7
|
+
data.tar.gz: 5d2e45a08e168f6d2377b70496e0b1c64b2cc2472524d793263699a5842a18c8cace41a58ef2f523020240810925ad2df316539e40f7599be4729373ed163052
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -11,7 +11,9 @@ image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchem
|
|
11
11
|
[link=https://circleci.com/gh/bkuhlmann/sublime_text_kit]
|
12
12
|
image::https://circleci.com/gh/bkuhlmann/sublime_text_kit.svg?style=svg[Circle CI Status]
|
13
13
|
|
14
|
-
|
14
|
+
Sublime Text Kit is a command line interface for managing Sublime Text metadata for multiple
|
15
|
+
projects, sessions, etc. It's also great for generating the metadata you need, while avoiding manual
|
16
|
+
labor, from existing projects.
|
15
17
|
|
16
18
|
toc::[]
|
17
19
|
|
@@ -23,11 +25,6 @@ toc::[]
|
|
23
25
|
metadata is in a directory) so one can easily toggle between up-to-date project information via
|
24
26
|
the `CONTROL+COMMAND+P` shortcut.
|
25
27
|
|
26
|
-
== Screencasts
|
27
|
-
|
28
|
-
[link=https://www.alchemists.io/screencasts/sublime_text_kit]
|
29
|
-
image::https://www.alchemists.io/images/screencasts/sublime_text_kit/cover.svg[Screencast,600,240,role=focal_point]
|
30
|
-
|
31
28
|
== Requirements
|
32
29
|
|
33
30
|
. link:https://www.ruby-lang.org[Ruby]
|
@@ -49,41 +46,14 @@ gem install sublime_text_kit
|
|
49
46
|
From the command line, type: `sublime_text_kit`
|
50
47
|
|
51
48
|
....
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
For configuration options, type: `sublime_text_kit --help --config`
|
62
|
-
|
63
|
-
....
|
64
|
-
-e, [--edit], [--no-edit] # Edit gem configuration.
|
65
|
-
-i, [--info], [--no-info] # Print gem configuration.
|
66
|
-
....
|
67
|
-
|
68
|
-
For metadata options, type: `sublime_text_kit --help --metadata`
|
69
|
-
|
70
|
-
....
|
71
|
-
-c, [--create], [--no-create] # Create metadata.
|
72
|
-
-D, [--destroy], [--no-destroy] # Destroy metadata.
|
73
|
-
-R, [--rebuild], [--no-rebuild] # Rebuild metadata.
|
74
|
-
....
|
75
|
-
|
76
|
-
For session options, type: `sublime_text_kit --help --session`
|
77
|
-
|
78
|
-
....
|
79
|
-
-R, [--rebuild], [--no-rebuild] # Rebuild session metadata.
|
80
|
-
....
|
81
|
-
|
82
|
-
For snippet options, type: `sublime_text_kit --help --snippets`
|
83
|
-
|
84
|
-
....
|
85
|
-
-a, [--ascii-doc], [--no-ascii-doc] # Print snippets in ASCII Doc format.
|
86
|
-
-m, [--markdown], [--no-markdown] # Print snippets in Markdown format.
|
49
|
+
USAGE:
|
50
|
+
-c, --config ACTION Manage gem configuration. Actions: edit or view.
|
51
|
+
-h, --help Show this message.
|
52
|
+
-m, --metadata ACTION Manage metadata. Actions: create, delete, or recreate.
|
53
|
+
-S, --session Rebuild session.
|
54
|
+
-s, --snippets [FORMAT] View snippets. Default: markdown. Formats: markdown or ascii_doc.
|
55
|
+
-u, --update Update metadata and session based on current settings.
|
56
|
+
-v, --version Show gem version.
|
87
57
|
....
|
88
58
|
|
89
59
|
=== Customization
|
@@ -97,10 +67,10 @@ An example configuration could be:
|
|
97
67
|
[source,yaml]
|
98
68
|
----
|
99
69
|
:project_roots:
|
100
|
-
- "~/
|
101
|
-
- "~/
|
102
|
-
- "~/Dropbox/Development/Work"
|
70
|
+
- "~/Engineering/Contributions"
|
71
|
+
- "~/Engineering/OSS"
|
103
72
|
:metadata_dir: "~/Dropbox/Cache/Sublime"
|
73
|
+
:snippets_format: :ascii_doc
|
104
74
|
----
|
105
75
|
|
106
76
|
Feel free to take this configuration, modify, and save as your own custom `+configuration.yml+`.
|
@@ -112,8 +82,8 @@ location, is written to the same metadata directory. If using the example settin
|
|
112
82
|
assuming the following directory structure exists…
|
113
83
|
|
114
84
|
....
|
115
|
-
~/
|
116
|
-
~/
|
85
|
+
~/Engineering/OSS/example
|
86
|
+
~/Engineering/OSS/sublime_text_kit
|
117
87
|
....
|
118
88
|
|
119
89
|
…the project metadata will be created in the workspace directory as follows:
|
@@ -132,12 +102,12 @@ The following demonstrates a default Sublime Text setup:
|
|
132
102
|
. Run: `sublime_text_kit --config --edit` (define Sublime Text Kit settings for project roots and
|
133
103
|
metadata directory).
|
134
104
|
. Shutdown Sublime Text (i.e. `CONTROL+Q`).
|
135
|
-
. Run: `sublime_text_kit --metadata
|
105
|
+
. Run: `sublime_text_kit --metadata create` (creates project metadata and rebuilds the session
|
136
106
|
metadata so Sublime Text has a complete project history from which to jump through via the
|
137
107
|
`CONTROL+COMMMAND+P` shortcut).
|
138
108
|
. Launch Sublime Text and use the `CONTROL+COMMAND+P` keyboard shortcut to toggle between
|
139
109
|
projects. Notice that you can (fuzzy type) project names to jump between them.
|
140
|
-
. Breeze through your project workload with ease.
|
110
|
+
. Breeze through your project workload with ease. 🎉
|
141
111
|
|
142
112
|
=== Troubleshooting
|
143
113
|
|
data/bin/sublime_text_kit
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "sublime_text_kit"
|
5
|
-
require "sublime_text_kit/cli"
|
6
|
-
require "sublime_text_kit/identity"
|
7
5
|
|
8
6
|
Process.setproctitle SublimeTextKit::Identity::VERSION_LABEL
|
9
|
-
SublimeTextKit::CLI.
|
7
|
+
SublimeTextKit::CLI::Shell.new.call ARGV
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SublimeTextKit
|
4
|
+
module CLI
|
5
|
+
module Actions
|
6
|
+
# Handles gem configuration action.
|
7
|
+
class Config
|
8
|
+
def initialize configuration: Configuration::Loader::HANDLER, container: Container
|
9
|
+
@configuration = configuration
|
10
|
+
@container = container
|
11
|
+
end
|
12
|
+
|
13
|
+
def call action
|
14
|
+
case action
|
15
|
+
when :edit then edit
|
16
|
+
when :view then view
|
17
|
+
else logger.error { "Invalid configuration action: #{action}." }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :configuration, :container
|
24
|
+
|
25
|
+
def edit = kernel.system("$EDITOR #{configuration.current}")
|
26
|
+
|
27
|
+
def view = kernel.system("cat #{configuration.current}")
|
28
|
+
|
29
|
+
def kernel = container[__method__]
|
30
|
+
|
31
|
+
def logger = container[__method__]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/pathnames"
|
4
|
+
|
5
|
+
module SublimeTextKit
|
6
|
+
module CLI
|
7
|
+
module Actions
|
8
|
+
# Handles metadata action.
|
9
|
+
class Metadata
|
10
|
+
using Refinements::Pathnames
|
11
|
+
|
12
|
+
def initialize handler: SublimeTextKit::Metadata::Handler, container: Container
|
13
|
+
@handler = handler
|
14
|
+
@container = container
|
15
|
+
end
|
16
|
+
|
17
|
+
def call kind
|
18
|
+
case kind
|
19
|
+
when :create then create
|
20
|
+
when :delete then delete
|
21
|
+
when :recreate then recreate
|
22
|
+
else logger.error "Unknown metadata action: #{kind}."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :handler, :container
|
29
|
+
|
30
|
+
def create
|
31
|
+
logger.info "Creating metadata in #{metadata_dir}..."
|
32
|
+
process_projects __method__
|
33
|
+
logger.info "Metadata created."
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete
|
37
|
+
logger.info "Deleting metadata in #{metadata_dir}..."
|
38
|
+
process_projects __method__
|
39
|
+
logger.info "Metadata deleted."
|
40
|
+
end
|
41
|
+
|
42
|
+
def recreate
|
43
|
+
logger.info "Recreating metadata in #{metadata_dir}..."
|
44
|
+
process_projects __method__
|
45
|
+
logger.info "Metadata recreated."
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_projects method
|
49
|
+
configuration.project_dirs.each do |directory|
|
50
|
+
handler.with_project(directory, metadata_dir).public_send method
|
51
|
+
handler.with_workspace(directory, metadata_dir).public_send method
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def metadata_dir = Pathname(configuration.metadata_dir).expand_path
|
56
|
+
|
57
|
+
def configuration = container[__method__]
|
58
|
+
|
59
|
+
def logger = container[__method__]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SublimeTextKit
|
4
|
+
module CLI
|
5
|
+
module Actions
|
6
|
+
# Handles session action.
|
7
|
+
class Session
|
8
|
+
def initialize rebuilder: Sessions::Rebuilder.new, container: Container
|
9
|
+
@rebuilder = rebuilder
|
10
|
+
@container = container
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
rebuilder.call
|
15
|
+
logger.info "Session rebuilt."
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :rebuilder, :container
|
21
|
+
|
22
|
+
def logger = container[__method__]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SublimeTextKit
|
4
|
+
module CLI
|
5
|
+
module Actions
|
6
|
+
# Handles snippets action.
|
7
|
+
class Snippets
|
8
|
+
PRINTERS = {
|
9
|
+
ascii_doc: SublimeTextKit::Snippets::Printers::ASCIIDoc.new,
|
10
|
+
markdown: SublimeTextKit::Snippets::Printers::Markdown.new
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize printers: PRINTERS, container: Container
|
14
|
+
@printers = printers
|
15
|
+
@container = container
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
kind = configuration.snippets_format
|
20
|
+
printers.fetch(kind).call
|
21
|
+
rescue KeyError
|
22
|
+
logger.error { "Invalid snippet format: #{kind}." }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :printers, :container
|
28
|
+
|
29
|
+
def configuration = container[__method__]
|
30
|
+
|
31
|
+
def logger = container[__method__]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SublimeTextKit
|
4
|
+
module CLI
|
5
|
+
module Actions
|
6
|
+
# Handles update action.
|
7
|
+
class Update
|
8
|
+
def initialize metadata: SublimeTextKit::Metadata::Handler,
|
9
|
+
session: Sessions::Rebuilder.new,
|
10
|
+
container: Container
|
11
|
+
@metadata = metadata
|
12
|
+
@session = session
|
13
|
+
@container = container
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
logger.info "Updating metadata and session..."
|
18
|
+
create_metadata
|
19
|
+
session.call
|
20
|
+
logger.info "Metadata and session updated."
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :metadata, :session, :container
|
26
|
+
|
27
|
+
def create_metadata
|
28
|
+
configuration.project_dirs.each do |directory|
|
29
|
+
metadata.with_project(directory, metadata_dir).create
|
30
|
+
metadata.with_workspace(directory, metadata_dir).create
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def metadata_dir = Pathname(configuration.metadata_dir).expand_path
|
35
|
+
|
36
|
+
def configuration = container[__method__]
|
37
|
+
|
38
|
+
def logger = container[__method__]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/pathnames"
|
4
|
+
|
5
|
+
module SublimeTextKit
|
6
|
+
module CLI
|
7
|
+
module Configuration
|
8
|
+
# Defines configuration content as the primary source of truth for use throughout the gem.
|
9
|
+
Content = Struct.new(
|
10
|
+
:action_config,
|
11
|
+
:action_help,
|
12
|
+
:action_metadata,
|
13
|
+
:action_session,
|
14
|
+
:action_snippets,
|
15
|
+
:action_update,
|
16
|
+
:action_version,
|
17
|
+
:project_roots,
|
18
|
+
:metadata_dir,
|
19
|
+
:snippets_format,
|
20
|
+
:session_path,
|
21
|
+
:user_dir,
|
22
|
+
keyword_init: true
|
23
|
+
) do
|
24
|
+
using Refinements::Pathnames
|
25
|
+
|
26
|
+
def initialize *arguments
|
27
|
+
super
|
28
|
+
|
29
|
+
home = Pathname ENV["HOME"]
|
30
|
+
|
31
|
+
self[:session_path] ||= home.join(
|
32
|
+
"Library/Application Support/Sublime Text/Local/Session.sublime_session"
|
33
|
+
)
|
34
|
+
|
35
|
+
self[:user_dir] ||= home.join "Library/Application Support/Sublime Text/Packages/User"
|
36
|
+
end
|
37
|
+
|
38
|
+
def project_dirs
|
39
|
+
Array(project_roots).map { |path| Pathname(path).expand_path }
|
40
|
+
.flat_map(&:directories)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require "refinements/hashes"
|
5
|
+
require "refinements/structs"
|
6
|
+
require "runcom"
|
7
|
+
require "yaml"
|
8
|
+
|
9
|
+
module SublimeTextKit
|
10
|
+
module CLI
|
11
|
+
module Configuration
|
12
|
+
# Represents the fully assembled Command Line Interface (CLI) configuration.
|
13
|
+
class Loader
|
14
|
+
using Refinements::Hashes
|
15
|
+
using Refinements::Structs
|
16
|
+
|
17
|
+
DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
|
18
|
+
HANDLER = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
|
19
|
+
|
20
|
+
def self.call = new.call
|
21
|
+
|
22
|
+
def self.with_defaults = new(handler: DEFAULTS)
|
23
|
+
|
24
|
+
def initialize content: Content.new, handler: HANDLER
|
25
|
+
@content = content
|
26
|
+
@handler = handler
|
27
|
+
end
|
28
|
+
|
29
|
+
def call = content.merge(**handler.to_h.flatten_keys)
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :content, :handler
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "runcom"
|
4
|
+
|
5
|
+
module SublimeTextKit
|
6
|
+
module CLI
|
7
|
+
module Parsers
|
8
|
+
# Assembles and parses all Command Line Interface (CLI) options.
|
9
|
+
class Assembler
|
10
|
+
def initialize section: Core, client: CLIENT, container: Container
|
11
|
+
@section = section
|
12
|
+
@client = client
|
13
|
+
@container = container
|
14
|
+
end
|
15
|
+
|
16
|
+
def call arguments = []
|
17
|
+
section.call client: client
|
18
|
+
client.parse! arguments
|
19
|
+
configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s = client.to_s
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :section, :client, :container
|
27
|
+
|
28
|
+
def configuration = container[__method__]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "versionaire/extensions/option_parser"
|
4
|
+
|
5
|
+
module SublimeTextKit
|
6
|
+
module CLI
|
7
|
+
# Handles parsing of Command Line Interface (CLI) primary options.
|
8
|
+
module Parsers
|
9
|
+
# Handles parsing of Command Line Interface (CLI) core options.
|
10
|
+
class Core
|
11
|
+
def self.call(...) = new(...).call
|
12
|
+
|
13
|
+
def initialize client: CLIENT, container: Container
|
14
|
+
@client = client
|
15
|
+
@container = container
|
16
|
+
end
|
17
|
+
|
18
|
+
def call arguments = []
|
19
|
+
client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
|
20
|
+
client.separator "\nUSAGE:\n"
|
21
|
+
collate
|
22
|
+
arguments.empty? ? arguments : client.parse!(arguments)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :client, :container
|
28
|
+
|
29
|
+
def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
|
30
|
+
|
31
|
+
def add_config
|
32
|
+
client.on(
|
33
|
+
"-c",
|
34
|
+
"--config ACTION",
|
35
|
+
%i[edit view],
|
36
|
+
"Manage gem configuration. Actions: edit or view."
|
37
|
+
) do |action|
|
38
|
+
configuration.action_config = action
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_metadata
|
43
|
+
client.on(
|
44
|
+
"-m",
|
45
|
+
"--metadata ACTION",
|
46
|
+
%i[create delete recreate],
|
47
|
+
"Manage metadata. Actions: create, delete, or recreate."
|
48
|
+
) do |action|
|
49
|
+
configuration.action_metadata = action
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_session
|
54
|
+
client.on "-S", "--session", "Rebuild session." do
|
55
|
+
configuration.action_session = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_snippets
|
60
|
+
client.on(
|
61
|
+
"-s",
|
62
|
+
"--snippets [FORMAT]",
|
63
|
+
%i[markdown ascii_doc],
|
64
|
+
"View snippets. Default: #{configuration.snippets_format}. " \
|
65
|
+
"Formats: markdown or ascii_doc."
|
66
|
+
) do |kind|
|
67
|
+
configuration.action_snippets = true
|
68
|
+
configuration.snippets_format = kind if kind
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_update
|
73
|
+
client.on "-u", "--update", "Update metadata and session based on current settings." do
|
74
|
+
configuration.action_update = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_version
|
79
|
+
client.on "-v", "--version", "Show gem version." do
|
80
|
+
configuration.action_version = Identity::VERSION_LABEL
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def add_help
|
85
|
+
client.on "-h", "--help", "Show this message." do
|
86
|
+
configuration.action_help = true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private_methods
|
91
|
+
|
92
|
+
def configuration = container[__method__]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SublimeTextKit
|
4
|
+
module CLI
|
5
|
+
# The main Command Line Interface (CLI) object.
|
6
|
+
class Shell
|
7
|
+
ACTIONS = {
|
8
|
+
config: Actions::Config.new,
|
9
|
+
metadata: Actions::Metadata.new,
|
10
|
+
session: Actions::Session.new,
|
11
|
+
snippets: Actions::Snippets.new,
|
12
|
+
update: Actions::Update.new
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def initialize parser: Parsers::Assembler.new, actions: ACTIONS, container: Container
|
16
|
+
@parser = parser
|
17
|
+
@actions = actions
|
18
|
+
@container = container
|
19
|
+
end
|
20
|
+
|
21
|
+
def call arguments = []
|
22
|
+
perform parser.call(arguments)
|
23
|
+
rescue OptionParser::ParseError, Error => error
|
24
|
+
logger.error { error.message }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :parser, :actions, :container
|
30
|
+
|
31
|
+
def perform configuration
|
32
|
+
case configuration
|
33
|
+
in action_config: Symbol => action then config action
|
34
|
+
in action_metadata: Symbol => kind then metadata kind
|
35
|
+
in action_session: true then session
|
36
|
+
in action_snippets: true then snippets
|
37
|
+
in action_update: true then update
|
38
|
+
in action_version: String => version then logger.info version
|
39
|
+
else usage
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def config(action) = actions.fetch(__method__).call(action)
|
44
|
+
|
45
|
+
def metadata(kind) = actions.fetch(__method__).call(kind)
|
46
|
+
|
47
|
+
def session = actions.fetch(__method__).call
|
48
|
+
|
49
|
+
def snippets = actions.fetch(__method__).call
|
50
|
+
|
51
|
+
def update = actions.fetch(__method__).call
|
52
|
+
|
53
|
+
def usage = logger.unknown { parser.to_s }
|
54
|
+
|
55
|
+
def logger = container[__method__]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry-container"
|
4
|
+
require "logger"
|
5
|
+
require "pastel"
|
6
|
+
|
7
|
+
module SublimeTextKit
|
8
|
+
# Provides a global gem container for injection into other objects.
|
9
|
+
module Container
|
10
|
+
extend Dry::Container::Mixin
|
11
|
+
|
12
|
+
register(:configuration, memoize: true) { CLI::Configuration::Loader.call }
|
13
|
+
register(:colorizer) { Pastel.new enabled: $stdout.tty? }
|
14
|
+
register(:kernel) { Kernel }
|
15
|
+
|
16
|
+
register :log_colors do
|
17
|
+
{
|
18
|
+
"DEBUG" => self[:colorizer].white.detach,
|
19
|
+
"INFO" => self[:colorizer].green.detach,
|
20
|
+
"WARN" => self[:colorizer].yellow.detach,
|
21
|
+
"ERROR" => self[:colorizer].red.detach,
|
22
|
+
"FATAL" => self[:colorizer].white.bold.on_red.detach,
|
23
|
+
"ANY" => self[:colorizer].white.bold.detach
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
register :logger do
|
28
|
+
Logger.new $stdout,
|
29
|
+
level: Logger.const_get(ENV.fetch("LOG_LEVEL", "INFO")),
|
30
|
+
formatter: (
|
31
|
+
lambda do |severity, _at, _name, message|
|
32
|
+
self[:log_colors][severity].call "#{message}\n"
|
33
|
+
end
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -5,7 +5,8 @@ module SublimeTextKit
|
|
5
5
|
module Identity
|
6
6
|
NAME = "sublime_text_kit"
|
7
7
|
LABEL = "Sublime Text Kit"
|
8
|
-
VERSION = "
|
9
|
-
VERSION_LABEL = "#{LABEL} #{VERSION}"
|
8
|
+
VERSION = "11.0.0"
|
9
|
+
VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
|
10
|
+
SUMMARY = "A command line interface for managing Sublime Text metadata."
|
10
11
|
end
|
11
12
|
end
|