bcli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +9 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +7 -0
  5. data/.standard.yml +3 -0
  6. data/CHANGELOG.md +5 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +120 -0
  10. data/LICENSE.txt +20 -0
  11. data/README.md +39 -0
  12. data/Rakefile +10 -0
  13. data/bcli.gemspec +116 -0
  14. data/exe/bcli +18 -0
  15. data/lib/bcli/cli.rb +54 -0
  16. data/lib/bcli/client.rb +42 -0
  17. data/lib/bcli/command.rb +101 -0
  18. data/lib/bcli/commands/.gitkeep +1 -0
  19. data/lib/bcli/commands/bookmarks/create.rb +52 -0
  20. data/lib/bcli/commands/bookmarks/search.rb +45 -0
  21. data/lib/bcli/commands/bookmarks.rb +35 -0
  22. data/lib/bcli/commands/drive/search.rb +61 -0
  23. data/lib/bcli/commands/drive/upload.rb +34 -0
  24. data/lib/bcli/commands/drive.rb +35 -0
  25. data/lib/bcli/commands/login.rb +62 -0
  26. data/lib/bcli/commands/news.rb +42 -0
  27. data/lib/bcli/commands/snippets/create.rb +47 -0
  28. data/lib/bcli/commands/snippets/search.rb +56 -0
  29. data/lib/bcli/commands/snippets.rb +35 -0
  30. data/lib/bcli/config.rb +24 -0
  31. data/lib/bcli/file_client.rb +32 -0
  32. data/lib/bcli/templates/.gitkeep +1 -0
  33. data/lib/bcli/templates/bookmarks/create/.gitkeep +0 -0
  34. data/lib/bcli/templates/bookmarks/search/.gitkeep +0 -0
  35. data/lib/bcli/templates/drive/search/.gitkeep +0 -0
  36. data/lib/bcli/templates/drive/upload/.gitkeep +0 -0
  37. data/lib/bcli/templates/login/.gitkeep +0 -0
  38. data/lib/bcli/templates/news/.gitkeep +0 -0
  39. data/lib/bcli/templates/snippets/create/.gitkeep +0 -0
  40. data/lib/bcli/templates/snippets/search/.gitkeep +0 -0
  41. data/lib/bcli/version.rb +5 -0
  42. data/lib/bcli.rb +17 -0
  43. data/sig/bcli.rbs +4 -0
  44. metadata +257 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c87bb7039bf0604524494d83b9cdd23c00c9035bf6c03ce293d62e0f64ef8f6
4
+ data.tar.gz: 4ac6ce809923f5cedafc143baec92209d9681bf02026b97e19a1f11a1a3d3d87
5
+ SHA512:
6
+ metadata.gz: 07fc2331e6418ce15120290902929df8b589b45f9ac196b52c49e0b5ba94bd178610471b01d78965da7c3c25ce0d2aa3e0444c089f8e4c57c494ec5e029d58a1
7
+ data.tar.gz: 638d3bf778ae6c72716eeb9e1b93ad8af6ff96e636a72e7d0acb837777bf62b68b080ed38c550c989964c1187c2eaf38c59a50d15a89775c90db8ee221123468
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*.rb]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 2
9
+ trim_trailing_whitespace = true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2.1
3
+
4
+ require: standard
5
+
6
+ inherit_gem:
7
+ standard: config/base.yml
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.2.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-04-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 43428385+leopolicastro@users.noreply.github.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in bcli.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bcli (0.1.0)
5
+ clipboard
6
+ httparty
7
+ pastel
8
+ thor
9
+ tty-link
10
+ tty-logger
11
+ tty-prompt
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ addressable (2.8.3)
17
+ public_suffix (>= 2.0.2, < 6.0)
18
+ ast (2.4.2)
19
+ byebug (11.1.3)
20
+ clipboard (1.3.6)
21
+ crack (0.4.5)
22
+ rexml
23
+ diff-lcs (1.5.0)
24
+ docile (1.4.0)
25
+ hashdiff (1.0.1)
26
+ httparty (0.21.0)
27
+ mini_mime (>= 1.0.0)
28
+ multi_xml (>= 0.5.2)
29
+ json (2.6.3)
30
+ language_server-protocol (3.17.0.3)
31
+ mini_mime (1.1.2)
32
+ multi_xml (0.6.0)
33
+ parallel (1.22.1)
34
+ parser (3.2.2.0)
35
+ ast (~> 2.4.1)
36
+ pastel (0.8.0)
37
+ tty-color (~> 0.5)
38
+ public_suffix (5.0.1)
39
+ rainbow (3.1.1)
40
+ rake (13.0.6)
41
+ regexp_parser (2.7.0)
42
+ rexml (3.2.5)
43
+ rspec (3.12.0)
44
+ rspec-core (~> 3.12.0)
45
+ rspec-expectations (~> 3.12.0)
46
+ rspec-mocks (~> 3.12.0)
47
+ rspec-core (3.12.1)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-expectations (3.12.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-mocks (3.12.5)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.12.0)
55
+ rspec-support (3.12.0)
56
+ rubocop (1.48.1)
57
+ json (~> 2.3)
58
+ parallel (~> 1.10)
59
+ parser (>= 3.2.0.0)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ regexp_parser (>= 1.8, < 3.0)
62
+ rexml (>= 3.2.5, < 4.0)
63
+ rubocop-ast (>= 1.26.0, < 2.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (>= 2.4.0, < 3.0)
66
+ rubocop-ast (1.28.0)
67
+ parser (>= 3.2.1.0)
68
+ rubocop-performance (1.16.0)
69
+ rubocop (>= 1.7.0, < 2.0)
70
+ rubocop-ast (>= 0.4.0)
71
+ ruby-progressbar (1.13.0)
72
+ simplecov (0.22.0)
73
+ docile (~> 1.1)
74
+ simplecov-html (~> 0.11)
75
+ simplecov_json_formatter (~> 0.1)
76
+ simplecov-html (0.12.3)
77
+ simplecov_json_formatter (0.1.4)
78
+ standard (1.26.0)
79
+ language_server-protocol (~> 3.17.0.2)
80
+ rubocop (~> 1.48.1)
81
+ rubocop-performance (~> 1.16.0)
82
+ thor (1.2.1)
83
+ tty-color (0.6.0)
84
+ tty-cursor (0.7.1)
85
+ tty-link (0.1.1)
86
+ tty-logger (0.6.0)
87
+ pastel (~> 0.8)
88
+ tty-prompt (0.23.1)
89
+ pastel (~> 0.8)
90
+ tty-reader (~> 0.8)
91
+ tty-reader (0.9.0)
92
+ tty-cursor (~> 0.7)
93
+ tty-screen (~> 0.8)
94
+ wisper (~> 2.0)
95
+ tty-screen (0.8.1)
96
+ unicode-display_width (2.4.2)
97
+ vcr (6.1.0)
98
+ webmock (3.18.1)
99
+ addressable (>= 2.8.0)
100
+ crack (>= 0.3.2)
101
+ hashdiff (>= 0.4.0, < 2.0.0)
102
+ wisper (2.0.1)
103
+
104
+ PLATFORMS
105
+ arm64-darwin-21
106
+ arm64-darwin-22
107
+ x86_64-linux
108
+
109
+ DEPENDENCIES
110
+ bcli!
111
+ byebug
112
+ rake (~> 13.0)
113
+ rspec (~> 3.0)
114
+ simplecov
115
+ standard (~> 1.3)
116
+ vcr
117
+ webmock
118
+
119
+ BUNDLED WITH
120
+ 2.4.9
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Leo Policastro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Bcli
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bcli`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bcli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/bcli/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the Bcli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bcli/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## Copyright
38
+
39
+ Copyright (c) 2023 Leo Policastro. See [MIT License](LICENSE.txt) for further details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
data/bcli.gemspec ADDED
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bcli/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bcli"
7
+ spec.license = "MIT"
8
+ spec.version = Bcli::VERSION
9
+ spec.authors = ["Leo Policastro"]
10
+ spec.email = ["43428385+leopolicastro@users.noreply.github.com"]
11
+
12
+ spec.summary = "BoilerCode CLI"
13
+ spec.description = "BoilerCode CLI"
14
+ spec.homepage = "https://github.com/leopolicastro/bcli"
15
+ spec.required_ruby_version = ">= 2.7.2"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+
38
+ # Draw various frames and boxes in terminal window.
39
+ # spec.add_dependency "tty-box", "~> 0.7"
40
+
41
+ # Terminal color capabilities detection.
42
+ # spec.add_dependency "tty-color", "~> 0.6"
43
+
44
+ # Execute shell commands with pretty logging.
45
+ # spec.add_dependency "tty-command", "~> 0.10"
46
+
47
+ # Define, read and write app configurations.
48
+ # spec.add_dependency "tty-config"
49
+
50
+ # Terminal cursor positioning, visibility and text manipulation.
51
+ # spec.add_dependency "tty-cursor", "~> 0.7"
52
+
53
+ # Open a file or text in a terminal text editor.
54
+ # spec.add_dependency "tty-editor", "~> 0.6"
55
+
56
+ # Terminal exit codes for humans and machines.
57
+ # spec.add_dependency "tty-exit", "~> 0.1"
58
+
59
+ # File and directory manipulation utility methods.
60
+ # spec.add_dependency "tty-file", "~> 0.10"
61
+
62
+ # Write text out to terminal in large stylized characters.
63
+ # spec.add_dependency "tty-font", "~> 0.5"
64
+
65
+ # Hyperlinks in terminal.
66
+ spec.add_dependency "tty-link"
67
+
68
+ # A readable, structured and beautiful logging for the terminal.
69
+ spec.add_dependency "tty-logger"
70
+
71
+ # Convert a markdown document or text into a terminal friendly output.
72
+ # spec.add_dependency "tty-markdown"
73
+
74
+ # Parser for command line arguments, keywords and options.
75
+ # spec.add_dependency "tty-option", "~> 0.1"
76
+
77
+ # A cross-platform terminal pager.
78
+ # spec.add_dependency "tty-pager", "~> 0.14"
79
+
80
+ # Draw pie charts in your terminal window.
81
+ # spec.add_dependency "tty-pie"
82
+
83
+ # Detect different operating systems.
84
+ # spec.add_dependency "tty-platform"
85
+
86
+ # A flexible and extensible progress bar for terminal applications.
87
+ # spec.add_dependency "tty-progressbar"
88
+
89
+ # A beautiful and powerful interactive command line prompt.
90
+ spec.add_dependency "tty-prompt"
91
+
92
+ # Terminal screen properties detection.
93
+ # spec.add_dependency "tty-screen"
94
+
95
+ # A terminal spinner for tasks with non-deterministic time.
96
+ # spec.add_dependency "tty-spinner"
97
+
98
+ # A flexible and intuitive table output generator.
99
+ # spec.add_dependency "tty-table", "~> 0.12"
100
+
101
+ # Print directory or structured data in a tree like format.
102
+ # spec.add_dependency "tty-tree", "~> 0.4"
103
+
104
+ # Platform independent implementation of Unix which command.
105
+ # spec.add_dependency "tty-which", "~> 0.4"
106
+
107
+ spec.add_dependency "clipboard"
108
+ spec.add_dependency "httparty"
109
+ spec.add_dependency "pastel"
110
+ spec.add_dependency "thor"
111
+ spec.add_development_dependency "byebug"
112
+ spec.add_development_dependency "simplecov"
113
+ spec.add_development_dependency "vcr"
114
+ spec.add_development_dependency "webmock"
115
+ spec.add_development_dependency "standard"
116
+ end
data/exe/bcli ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path("../lib", __dir__)
5
+ $:.unshift(lib_path) if !$:.include?(lib_path)
6
+ require "bcli/cli"
7
+
8
+ Signal.trap("INT") do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ Bcli::CLI.start
15
+ rescue Bcli::CLI::Error => err
16
+ puts "ERROR: #{err.message}"
17
+ exit 1
18
+ end
data/lib/bcli/cli.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module Bcli
6
+ # Handle the application command line parsing
7
+ # and the dispatch to various command objects
8
+ #
9
+ # @api public
10
+ class CLI < Thor
11
+ # Error raised by this runner
12
+ Error = Class.new(StandardError)
13
+
14
+ desc "version", "bcli version"
15
+ def version
16
+ require_relative "version"
17
+ puts "v#{Bcli::VERSION}"
18
+ end
19
+ map %w[--version -v] => :version
20
+
21
+ require_relative "commands/drive"
22
+ register Bcli::Commands::Drive, "drive", "drive [SUBCOMMAND]", "Manage your file uploads"
23
+
24
+ require_relative "commands/bookmarks"
25
+ register Bcli::Commands::Bookmarks, "bookmarks", "bookmarks [SUBCOMMAND]", "Manage your bookmarks"
26
+
27
+ require_relative "commands/snippets"
28
+ register Bcli::Commands::Snippets, "snippets", "snippets [SUBCOMMAND]", "Manage your snippets"
29
+
30
+ desc "news", "Command description..."
31
+ method_option :help, aliases: "-h", type: :boolean,
32
+ desc: "Display usage information"
33
+ def news(*)
34
+ if options[:help]
35
+ invoke :help, ["news"]
36
+ else
37
+ require_relative "commands/news"
38
+ Bcli::Commands::News.new(options).execute
39
+ end
40
+ end
41
+
42
+ desc "login", "Authenticate with Boilercode.io"
43
+ method_option :help, aliases: "-h", type: :boolean,
44
+ desc: "Display usage information"
45
+ def login(*)
46
+ if options[:help]
47
+ invoke :help, ["login"]
48
+ else
49
+ require_relative "commands/login"
50
+ Bcli::Commands::Login.new.execute
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,42 @@
1
+ module Bcli
2
+ class Client
3
+ include HTTParty
4
+ # base_uri "http://localhost:3000/api/v1"
5
+ base_uri "https://boilercode.io/api/v1"
6
+
7
+ attr_reader :config
8
+
9
+ def initialize
10
+ @config = Bcli::Config.new
11
+ end
12
+
13
+ def get(endpoint)
14
+ self.class.get(endpoint, headers: headers)
15
+ end
16
+
17
+ def post(endpoint, body)
18
+ self.class.post(endpoint, headers: headers, body: body.to_json)
19
+ end
20
+
21
+ def patch(endpoint, body)
22
+ self.class.patch(endpoint, headers: headers, body: body.to_json)
23
+ end
24
+
25
+ def put(endpoint, body)
26
+ self.class.put(endpoint, headers: headers, body: body.to_json)
27
+ end
28
+
29
+ def delete(endpoint)
30
+ self.class.delete(endpoint, headers: headers)
31
+ end
32
+
33
+ protected
34
+
35
+ def headers
36
+ {
37
+ "Content-Type": "application/json",
38
+ Authorization: "Bearer #{config.creds[:token]}"
39
+ }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bcli
4
+ class Command
5
+ # Execute this command
6
+ #
7
+ # @api public
8
+ def execute(*)
9
+ raise(
10
+ NotImplementedError,
11
+ "#{self.class}##{__method__} must be implemented"
12
+ )
13
+ end
14
+
15
+ # Below are examples of how to integrate TTY components
16
+
17
+ # The external commands runner
18
+ #
19
+ # @see http://www.rubydoc.info/gems/tty-command
20
+ #
21
+ # @api public
22
+ # def command(**options)
23
+ # require "tty-command"
24
+ # TTY::Command.new(options)
25
+ # end
26
+
27
+ # The interactive prompt
28
+ #
29
+ # @see http://www.rubydoc.info/gems/tty-prompt
30
+ #
31
+ # @api public
32
+ def prompt
33
+ require "tty-prompt"
34
+ TTY::Prompt.new
35
+ end
36
+
37
+ # @api public
38
+ def link_to(url, title = nil)
39
+ require "tty-link"
40
+
41
+ TTY::Link.link_to(url, title)
42
+ end
43
+
44
+ def logger
45
+ require "tty-logger"
46
+ TTY::Logger.new
47
+ end
48
+
49
+ # @api public
50
+ def download(url)
51
+ require "open-uri"
52
+ filename = File.basename(url)
53
+ # rubocop:disable Security/Open
54
+ remote_file = URI.open(url)
55
+ # rubocop:enable Security/Open
56
+ File.write(filename, remote_file.read)
57
+ remote_file.close
58
+ file_path = File.expand_path(filename)
59
+ puts pastel.green "Downloaded #{filename} to #{file_path}"
60
+ end
61
+
62
+ # @api public
63
+ def pastel
64
+ require "pastel"
65
+ @pastel ||= Pastel.new
66
+ end
67
+
68
+ # @api public
69
+ def config
70
+ # require "tty-config"
71
+ @config ||= Bcli::Config.new
72
+ end
73
+
74
+ # @api public
75
+ def credentials
76
+ config.creds
77
+ end
78
+
79
+ # @api public
80
+ def client
81
+ @client ||= Bcli::Client.new
82
+ end
83
+
84
+ # @api public
85
+ def open_in_browser(url)
86
+ system("open", url)
87
+ end
88
+
89
+ # @api public
90
+ def parse_json(response)
91
+ JSON.parse(response.body, object_class: OpenStruct)
92
+ end
93
+
94
+ # @api public
95
+ def ask(question)
96
+ prompt.ask(question) do |q|
97
+ q.required true
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1 @@
1
+ #