snippet_cli 0.3.6 → 0.5.2

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -15
  3. data/exe/snippet_cli +45 -11
  4. data/lib/snippet_cli/Espanso_Merged_Matchfile_Schema.json +889 -0
  5. data/lib/snippet_cli/banner.rb +16 -0
  6. data/lib/snippet_cli/commands/check.rb +49 -0
  7. data/lib/snippet_cli/commands/conflict.rb +75 -0
  8. data/lib/snippet_cli/commands/new.rb +16 -102
  9. data/lib/snippet_cli/commands/vars.rb +58 -0
  10. data/lib/snippet_cli/commands/version.rb +17 -0
  11. data/lib/snippet_cli/conflict_detector.rb +71 -0
  12. data/lib/snippet_cli/cursor_helper.rb +20 -0
  13. data/lib/snippet_cli/espanso_config.rb +26 -0
  14. data/lib/snippet_cli/file_helper.rb +16 -0
  15. data/lib/snippet_cli/file_validator.rb +33 -0
  16. data/lib/snippet_cli/file_writer.rb +12 -0
  17. data/lib/snippet_cli/form_field_parser.rb +13 -0
  18. data/lib/snippet_cli/global_vars_formatter.rb +63 -0
  19. data/lib/snippet_cli/global_vars_writer.rb +29 -0
  20. data/lib/snippet_cli/gum_theme.rb +39 -0
  21. data/lib/snippet_cli/hash_utils.rb +21 -0
  22. data/lib/snippet_cli/match_file_writer.rb +26 -0
  23. data/lib/snippet_cli/match_validator.rb +33 -0
  24. data/lib/snippet_cli/new_workflow.rb +98 -0
  25. data/lib/snippet_cli/replacement_text_collector.rb +55 -0
  26. data/lib/snippet_cli/replacement_validator.rb +35 -0
  27. data/lib/snippet_cli/replacement_wizard.rb +100 -0
  28. data/lib/snippet_cli/schema_validator.rb +27 -0
  29. data/lib/snippet_cli/snippet_builder.rb +133 -0
  30. data/lib/snippet_cli/string_helper.rb +11 -0
  31. data/lib/snippet_cli/table_formatter.rb +37 -0
  32. data/lib/snippet_cli/trigger_resolver.rb +67 -0
  33. data/lib/snippet_cli/ui.rb +90 -0
  34. data/lib/snippet_cli/var_builder/form_fields.rb +54 -0
  35. data/lib/snippet_cli/var_builder/name_collector.rb +69 -0
  36. data/lib/snippet_cli/var_builder/param_schema.rb +71 -0
  37. data/lib/snippet_cli/var_builder/params.rb +127 -0
  38. data/lib/snippet_cli/var_builder.rb +125 -0
  39. data/lib/snippet_cli/var_summary_renderer.rb +48 -0
  40. data/lib/snippet_cli/var_usage_checker.rb +48 -0
  41. data/lib/snippet_cli/var_yaml_renderer.rb +20 -0
  42. data/lib/snippet_cli/vars_block_renderer.rb +15 -0
  43. data/lib/snippet_cli/version.rb +3 -1
  44. data/lib/snippet_cli/wizard_context.rb +13 -0
  45. data/lib/snippet_cli/wizard_helpers/error_handler.rb +20 -0
  46. data/lib/snippet_cli/wizard_helpers/match_file_selector.rb +32 -0
  47. data/lib/snippet_cli/wizard_helpers/prompt_helpers.rb +57 -0
  48. data/lib/snippet_cli/wizard_helpers/validation_loop.rb +33 -0
  49. data/lib/snippet_cli/wizard_helpers.rb +8 -0
  50. data/lib/snippet_cli/yaml_line_resolver.rb +46 -0
  51. data/lib/snippet_cli/yaml_loader.rb +19 -0
  52. data/lib/snippet_cli/yaml_param_renderer.rb +33 -0
  53. data/lib/snippet_cli/yaml_scalar.rb +48 -0
  54. data/lib/snippet_cli.rb +44 -1
  55. metadata +134 -101
  56. data/.gitignore +0 -11
  57. data/.rspec +0 -3
  58. data/.travis.yml +0 -9
  59. data/CODE_OF_CONDUCT.md +0 -74
  60. data/Gemfile +0 -17
  61. data/Rakefile +0 -10
  62. data/bin/console +0 -14
  63. data/bin/setup +0 -8
  64. data/lib/Setup.rb +0 -76
  65. data/lib/banner.rb +0 -16
  66. data/lib/snippet_cli/cli.rb +0 -62
  67. data/lib/snippet_cli/command.rb +0 -121
  68. data/lib/snippet_cli/commands/info.md +0 -20
  69. data/lib/snippet_cli/commands/info.rb +0 -36
  70. data/lib/snippet_cli/commands/setup.rb +0 -108
  71. data/lib/snippet_cli/templates/.gitkeep +0 -1
  72. data/lib/snippet_cli/templates/config/.gitkeep +0 -1
  73. data/lib/snippet_cli/templates/create/.gitkeep +0 -1
  74. data/lib/snippet_cli/templates/info/.gitkeep +0 -1
  75. data/lib/snippet_cli/templates/setup/.gitkeep +0 -1
  76. data/lib/snippet_generator.rb +0 -85
  77. data/snippet_cli-0.1.0.gem +0 -0
  78. data/snippet_cli-0.1.1.gem +0 -0
  79. data/snippet_cli-0.1.2.gem +0 -0
  80. data/snippet_cli-0.1.3.gem +0 -0
  81. data/snippet_cli-0.1.4.gem +0 -0
  82. data/snippet_cli-0.1.5.gem +0 -0
  83. data/snippet_cli-0.1.6.gem +0 -0
  84. data/snippet_cli-0.1.7.gem +0 -0
  85. data/snippet_cli-0.1.8.gem +0 -0
  86. data/snippet_cli-0.1.9.gem +0 -0
  87. data/snippet_cli-0.2.0.gem +0 -0
  88. data/snippet_cli-0.2.1.gem +0 -0
  89. data/snippet_cli-0.2.2.gem +0 -0
  90. data/snippet_cli-0.2.3.gem +0 -0
  91. data/snippet_cli-0.2.4.gem +0 -0
  92. data/snippet_cli-0.2.6.gem +0 -0
  93. data/snippet_cli-0.2.7.gem +0 -0
  94. data/snippet_cli-0.2.8.gem +0 -0
  95. data/snippet_cli.gemspec +0 -37
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module SnippetCli
6
- class Command
7
- extend Forwardable
8
-
9
- def_delegators :command, :run
10
-
11
- # Execute this command
12
- #
13
- # @api public
14
- def execute(*)
15
- raise(
16
- NotImplementedError,
17
- "#{self.class}##{__method__} must be implemented"
18
- )
19
- end
20
-
21
- # The external commands runner
22
- #
23
- # @see http://www.rubydoc.info/gems/tty-command
24
- #
25
- # @api public
26
- def command(**options)
27
- require 'tty-command'
28
- TTY::Command.new(options)
29
- end
30
-
31
- # The cursor movement
32
- #
33
- # @see http://www.rubydoc.info/gems/tty-cursor
34
- #
35
- # @api public
36
- def cursor
37
- require 'tty-cursor'
38
- TTY::Cursor
39
- end
40
-
41
- # Open a file or text in the user's preferred editor
42
- #
43
- # @see http://www.rubydoc.info/gems/tty-editor
44
- #
45
- # @api public
46
- def editor
47
- require 'tty-editor'
48
- TTY::Editor
49
- end
50
-
51
- # File manipulation utility methods
52
- #
53
- # @see http://www.rubydoc.info/gems/tty-file
54
- #
55
- # @api public
56
- def generator
57
- require 'tty-file'
58
- TTY::File
59
- end
60
-
61
- # Terminal output paging
62
- #
63
- # @see http://www.rubydoc.info/gems/tty-pager
64
- #
65
- # @api public
66
- def pager(**options)
67
- require 'tty-pager'
68
- TTY::Pager.new(options)
69
- end
70
-
71
- # Terminal platform and OS properties
72
- #
73
- # @see http://www.rubydoc.info/gems/tty-pager
74
- #
75
- # @api public
76
- def platform
77
- require 'tty-platform'
78
- TTY::Platform.new
79
- end
80
-
81
- # The interactive prompt
82
- #
83
- # @see http://www.rubydoc.info/gems/tty-prompt
84
- #
85
- # @api public
86
- def prompt(**options)
87
- require 'tty-prompt'
88
- TTY::Prompt.new(options)
89
- end
90
-
91
- # Get terminal screen properties
92
- #
93
- # @see http://www.rubydoc.info/gems/tty-screen
94
- #
95
- # @api public
96
- def screen
97
- require 'tty-screen'
98
- TTY::Screen
99
- end
100
-
101
- # The unix which utility
102
- #
103
- # @see http://www.rubydoc.info/gems/tty-which
104
- #
105
- # @api public
106
- def which(*args)
107
- require 'tty-which'
108
- TTY::Which.which(*args)
109
- end
110
-
111
- # Check if executable exists
112
- #
113
- # @see http://www.rubydoc.info/gems/tty-which
114
- #
115
- # @api public
116
- def exec_exist?(*args)
117
- require 'tty-which'
118
- TTY::Which.exist?(*args)
119
- end
120
- end
121
- end
@@ -1,20 +0,0 @@
1
- # Thanks for trying Snippet CLI!
2
-
3
- Hi! Have any feedback?
4
- We'd love to hear it.
5
- Click the link below to send an email to the developer.
6
-
7
- ## Links
8
-
9
- - [Install Espanso](https://espanso.org/)
10
- - [Snippet CLI Github](https://www.github.com/ajmarkow/snippet_cli)
11
- - [Snippet CLI Docs](https:/docs.snippetcli.com)
12
- - [Email Me Feedback](mailto:aj@ajm.codes)
13
-
14
- ## Commands
15
-
16
- | **Command** | **Purpose** |
17
- |----------|:------------------:|
18
- | setup | Sets up path to snippet file |
19
- | new | Opens dialog to add new snippet or form. |
20
- | info| Docs, Contact Info, and Resources |
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'bundler/setup'
3
- require_relative '../command'
4
- require 'tty-markdown'
5
- require 'tty-box'
6
-
7
- module SnippetCli
8
- module Commands
9
- class Info < SnippetCli::Command
10
- def initialize(docs, options)
11
- @docs = docs
12
- @options = options
13
- end
14
-
15
- def execute(input: $stdin, output: $stdout)
16
- def show_banner()
17
- box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
18
- "
19
- ##### # # ### ###### ###### ####### #######
20
- # # ## # # # # # # # #
21
- # # # # # # # # # # #
22
- ##### # # # # ###### ###### ##### #
23
- # # # # # # # # #
24
- # # # ## # # # # #
25
- ##### # # ### # # ####### # CLI
26
- "
27
- end
28
- puts box
29
- end
30
- puts show_banner()
31
- parsed_markdown=TTY::Markdown.parse_file('/snippet_cli/commands/info.md')
32
- output.puts parsed_markdown
33
- end
34
- end
35
- end
36
- end
@@ -1,108 +0,0 @@
1
- require_relative '../command'
2
- require 'bundler/setup'
3
- require 'tty-box'
4
- require 'tty-prompt'
5
- require 'tty-platform'
6
- # frozen_string_literal: true
7
-
8
-
9
- module SnippetCli
10
- module Commands
11
- class Setup < SnippetCli::Command
12
- platform= TTY::Platform.new
13
- @leading = " "
14
- attr_accessor :user_name,:config_path,:user_storage,:config_present,:os_choice
15
-
16
- def initialize()
17
- @user_name = user_name
18
- @config_path = config_path
19
- @user_storage = user_storage
20
- @os_choice = os_choice
21
- @config_present = config_present
22
- end
23
-
24
- def show_banner()
25
- box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
26
- "
27
- ##### # # ### ###### ###### ####### #######
28
- # # ## # # # # # # # #
29
- # # # # # # # # # # #
30
- ##### # # # # ###### ###### ##### #
31
- # # # # # # # # #
32
- # # # ## # # # # #
33
- ##### # # ### # # ####### # CLI
34
- "
35
- end
36
- puts box
37
- end
38
-
39
- def get_name()
40
- puts @leading
41
- prompt = TTY::Prompt.new
42
- name = prompt.ask("⟶ To begin setup, may I have your name?", default: ENV["USER"], active_color: :bright_blue) do |q|
43
- q.required true
44
- end
45
- puts @leading
46
- self.user_name = name
47
- end
48
-
49
- def get_os()
50
- puts @leading
51
- puts "Checking what os you're using..."
52
- os_choice = platform.os()
53
- if (platform.windows? == true)
54
- config_path = "#{ENV["HOMEPATH"]}\\AppData\\Roaming\\espanso\\default.yml"
55
- elsif (platform.mac? == true)
56
- config_path = "#{ENV["HOME"]}/Library/Preferences/espanso/default.yml"
57
- else (platform.linux? == true)
58
- config_path = "#{ENV["HOME"]}/.config/espanso/default.yml"
59
- end
60
- puts @leading
61
- self.config_path=config_path
62
- self.os_choice = os_choice
63
- puts "We'll set the config path to:"
64
- puts @leading
65
- prompt.ok("#{config_path}")
66
-
67
- end
68
-
69
- # REFACTOR TO PROVIDE PATH
70
- def get_storage()
71
- puts @leading
72
- prompt = TTY::Prompt.new
73
- return snippet_storage = prompt.select("Do your store your snippets in Dropbox or a different directory?", default: 1, active_color: :bright_blue) do |menu|
74
- menu.enum "."
75
-
76
- menu.choice "No I use the default folder.", 1
77
- menu.choice "I use Dropbox.", 2
78
- menu.choice "I use Google Drive", 3
79
- menu.choice "I use Another Directory.", 4
80
- end
81
- puts @leading
82
- self.user_storage = snippet_storage
83
- end
84
-
85
- def generate_config()
86
- if File.exist?("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt") && File.read("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt").include?("CONFIG_PRESENT = TRUE")
87
- else
88
- File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "NAME = #{self.user_name}\n"}
89
- File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "#{self.config_path}\n"}
90
- File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "CONFIG_PRESENT = TRUE\n"}
91
- end
92
- end
93
-
94
- def execute(input: $stdin, output: $stdout)
95
- show_banner()
96
- self.get_name()
97
- self.get_os()
98
- output.puts @leading
99
- output.puts "Thanks, that's all we need to know about your configuration."
100
- output.puts @leading
101
- output.puts @leading
102
- output.puts "You can now type snippet_cli new to get started."
103
- output.puts @leading
104
- self.generate_config()
105
- end
106
- end
107
- end
108
- end
@@ -1 +0,0 @@
1
- #
@@ -1 +0,0 @@
1
- #
@@ -1 +0,0 @@
1
- #
@@ -1 +0,0 @@
1
- #
@@ -1 +0,0 @@
1
- #
@@ -1,85 +0,0 @@
1
- # Some Definitions for the sake of readability.
2
- module SnippetGenerator
3
- NEW_LINE="\n"
4
- QUOTE = '"'
5
-
6
- #Just writes matches: at the beginning of file so espanso can read the mapping.
7
-
8
- def initialize_espanso_yml(file_to_write)
9
- File.open(file_to_write,"a") { |file| file.write('matches:'+NEW_LINE) }
10
- end
11
-
12
- #Writes a snippet to file when given trigger and replacement strings.
13
-
14
- def single_snippet_export(file_to_write,trigger,replacement)
15
- File.open(file_to_write,"a") { |file| file.write(NEW_LINE+' - trigger: '+'":'+trigger+QUOTE+NEW_LINE) }
16
- File.open(file_to_write,"a") { |file| file.write(' replace: |-'+NEW_LINE) }
17
- if (replacement.instance_of?(String)) then
18
- File.open(file_to_write,"a") { |file| file.write(' '+replacement) }
19
- else
20
- replacement.each do |item|
21
- File.open(file_to_write,"a") { |file| file.write(' '+item) }
22
- end
23
- end
24
- File.open(file_to_write,"a") { |file| file.write(NEW_LINE) }
25
- end
26
-
27
- # New a YAML Comment to separate sections of snippet file.
28
-
29
- def heading_snippet_export(file_to_write,heading)
30
- File.open(file_to_write,"a") { |file| file.write("# "+ heading+NEW_LINE) }
31
- end
32
-
33
- # Any input fields should be entered with double brackets around them when passed in as form_statement
34
- # For example "AJ likes coding in {{language}} and using {{editor}} to write code."
35
-
36
- def input_form_snippet_export(file_to_write, form_trigger,form_statement)
37
- File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) }
38
- File.open(file_to_write,"a") { |file| file.write(' form: |-'+NEW_LINE)}
39
- if (form_statement.instance_of?(String)) then
40
- File.open(file_to_write,"a") { |file| file.write(' '+form_statement)}
41
- else
42
- form_statement.each do |item|
43
- File.open(file_to_write,"a") { |file| file.write(' '+item) }
44
- end
45
- end
46
- File.open(file_to_write,"a") { |file| file.write(NEW_LINE) }
47
- end
48
- ## ! TO DO: REFACTOR FORM METHODS INTO ONE METHOD which accounts for all cases. Add comments clarifying
49
- ## ! DATA STRUCTURE NEEDED.
50
- #Takes a string for trigger. form_values should be an array.form_fields should also be of type array.
51
- #Parses statements and news picklists based on form fields and values for each field provided
52
-
53
- def picklist_snippet_export(form_trigger,statement,form_fields,formvalues,file_to_write)
54
- form_fields.each do |value|
55
- value+':'
56
- end
57
- form_type = 'choice'
58
- File.open(file_to_write,"a") { |file| file.write(' - trigger: '+'":'+form_trigger+QUOTE+NEW_LINE) }
59
- File.open(file_to_write,"a") { |file| file.write(' form: '+QUOTE+statement+QUOTE+NEW_LINE) }
60
- form_fields.each do |value|
61
- File.open(file_to_write,"a") { |file| file.write(' form_fields:'+NEW_LINE) }
62
- File.open(file_to_write,"a") { |file| file.write(' '+form_fields+NEW_LINE) }
63
- File.open(file_to_write,"a") { |file| file.write(' type: '+ form_type+NEW_LINE) }
64
- File.open(file_to_write,"a") { |file| file.write(' values:'+NEW_LINE) }
65
- formvalues.each do |value|
66
- File.open(file_to_write,"a") { |file| file.write(' - '+QUOTE+value+QUOTE+NEW_LINE) }
67
- end
68
- end
69
-
70
- end
71
-
72
- # News a snippet with large text box
73
-
74
- def textarea_snippet_export(file_to_write)
75
- File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) }
76
- File.open(file_to_write,"a") { |file| file.write(' form: |'+NEW_LINE)}
77
- File.open(file_to_write,"a") { |file| file.write(' '+form_statement+NEW_LINE)}
78
- File.open(file_to_write,"a") { |file| file.write(' '+field_names+NEW_LINE) }
79
- File.open(file_to_write,"a") { |file| file.write(' '+"multiline: true"+NEW_LINE) }
80
- end
81
-
82
- ## Form Generator Method. Will make form that has, .
83
- ## Takes a few arrays as arguments.
84
- ## Form Fields: Just string in array, but in form context represented as {{Form Field Name}}
85
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/snippet_cli.gemspec DELETED
@@ -1,37 +0,0 @@
1
- require_relative 'lib/snippet_cli/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "snippet_cli"
5
- spec.license = "MIT"
6
- spec.version = SnippetCli::VERSION
7
- spec.authors = ["AJ Markow"]
8
- spec.email = ["alexanderjmarkow@gmail.com"]
9
-
10
- spec.summary = "Allows you to add snippets to Espanso Config from CLI"
11
- spec.description = "You can write to your espanso config directly using this gem"
12
- spec.homepage = "https://github.com/ajmarkow/snippet_cli"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
- spec.add_runtime_dependency "tty-prompt"
15
- spec.add_runtime_dependency "tty-box"
16
- spec.add_runtime_dependency "tty-platform"
17
- spec.add_runtime_dependency "tty-markdown"
18
- spec.add_runtime_dependency "pastel"
19
- spec.add_runtime_dependency "bundler"
20
- spec.add_runtime_dependency "snippets_for_espanso"
21
- spec.add_runtime_dependency "httparty"
22
- spec.add_runtime_dependency "ascii"
23
-
24
-
25
- spec.metadata["homepage_uri"] = spec.homepage
26
- spec.metadata["source_code_uri"] = "https://github.com/ajmarkow/snippet_cli"
27
- spec.metadata["changelog_uri"] = "https://github.com/ajmarkow/snippet_cli"
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
- end
34
- spec.bindir = "exe"
35
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
- spec.require_paths = ["lib"]
37
- end