mozconfig 0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: deab982bf7a16337ecc968051e64f58060e57c87347fbc7ac7110a4e4dcbeaa3
4
+ data.tar.gz: 982729e6bca482b2731d7e6eb465d786855319639804d49b3ec89f1136cc2144
5
+ SHA512:
6
+ metadata.gz: 262fffdff7424b2d03d7f48d474c8a9cc2f2438e4bbd32705547a818eb31780872dd7b8db4a1fad0a68dc82c078218aa72b0ae63c24a0ce68b09f4ed577c8fb6
7
+ data.tar.gz: 757347cdfb31b1f6f923b8d20280134bdbff40465282e1dae17afbd5073abdac97900c4dc472659fa64d719f7ac956c364a9355ba5323cda37bfcb0d823664c8
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ # Don't push Gemfile.lock on a RubyGem
21
+ Gemfile.lock
22
+
23
+ # Might want one of these around for debugging purposes
24
+ /mozconfig
data/.rubocop.yml ADDED
@@ -0,0 +1,91 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.2
4
+
5
+ Gemspec/DevelopmentDependencies:
6
+ EnforcedStyle: gemspec
7
+
8
+ Gemspec/RequiredRubyVersion:
9
+ Enabled: false
10
+
11
+ Layout/ArgumentAlignment:
12
+ Enabled: false
13
+
14
+ Layout/EndAlignment:
15
+ EnforcedStyleAlignWith: variable
16
+
17
+ Layout/ExtraSpacing:
18
+ Enabled: false
19
+
20
+ Layout/FirstHashElementIndentation:
21
+ EnforcedStyle: consistent
22
+
23
+ Layout/MultilineMethodCallIndentation:
24
+ EnforcedStyle: indented
25
+
26
+ Layout/SpaceAroundEqualsInParameterDefault:
27
+ Enabled: false
28
+
29
+ Layout/TrailingWhitespace:
30
+ AllowInHeredoc: false
31
+
32
+ Lint/NonDeterministicRequireOrder:
33
+ Enabled: false
34
+
35
+ Metrics:
36
+ Enabled: false
37
+
38
+ Naming/HeredocDelimiterNaming:
39
+ Enabled: false
40
+
41
+ Naming/MethodParameterName:
42
+ Enabled: false
43
+
44
+ Naming/VariableNumber:
45
+ Enabled: false
46
+
47
+ Security/Eval:
48
+ Exclude:
49
+ - lib/cli.rb
50
+
51
+ Style/ClassAndModuleChildren:
52
+ Enabled: false
53
+
54
+ Style/Documentation:
55
+ Enabled: false
56
+
57
+ Style/FormatString:
58
+ Enabled: false
59
+
60
+ Style/GuardClause:
61
+ Enabled: false
62
+
63
+ Style/IfUnlessModifier:
64
+ Enabled: false
65
+
66
+ Style/MultilineTernaryOperator:
67
+ Enabled: false
68
+
69
+ Style/NestedParenthesizedCalls:
70
+ Enabled: false
71
+
72
+ Style/NestedTernaryOperator:
73
+ Enabled: false
74
+
75
+ Style/Next:
76
+ Enabled: false
77
+
78
+ Style/NumericPredicate:
79
+ Enabled: false
80
+
81
+ Style/ParallelAssignment:
82
+ Enabled: false
83
+
84
+ Style/RequireOrder:
85
+ Enabled: true
86
+
87
+ Style/StderrPuts:
88
+ Enabled: false
89
+
90
+ Style/StringLiterals:
91
+ EnforcedStyle: double_quotes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright © 2023 Vinny Diehl
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
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # `mozconfig` Switcher
2
+
3
+ A simple TUI utility to switch between different
4
+ [`mozconfig`](https://firefox-source-docs.mozilla.org/build/buildsystem/mozconfigs.html)s
5
+ in the Mozilla source code.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ gem install mozconfig
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Your `mozconfig` should be formatted like this, for example:
16
+
17
+ ```py
18
+ mk_add_options AUTOCLOBBER=1
19
+
20
+ # Firefox
21
+ ac_add_options --with-branding=browser/branding/nightly
22
+ ac_add_options --with-ccache=sccache
23
+
24
+ # Firefox (artifact build)
25
+ # ac_add_options --with-branding=browser/branding/nightly
26
+ # ac_add_options --enable-artifact-builds
27
+
28
+ # Thunderbird
29
+ # mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-mail-@CONFIG_GUESS@
30
+ # ac_add_options --enable-project=comm/mail
31
+ # ac_add_options --with-branding=comm/mail/branding/nightly
32
+ # ac_add_options --with-ccache=sccache
33
+
34
+ # Thunderbird (artifact build)
35
+ # mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-mail-@CONFIG_GUESS@
36
+ # ac_add_options --enable-project=comm/mail
37
+ # ac_add_options --with-branding=comm/mail/branding/nightly
38
+ # ac_add_options --enable-artifact-builds
39
+ ```
40
+
41
+ The options are separated into "paragraphs", each one a separate configuration.
42
+ This tool will comment out all of the inactive configurations. The comment
43
+ above each paragraph will be the name displayed in the TUI. Any paragraph
44
+ without a comment above it will remain active in all configurations.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task dist: :build
7
+ task default: :build
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1
data/bin/mozconfig ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "mozconfig"
5
+
6
+ MozConfig::TUI.new.run
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Checks if a line is commented out or not.
5
+ def commented?
6
+ start_with?("#")
7
+ end
8
+
9
+ # Comments a line if it is not already commented out.
10
+ def comment
11
+ commented? ? self : "# #{self}"
12
+ end
13
+
14
+ # Uncomments a line if it is commented out.
15
+ def uncomment
16
+ gsub(/^#\s*/, "")
17
+ end
18
+
19
+ # Removes whitespace from the beginning of the String.
20
+ def strip_beginning
21
+ gsub(/^\s*/, "")
22
+ end
23
+ end
data/lib/mozconfig.rb ADDED
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optimist"
4
+ require "tty-prompt"
5
+
6
+ require "core_ext/string"
7
+
8
+ VERSION = File.read(File.expand_path("../VERSION", __dir__)).strip.freeze
9
+
10
+ module MozConfig
11
+ class TUI
12
+ def initialize
13
+ check_options
14
+
15
+ unless File.exist?("mozconfig")
16
+ $stderr.puts "Error: mozconfig not found."
17
+ exit 1
18
+ end
19
+
20
+ # Fix whitespace-only lines and split by paragraph, then each paragraph
21
+ # into lines
22
+ @mozconfig = File.read("mozconfig")
23
+ .gsub(/^\s+$/, "")
24
+ .split(/\n{2,}/)
25
+ .map { |p| p.lines.map(&:strip_beginning) }
26
+
27
+ # Only paragraphs that begin with a comment are recognized as configs;
28
+ # anything else will remain active globally.
29
+ configs, @globals = @mozconfig.partition { |p| p.first.commented? }
30
+ # Form configs into a hash with the names as keys
31
+ @configs = configs.to_h { |cfg| [cfg.first.uncomment.strip, cfg[1..]] }
32
+ # Globals won't be manipulated further so we can rejoin them
33
+ @globals.map!(&:join)
34
+ end
35
+
36
+ def run
37
+ selection = TTY::Prompt.new.select("Pick a configuration", @configs)
38
+
39
+ output = "#{@globals.join("\n\n")}\n\n"
40
+
41
+ output << @configs.map do |name, options|
42
+ action = options == selection ? :uncomment : :comment
43
+ "#{name.comment}\n#{options.map(&action).join}"
44
+ end.join("\n\n")
45
+
46
+ File.write("mozconfig", output)
47
+ end
48
+
49
+ private
50
+
51
+ # Parses command-line options.
52
+ def check_options
53
+ @opts = Optimist.options do
54
+ version "mozconfig Picker #{VERSION}"
55
+ banner version
56
+ banner "https://github.com/vinnydiehl/mozconfig"
57
+ banner "\nOptions:"
58
+ opt :version, "display version number"
59
+ opt :help, "display this message"
60
+ educate_on_error
61
+ end
62
+ end
63
+ end
64
+ end
data/mozconfig.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "mozconfig"
5
+ gem.version = File.read(File.expand_path("VERSION", __dir__)).strip
6
+
7
+ gem.author = "Vinny Diehl"
8
+ gem.email = "vinny.diehl@gmail.com"
9
+ gem.homepage = "https://github.com/vinnydiehl/mozconfig"
10
+ gem.metadata["rubygems_mfa_required"] = "true"
11
+
12
+ gem.license = "MIT"
13
+
14
+ gem.summary = "TUI mozconfig switcher"
15
+ gem.description = "Switch between mozconfigs quickly and easily."
16
+
17
+ gem.bindir = "bin"
18
+ gem.executables = %w[mozconfig]
19
+ gem.files = `git ls-files -z`.split "\x0"
20
+
21
+ gem.add_dependency "optimist", "~> 3.1"
22
+ gem.add_dependency "tty-prompt", "~> 0.23"
23
+
24
+ gem.add_development_dependency "rubocop", "~> 1.54"
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mozconfig
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Vinny Diehl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: optimist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.23'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.23'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.54'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.54'
55
+ description: Switch between mozconfigs quickly and easily.
56
+ email: vinny.diehl@gmail.com
57
+ executables:
58
+ - mozconfig
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - Gemfile
65
+ - LICENSE.md
66
+ - README.md
67
+ - Rakefile
68
+ - VERSION
69
+ - bin/mozconfig
70
+ - lib/core_ext/string.rb
71
+ - lib/mozconfig.rb
72
+ - mozconfig.gemspec
73
+ homepage: https://github.com/vinnydiehl/mozconfig
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ rubygems_mfa_required: 'true'
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: TUI mozconfig switcher
97
+ test_files: []