sublime_text_kit 10.0.2 → 11.0.3
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 +54 -70
- data/{bin → exe}/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 +37 -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 +99 -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 +59 -16
- 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: e84516b60691029bd9bbaabbfcedc6cd2c840aa60415e19fdd52fb0c8152007c
|
4
|
+
data.tar.gz: a6d8a1a7574affde7efa53e48fd15c8cf6df481e1ece6ba7d1797da6ec8c5bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 696d155d918d2276d877756e7f739c76d8f17de619bc38df195c8601f613d19967952f012a7e5effb90a806df111d103107fa8318ddd30f1c382bd56dd936c9e
|
7
|
+
data.tar.gz: 0b5d562219ff73955e04d96af4930dfc672ccff897f77d4e549cf773298b2f7851d3a60bd623ae627de3a541ff06f13c0003bf1c57d89eed87b829bd9ecea743
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -11,22 +11,20 @@ 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, snippets, etc. This allows you to avoiding manual maintenance of your workspace
|
16
|
+
so you can stay focused on your own work.
|
15
17
|
|
16
18
|
toc::[]
|
17
19
|
|
18
20
|
== Features
|
19
21
|
|
20
|
-
*
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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]
|
22
|
+
* Manages project metadata (`.sublime-project` and `.sublime-workspace` files).
|
23
|
+
* Manages session metadata so you can quickly toggle between projects via the `CONTROL+COMMAND+p`
|
24
|
+
shortcut.
|
25
|
+
* Prints all of your custom snippets in either
|
26
|
+
link:https://daringfireball.net/projects/markdown[Markdown] or
|
27
|
+
link:https://asciidoctor.org[ASCII Doc] format.
|
30
28
|
|
31
29
|
== Requirements
|
32
30
|
|
@@ -49,41 +47,14 @@ gem install sublime_text_kit
|
|
49
47
|
From the command line, type: `sublime_text_kit`
|
50
48
|
|
51
49
|
....
|
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.
|
50
|
+
USAGE:
|
51
|
+
-c, --config ACTION Manage gem configuration. Actions: edit or view.
|
52
|
+
-h, --help Show this message.
|
53
|
+
-m, --metadata ACTION Manage project metadata. Actions: create, delete, or recreate.
|
54
|
+
-S, --session Rebuild session metadata.
|
55
|
+
-s, --snippets [FORMAT] View snippets. Default: ascii_doc. Formats: markdown or ascii_doc.
|
56
|
+
-u, --update Update project and session metadata based on current settings.
|
57
|
+
-v, --version Show gem version.
|
87
58
|
....
|
88
59
|
|
89
60
|
=== Customization
|
@@ -97,26 +68,26 @@ An example configuration could be:
|
|
97
68
|
[source,yaml]
|
98
69
|
----
|
99
70
|
:project_roots:
|
100
|
-
- "~/
|
101
|
-
- "~/
|
102
|
-
- "~/Dropbox/Development/Work"
|
71
|
+
- "~/Engineering/Organizations"
|
72
|
+
- "~/Engineering/OSS"
|
103
73
|
:metadata_dir: "~/Dropbox/Cache/Sublime"
|
74
|
+
:snippets_format: :ascii_doc
|
104
75
|
----
|
105
76
|
|
106
|
-
Feel free to take this configuration, modify, and save as your own
|
77
|
+
Feel free to take this configuration, modify, and save as your own.
|
107
78
|
|
108
|
-
The
|
109
|
-
metadata (i.e. `.sublime-project`, `.sublime-workspace`) is generated, the name of the
|
110
|
-
will be the same name as
|
111
|
-
location, is written to the same metadata directory
|
112
|
-
assuming the following directory structure exists…
|
79
|
+
The `project_roots` key defines the root level directories where your project folders are located.
|
80
|
+
When project metadata (i.e. `.sublime-project`, `.sublime-workspace`) is generated, the name of the
|
81
|
+
metadata file will be the same name as the project folder. All project metadata, regardless of root
|
82
|
+
location, is written to the same metadata directory as defined by the `metadata_dir` key. If using
|
83
|
+
the example settings shown above and assuming the following directory structure exists…
|
113
84
|
|
114
85
|
....
|
115
|
-
~/
|
116
|
-
~/
|
86
|
+
~/Engineering/OSS/example
|
87
|
+
~/Engineering/OSS/sublime_text_kit
|
117
88
|
....
|
118
89
|
|
119
|
-
|
90
|
+
...project metadata will be created in the `metadata_dir` as follows:
|
120
91
|
|
121
92
|
....
|
122
93
|
~/Dropbox/Cache/Sublime/example.sublime-project
|
@@ -125,25 +96,33 @@ assuming the following directory structure exists…
|
|
125
96
|
~/Dropbox/Cache/Sublime/sublime_text_kit.sublime-workspace
|
126
97
|
....
|
127
98
|
|
99
|
+
The `snippets_format` key allows you define what format to print your snippets as. The default
|
100
|
+
format is Markdown but you can switch to ASCII Doc too. You can always override your default
|
101
|
+
configuration by specifying the format from the command line: `sublime_text_kit -s ascii_doc`. For
|
102
|
+
example, this is how link:https://www.alchemists.io/projects/sublime_text_setup/#_snippets[snippets
|
103
|
+
documentation] is genereted for the
|
104
|
+
link:https://www.alchemists.io/projects/sublime_text_setup[Sublime Text Setup] project.
|
105
|
+
|
128
106
|
=== Workflow
|
129
107
|
|
130
108
|
The following demonstrates a default Sublime Text setup:
|
131
109
|
|
132
|
-
.
|
133
|
-
|
134
|
-
.
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
. Breeze through your project workload with ease. 😉
|
110
|
+
1. Start by defining your configuration: `sublime_text_kit --config edit`.
|
111
|
+
2. Shutdown Sublime Text (i.e. `COMMAND+q`).
|
112
|
+
3. Run `sublime_text_kit --update` which will create project metadata and rebuild session metadata
|
113
|
+
so Sublime Text has a complete project history from which to switch between via the
|
114
|
+
`CONTROL+COMMMAND+p` shortcut.
|
115
|
+
4. Launch Sublime Text and use the `CONTROL+COMMAND+p` keyboard shortcut to toggle between projects.
|
116
|
+
Notice that you can (fuzzy type) project names to jump between them.
|
117
|
+
5. Navigate through your project workload with ease. 🎉
|
141
118
|
|
142
119
|
=== Troubleshooting
|
143
120
|
|
144
|
-
* When rebuilding
|
145
|
-
|
146
|
-
|
121
|
+
* When rebuilding your session, ensure Sublime Text is shut down or changes might not be applied
|
122
|
+
properly.
|
123
|
+
* When rebuilding project metadata, ensure the `metadata_dir` -- as defined via your configuration
|
124
|
+
-- points to an existing directory which can contain `.sublime-project` and `.sublime-workspace`
|
125
|
+
files.
|
147
126
|
|
148
127
|
== Development
|
149
128
|
|
@@ -189,6 +168,11 @@ participating in this project you agree to abide by its terms.
|
|
189
168
|
|
190
169
|
Read link:CONTRIBUTING.adoc[CONTRIBUTING] for details.
|
191
170
|
|
171
|
+
== Community
|
172
|
+
|
173
|
+
Feel free to link:https://www.alchemists.io/community[join the commmunity] for discussions related
|
174
|
+
to this project and much more.
|
175
|
+
|
192
176
|
== License
|
193
177
|
|
194
178
|
Read link:LICENSE.adoc[LICENSE] for details.
|
@@ -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,37 @@
|
|
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 (must be a symbol): #{kind}. Use: #{formats}." }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :printers, :container
|
28
|
+
|
29
|
+
def formats = printers.keys.map(&:inspect).join(" or ")
|
30
|
+
|
31
|
+
def configuration = container[__method__]
|
32
|
+
|
33
|
+
def logger = container[__method__]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
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,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "versionaire/extensions/option_parser"
|
4
|
+
|
5
|
+
module SublimeTextKit
|
6
|
+
module CLI
|
7
|
+
module Parsers
|
8
|
+
# Handles parsing of Command Line Interface (CLI) core options.
|
9
|
+
class Core
|
10
|
+
def self.call(...) = new(...).call
|
11
|
+
|
12
|
+
def initialize client: CLIENT, container: Container
|
13
|
+
@client = client
|
14
|
+
@container = container
|
15
|
+
end
|
16
|
+
|
17
|
+
def call arguments = []
|
18
|
+
client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
|
19
|
+
client.separator "\nUSAGE:\n"
|
20
|
+
collate
|
21
|
+
arguments.empty? ? arguments : client.parse!(arguments)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :client, :container
|
27
|
+
|
28
|
+
def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
|
29
|
+
|
30
|
+
def add_config
|
31
|
+
client.on(
|
32
|
+
"-c",
|
33
|
+
"--config ACTION",
|
34
|
+
%i[edit view],
|
35
|
+
"Manage gem configuration. Actions: edit or view."
|
36
|
+
) do |action|
|
37
|
+
configuration.action_config = action
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_metadata
|
42
|
+
client.on(
|
43
|
+
"-m",
|
44
|
+
"--metadata ACTION",
|
45
|
+
%i[create delete recreate],
|
46
|
+
"Manage project metadata. Actions: create, delete, or recreate."
|
47
|
+
) do |action|
|
48
|
+
configuration.action_metadata = action
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_session
|
53
|
+
client.on "-S", "--session", "Rebuild session metadata." do
|
54
|
+
configuration.action_session = true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_snippets
|
59
|
+
client.on(
|
60
|
+
"-s",
|
61
|
+
"--snippets [FORMAT]",
|
62
|
+
%i[markdown ascii_doc],
|
63
|
+
"View snippets. Default: #{configuration.snippets_format}. " \
|
64
|
+
"Formats: markdown or ascii_doc."
|
65
|
+
) do |kind|
|
66
|
+
configuration.action_snippets = true
|
67
|
+
configuration.snippets_format = kind if kind
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_update
|
72
|
+
client.on(
|
73
|
+
"-u",
|
74
|
+
"--update",
|
75
|
+
"Update project and session metadata based on current settings."
|
76
|
+
) do
|
77
|
+
configuration.action_update = true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_version
|
82
|
+
client.on "-v", "--version", "Show gem version." do
|
83
|
+
configuration.action_version = Identity::VERSION_LABEL
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_help
|
88
|
+
client.on "-h", "--help", "Show this message." do
|
89
|
+
configuration.action_help = true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private_methods
|
94
|
+
|
95
|
+
def configuration = container[__method__]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|