repofetch 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 82e31a1aff66491aa6ee4f0ce862ed960876a5762fe7b870536d2a4b6f3ab2a2
4
+ data.tar.gz: cdd76b64181cfa253e87be1633ab3f16b370462de69d47e4d1b4468eb6e5f0c2
5
+ SHA512:
6
+ metadata.gz: 798b248c171c24dc046904cbd76fd0b9a8d81a32d73244d657881e815f6801f464018a518990fb31e64429c756cf090c97a2d3ec77fe4200703d10c85e07ddfc
7
+ data.tar.gz: 170af910f544c77a35eb66a8f7155a0105e7a3493590b875ee38d3787a158f6fc6815b73ecdae5d53f474ab5906d51636813c70c0f5e3aa19f1be65549487ba1
data/CHANGELOG.md ADDED
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Other
6
+
7
+ - NetBSD installation option (@0323pin)
8
+
9
+ ## [0.3.3]
10
+
11
+ ### Fixed
12
+
13
+ - Crash caused by `-r`/`--repository` type mismatch (@orhun)
14
+ - GitHub repository names not being detected when they didn't have the optional
15
+ `.git` suffix
16
+
17
+ ## [0.3.2]
18
+
19
+ Internal changes only
20
+
21
+ ## [0.3.1]
22
+
23
+ ### Changed
24
+
25
+ - CLI help to be colored
26
+ - Order of CLI help
27
+
28
+ ## [0.3.0]
29
+
30
+ ### Added
31
+
32
+ - GitHub ASCII art
33
+ - Option to select local repository to detect remote owner and repository
34
+
35
+ ### Changed
36
+
37
+ - Date created and updated to be human-readable durations
38
+
39
+ ## [0.2.1]
40
+
41
+ ### Added
42
+
43
+ - config option for a personal access token
44
+
45
+ ## [0.2.0]
46
+
47
+ ### Added
48
+
49
+ - Issues counts
50
+ - Pull Requests counts
51
+ - Count of available issues with the `help wanted` label
52
+ - Count of available issues with the `good first issue` label
53
+ - Customizable behavior via `repofetch.yml` config file
54
+
55
+ ## 0.1.0
56
+ Initial version :tada:
57
+
58
+ [Unreleased]: https://github.com/spenserblack/repofetch/compare/v0.3.3...HEAD
59
+ [0.3.3]: https://github.com/spenserblack/repofetch/compare/v0.3.2...v0.3.3
60
+ [0.3.2]: https://github.com/spenserblack/repofetch/compare/v0.3.1...v0.3.2
61
+ [0.3.1]: https://github.com/spenserblack/repofetch/compare/v0.3.0...v0.3.1
62
+ [0.3.0]: https://github.com/spenserblack/repofetch/compare/v0.2.1...v0.3.0
63
+ [0.2.1]: https://github.com/spenserblack/repofetch/compare/v0.2.0...v0.2.1
64
+ [0.2.0]: https://github.com/spenserblack/repofetch/compare/v0.1.0...v0.2.0
data/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @spenserblack
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,123 @@
1
+ # Contributing
2
+
3
+ ## Contributing to repofetch
4
+
5
+ ### Initializing your repository
6
+
7
+ This will install dependencies and also set up git to run code quality checks
8
+ when you attempt to make a commit. If you are using a codespace, this should
9
+ run automatically.
10
+
11
+ ```bash
12
+ bundle install
13
+ bundle exec overcommit --install
14
+ ```
15
+
16
+ ## Writing a 3rd-party plugin
17
+
18
+ 3rd-party plugins are Ruby gems that users can install and activate in their
19
+ configuration files.
20
+
21
+ You can view an officially supported plugin, like `Repofetch::Github`, as an
22
+ example for writing a plugin.
23
+
24
+ The easiest way to set up a plugin is to inherit from `Repofetch::Plugin`, which
25
+ will provide several helper methods that repofetch relies on to construct the
26
+ output. A few methods need to be implemented to complete your plugin:
27
+
28
+ ### Required Plugin Class Methods
29
+
30
+ #### Detecting if repofetch should use a plugin
31
+
32
+ When a user does *not* explicitly choose their plugin from the command-line,
33
+ repofetch must select the plugin by matching it against a directory. `matches_repo?`
34
+ is a class method that takes a [`Git::Base`][git-base] instance and returns `true`
35
+ if repofetch should use the plugin for that repository, and `false` if repofetch should
36
+ not use the plugin (e.g. a GitHub plugin would return `false` for a GitLab repository).
37
+
38
+ #### Constructing the Plugin Instance
39
+
40
+ When repofetch selects a plugin using `matches_repo?`, it will then try to create an
41
+ instance of that plugin by calling `from_git`. From git will receive the
42
+ [`Git::Base`][git-base] instance, an array of CLI args that the plugin can use, and
43
+ an instance of `Repofetch::Config`.
44
+
45
+ If the user explicitly chooses the plugin to use via `repofetch --plugin <plugin>`, then
46
+ repofetch will pick that plugin and call its `from_args` class method. `from_args` takes
47
+ an array of CLI args and an instance of `Repofetch::Config`.
48
+
49
+ ### Required Plugin Instance Methods
50
+
51
+ The following requirements assume you are *not* manually implementing a plugin's
52
+ `to_s` method, and you are inheriting from `Repofetch::Plugin`.
53
+
54
+ - `ascii` should return a string for the ASCII art
55
+ - `header` should return the header text that will be above the `---` separator on the right side.
56
+ - `stats` should return an array of values that implement `to_s`. These will be
57
+ the stats displayed to the right of the ASCII art. You can use`Repofetch::Stat` and
58
+ `Repofetch::TimespanStat` to create a pretty stat.
59
+
60
+ The following are optional.
61
+
62
+ - `theme` can return an instance of `Repofetch::Theme` to use a different color scheme.
63
+
64
+ ### Authoring ASCII Art
65
+
66
+ The ASCII art should be no more than 40 characters wide or 20 characters tall.
67
+ It can receive ANSI escape sequences for styling by using `%{<style>}`. For example,
68
+ using the default theme, `%{red}foo%{reset}` would print `foo` with red text. See the
69
+ source code of `Repofetch::Theme` for all available default styles.
70
+
71
+ ### Registering a Plugin
72
+
73
+ A plugin must register itself so that repofetch can discover it. You can call either
74
+ the plugin class's `register` method, or `Repofetch.register_plugin`.
75
+
76
+ ### Example Plugin
77
+
78
+ This is a simple example of a plugin.
79
+
80
+ ```ruby
81
+ require 'repofetch'
82
+
83
+ class MyCoolPlugin < Repofetch::Plugin
84
+ def initialize(detected_from_git, arg_count)
85
+ @detected_from_git = detected_from_git
86
+ @arg_count = arg_count
87
+ end
88
+
89
+ def self.from_git(git, args, _config)
90
+ new(true, args.length)
91
+ end
92
+
93
+ def self.from_args(args, _config)
94
+ new(false, args.length)
95
+ end
96
+
97
+ def ascii
98
+ <<~ASCII
99
+ ####################
100
+ # %{bold}Hello, World%{reset} #
101
+ ####################
102
+ ASCII
103
+ end
104
+
105
+ def header
106
+ # NOTE: theme is provided by the base Plugin class
107
+ "stats from #{theme.format(:underline, 'my plugin')}"
108
+ end
109
+
110
+ def stats
111
+ # if theme is not passed, the stat will not be styled
112
+ [
113
+ Repofetch::Stat.new('git repo detected', @detected_from_git, emoji: '📂', theme: theme),
114
+ Repofetch::Stat.new('args passed', @arg_count, theme: theme)
115
+ ]
116
+ end
117
+ end
118
+
119
+ # When the user adds your plugin to their configuration file, this line will register the plugin
120
+ MyCoolPlugin.register
121
+ ```
122
+
123
+ [git-base]: https://www.rubydoc.info/github/ruby-git/ruby-git/Git/Base
data/CREDITS.md ADDED
@@ -0,0 +1,20 @@
1
+ # Credits
2
+
3
+ A special thanks to all listed below!
4
+
5
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
6
+ <!-- prettier-ignore-start -->
7
+ <!-- markdownlint-disable -->
8
+ <table>
9
+ <tbody>
10
+ <tr>
11
+ <td align="center"><a href="http://orhun.dev"><img src="https://avatars.githubusercontent.com/u/24392180?v=4?s=100" width="100px;" alt="Orhun Parmaksız"/><br /><sub><b>Orhun Parmaksız</b></sub></a><br /><a href="#bug-orhun" title="Bug reports">🐛</a> <a href="#code-orhun" title="Code">💻</a></td>
12
+ <td align="center"><a href="https://github.com/0323pin"><img src="https://avatars.githubusercontent.com/u/90570748?v=4?s=100" width="100px;" alt="pin"/><br /><sub><b>pin</b></sub></a><br /><a href="#platform-0323pin" title="Packaging/porting to new platform">📦</a></td>
13
+ </tr>
14
+ </tbody>
15
+ </table>
16
+
17
+ <!-- markdownlint-restore -->
18
+ <!-- prettier-ignore-end -->
19
+
20
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,147 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ repofetch (0.4.0)
5
+ actionview (~> 7.0, >= 7.0.4)
6
+ dotenv (~> 2.8)
7
+ faraday-retry (~> 2.0)
8
+ git (~> 1.12)
9
+ octokit (~> 6.0, >= 6.0.1)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionview (7.0.4)
15
+ activesupport (= 7.0.4)
16
+ builder (~> 3.1)
17
+ erubi (~> 1.4)
18
+ rails-dom-testing (~> 2.0)
19
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
20
+ activesupport (7.0.4)
21
+ concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ tzinfo (~> 2.0)
25
+ addressable (2.8.1)
26
+ public_suffix (>= 2.0.2, < 6.0)
27
+ ast (2.4.2)
28
+ awesome_print (1.9.2)
29
+ builder (3.2.4)
30
+ childprocess (4.1.0)
31
+ concurrent-ruby (1.1.10)
32
+ crass (1.0.6)
33
+ diff-lcs (1.5.0)
34
+ docile (1.4.0)
35
+ dotenv (2.8.1)
36
+ erubi (1.11.0)
37
+ faraday (2.7.1)
38
+ faraday-net_http (>= 2.0, < 3.1)
39
+ ruby2_keywords (>= 0.0.4)
40
+ faraday-net_http (3.0.2)
41
+ faraday-retry (2.0.0)
42
+ faraday (~> 2.0)
43
+ git (1.12.0)
44
+ addressable (~> 2.8)
45
+ rchardet (~> 1.8)
46
+ i18n (1.12.0)
47
+ concurrent-ruby (~> 1.0)
48
+ iniparse (1.5.0)
49
+ json (2.6.2)
50
+ loofah (2.19.0)
51
+ crass (~> 1.0.2)
52
+ nokogiri (>= 1.5.9)
53
+ mini_portile2 (2.8.0)
54
+ minitest (5.16.3)
55
+ nokogiri (1.13.9)
56
+ mini_portile2 (~> 2.8.0)
57
+ racc (~> 1.4)
58
+ octokit (6.0.1)
59
+ faraday (>= 1, < 3)
60
+ sawyer (~> 0.9)
61
+ overcommit (0.59.1)
62
+ childprocess (>= 0.6.3, < 5)
63
+ iniparse (~> 1.4)
64
+ rexml (~> 3.2)
65
+ parallel (1.22.1)
66
+ parser (3.1.3.0)
67
+ ast (~> 2.4.1)
68
+ public_suffix (5.0.0)
69
+ racc (1.6.0)
70
+ rails-dom-testing (2.0.3)
71
+ activesupport (>= 4.2.0)
72
+ nokogiri (>= 1.6)
73
+ rails-html-sanitizer (1.4.3)
74
+ loofah (~> 2.3)
75
+ rainbow (3.1.1)
76
+ rake (13.0.6)
77
+ rchardet (1.8.0)
78
+ regexp_parser (2.6.1)
79
+ rexml (3.2.5)
80
+ rspec (3.12.0)
81
+ rspec-core (~> 3.12.0)
82
+ rspec-expectations (~> 3.12.0)
83
+ rspec-mocks (~> 3.12.0)
84
+ rspec-core (3.12.0)
85
+ rspec-support (~> 3.12.0)
86
+ rspec-expectations (3.12.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.12.0)
89
+ rspec-mocks (3.12.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.12.0)
92
+ rspec-snapshot (2.0.1)
93
+ awesome_print (> 1.0.0)
94
+ rspec (> 3.0.0)
95
+ rspec-support (3.12.0)
96
+ rubocop (1.39.0)
97
+ json (~> 2.3)
98
+ parallel (~> 1.10)
99
+ parser (>= 3.1.2.1)
100
+ rainbow (>= 2.2.2, < 4.0)
101
+ regexp_parser (>= 1.8, < 3.0)
102
+ rexml (>= 3.2.5, < 4.0)
103
+ rubocop-ast (>= 1.23.0, < 2.0)
104
+ ruby-progressbar (~> 1.7)
105
+ unicode-display_width (>= 1.4.0, < 3.0)
106
+ rubocop-ast (1.24.0)
107
+ parser (>= 3.1.1.0)
108
+ rubocop-rake (0.6.0)
109
+ rubocop (~> 1.0)
110
+ rubocop-rspec (2.15.0)
111
+ rubocop (~> 1.33)
112
+ ruby-progressbar (1.11.0)
113
+ ruby2_keywords (0.0.5)
114
+ sawyer (0.9.2)
115
+ addressable (>= 2.3.5)
116
+ faraday (>= 0.17.3, < 3)
117
+ simplecov (0.21.2)
118
+ docile (~> 1.1)
119
+ simplecov-html (~> 0.11)
120
+ simplecov_json_formatter (~> 0.1)
121
+ simplecov-cobertura (2.1.0)
122
+ rexml
123
+ simplecov (~> 0.19)
124
+ simplecov-html (0.12.3)
125
+ simplecov_json_formatter (0.1.4)
126
+ tzinfo (2.0.5)
127
+ concurrent-ruby (~> 1.0)
128
+ unicode-display_width (2.3.0)
129
+
130
+ PLATFORMS
131
+ ruby
132
+
133
+ DEPENDENCIES
134
+ bundler (~> 2.0)
135
+ overcommit (~> 0.59)
136
+ rake (~> 13.0)
137
+ repofetch!
138
+ rspec (~> 3.11)
139
+ rspec-snapshot (~> 2.0)
140
+ rubocop (~> 1.36)
141
+ rubocop-rake (~> 0.6)
142
+ rubocop-rspec (~> 2.13)
143
+ simplecov (~> 0.21)
144
+ simplecov-cobertura (~> 2.1)
145
+
146
+ BUNDLED WITH
147
+ 2.1.2
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Spenser Black
4
+
5
+ Permission is hereby granted, free of charge, to any
6
+ person obtaining a copy of this software and associated
7
+ documentation files (the "Software"), to deal in the
8
+ Software without restriction, including without
9
+ limitation the rights to use, copy, modify, merge,
10
+ publish, distribute, sublicense, and/or sell copies of
11
+ the Software, and to permit persons to whom the Software
12
+ is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions
17
+ of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
20
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
23
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
26
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,7 @@
1
+ .PHONY: install
2
+
3
+ repofetch.gem: repofetch.gemspec lib/** exe/**
4
+ gem build -o repofetch.gem repofetch.gemspec
5
+
6
+ install: repofetch.gem
7
+ gem install repofetch.gem
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # `repofetch`
2
+
3
+ [![GitHub contributors (via allcontributors.org)](https://img.shields.io/github/all-contributors/spenserblack/repofetch)](./CREDITS.md)
4
+ ![CI](https://github.com/spenserblack/repofetch/workflows/CI/badge.svg)
5
+ [![CodeQL](https://github.com/spenserblack/repofetch/actions/workflows/codeql.yml/badge.svg)](https://github.com/spenserblack/repofetch/actions/workflows/codeql.yml)
6
+ [![codecov](https://codecov.io/gh/spenserblack/repofetch/branch/master/graph/badge.svg?token=3572AEWQAY)](https://codecov.io/gh/spenserblack/repofetch)
7
+
8
+ Fetch details about your remote repository.
9
+
10
+ ## Description
11
+
12
+ repofetch is a CLI tool to fetch stats (think [neofetch] or
13
+ [onefetch]) that uses plugins for its implementation. The original version was focused on
14
+ repository stats, and any official plugin will be for repositories, hence the "repo" in
15
+ repofetch. With 3rd-party plugins, however, it can support other types of outputs, too.
16
+
17
+ ## Installation
18
+
19
+ ### NetBSD (version <= 0.3.3)
20
+
21
+ Pre-compiled binaries are available from the [official repositories](https://pkgsrc.se/sysutils/repofetch)
22
+ To install this, simply run:
23
+
24
+ ```bash
25
+ pkgin install repofetch
26
+ ```
27
+
28
+ Or, if you prefer to build it from source:
29
+
30
+ ```
31
+ cd /usr/pkgsrc/sysutils/repofetch
32
+ make install
33
+ ```
34
+
35
+ You need to have `rust` and `libgit2` installed in order to build the package.
36
+
37
+ ## Configuration
38
+
39
+ A file called `.repofetch.yml` in your home directory will configure repofetch. The
40
+ first time you run `repofetch`, the default configuration will be written to this file.
41
+
42
+ Files called `.repofetch.env` and `repofetch.env` in your home directory will set
43
+ environment variables for repofetch, via the [dotenv gem][dotenv]. These environment
44
+ variables can be useful for plugins that require secrets. The purpose of these files
45
+ is to separate secrets from configuration, so that, for example, you could add
46
+ `.repofetch.yml` to a dotfiles repository without compromising an API token.
47
+
48
+ You can find the absolute paths to these files with the `--help` option.
49
+
50
+ ### Examples
51
+
52
+ ```yaml
53
+ # .repofetch.yml
54
+ plugins:
55
+ - 'repofetch/github'
56
+ ```
57
+
58
+ ```dotenv
59
+ # .repofetch.env
60
+ # Assuming you have gh (the GitHub CLI) installed
61
+ GITHUB_TOKEN=$(gh auth token)
62
+ ```
63
+
64
+ [dotenv]: https://github.com/bkeepers/dotenv
65
+ [neofetch]: https://github.com/dylanaraps/neofetch
66
+ [onefetch]: https://github.com/o2sh/onefetch
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'rake'
5
+
6
+ require 'rspec/core/rake_task'
7
+ require 'rubocop/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+ RuboCop::RakeTask.new(:format) do |t|
11
+ t.requires << 'rubocop-rspec'
12
+ end
13
+
14
+ desc 'Run tests'
15
+ task default: %i[format spec]
data/exe/repofetch ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'git'
5
+ require 'optparse'
6
+ require 'repofetch'
7
+ require 'repofetch/config'
8
+ require 'repofetch/env'
9
+
10
+ Repofetch::Env.load
11
+ config = Repofetch::Config.load!
12
+
13
+ config.plugins.each { |plugin| require plugin }
14
+
15
+ options = {
16
+ plugin: nil,
17
+ repository: '.'
18
+ }
19
+
20
+ available_plugins = Repofetch.plugins.to_h { |plugin| [plugin.name, plugin] }
21
+
22
+ command = OptionParser.new do |opts|
23
+ opts.banner = 'Usage: repofetch [options] -- [plugin arguments]'
24
+
25
+ opts.on('-r', '--repository PATH', 'Use the provided repository. Defaults to the current directory.') do |path|
26
+ options[:repository] = path
27
+ end
28
+
29
+ opts.on('-p', '--plugin PLUGIN', 'Use the specified plugin') do |plugin|
30
+ options[:plugin] = available_plugins[plugin]
31
+ end
32
+
33
+ Repofetch.plugins.each do |plugin|
34
+ opts.on("--#{plugin.name.sub(/::/, '-').downcase}", "Shortcut for --plugin #{plugin.name}") do
35
+ options[:plugin] = plugin
36
+ end
37
+ end
38
+
39
+ opts.separator ''
40
+ dotenv_paths = Repofetch::Env::DOTENV_PATHS.join(', ')
41
+ opts.separator "The following dotenv files can be used to set environment variables: #{dotenv_paths}"
42
+ opts.separator ''
43
+ opts.separator "You config file is at #{Repofetch::Config::PATH}"
44
+ opts.separator "Installed plugins: #{available_plugins.keys.join(', ')}"
45
+ end
46
+
47
+ command.parse!
48
+
49
+ git = Git.open(options[:repository])
50
+ plugin_class = options[:plugin]
51
+ # NOTE: If the user explicitly selected a plugin, then it is constructed from CLI args.
52
+ # Otherwise, we try to build it from the repository.
53
+ begin
54
+ plugin = plugin_class.nil? ? Repofetch.get_plugin(git, ARGV, config) : plugin_class.from_args(ARGV, config)
55
+ rescue ArgumentError => e
56
+ warn e
57
+ exit 1
58
+ end
59
+
60
+ puts plugin
@@ -0,0 +1,4 @@
1
+ ---
2
+ # vim: set ft=yaml:
3
+ plugins:
4
+ - 'repofetch/github'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ class Repofetch
6
+ # Utilities for managing config.
7
+ class Config
8
+ PATH = File.expand_path('.repofetch.yml', Dir.home)
9
+ DEFAULT_CONFIG = File.read(File.expand_path('DEFAULT_CONFIG', __dir__))
10
+
11
+ # Loads from config file.
12
+ def self.load
13
+ new(File.read(PATH))
14
+ end
15
+
16
+ # Loads from a config file if it exists. If it doesn't, it writes the config file,
17
+ # then creates a default.
18
+ def self.load!
19
+ if File.exist?(PATH)
20
+ self.load
21
+ else
22
+ File.write(PATH, DEFAULT_CONFIG)
23
+ new(DEFAULT_CONFIG)
24
+ end
25
+ end
26
+
27
+ # @param config_yaml [String] a YAML string
28
+ def initialize(config_yaml = DEFAULT_CONFIG)
29
+ @config = YAML.safe_load(config_yaml, symbolize_names: true)
30
+ end
31
+
32
+ def plugins
33
+ @config[:plugins] || []
34
+ end
35
+
36
+ def [](key)
37
+ @config[key]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv'
4
+
5
+ class Repofetch
6
+ # Environment variable manager. Basically a wrapper around dotenv.
7
+ class Env
8
+ DOTENV_NAMES = ['repofetch.env', '.repofetch.env'].freeze
9
+ DOTENV_PATHS = DOTENV_NAMES.map { |name| File.expand_path(name, Dir.home) }
10
+
11
+ def self.load
12
+ DOTENV_PATHS.each { |dotenv| Dotenv.load(dotenv) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Raised when there aren't any available plugins.
4
+ class Repofetch
5
+ class Error < RuntimeError
6
+ end
7
+
8
+ class NoPluginsError < Error
9
+ end
10
+
11
+ class TooManyPluginsError < Error
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ .ooOOOOOOOoo.
2
+ .oOOOOOOOOOOOOOOOOOo.
3
+ .oOOOOOOOOOOOOOOOOOOOOOOo.
4
+ .oOOOOOOOOOOOOOOOOOOOOOOOOOOOo
5
+ .OOOOO OO-------OO OOOOo
6
+ oOOOOOO OOOOOo
7
+ .OOOOOOO OOOOOOo
8
+ oOOOOOO OOOOOOo
9
+ OOOOOOo oOOOOOO
10
+ OOOOOO. .OOOOOO
11
+ OOOOOOO OOOOOOO
12
+ .OOOOOOo oOOOOOO.
13
+ OOOOOOOo. .OOOOOOO.
14
+ oOOO|\OOOoo./ \.ooOOOOOOOOo
15
+ .OOO \\OO/ \OOOOOOOOO.
16
+ OO. OOOOOOOOO
17
+ OOOOOOO OOOOOOO
18
+ OOO OOO
19
+
20
+