apender 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66fb5c0b4aedbedb0583f4881782380314309c7bb4942d53aead05ff0daa5eb6
4
- data.tar.gz: ff1ff8c3918edec89cbfdf79a9ce40222268d26d3f7882682d10632f017cdc29
3
+ metadata.gz: 7c15c0bef36e8548a32a35a52f827c3e25fb948a7ce6bd8f4baec87834c481fa
4
+ data.tar.gz: 053a45680b3b6c711e898bc9ad5f369efa70664f2b4f8af2291e344424a04f29
5
5
  SHA512:
6
- metadata.gz: fb3743f39a42d79e6db87b16da9b73558ca705a74815037bbefa89de6564046e2a6fb4aadbac98d504d6c93f8b620d7e481c356669c49fff78c15af895e5bf1b
7
- data.tar.gz: 67c4baff60dfb0a5693183a145173dfacf4f0aeb0e9221f8fee333d075211358b3a7856f5051ff6d9bf808adadaf7d190c3544e4c2a6d1697731b05f3b7aeada
6
+ metadata.gz: 8058260e2c20bb766deba3a88c3c49389f36ff3b2e3f4d3f8398ada32a666cd275bb4b6c03f8790ffd60017aab6cab9b79c26cf2ddd177442f4be3687087afc8
7
+ data.tar.gz: c0c8d276cc408a5c718036cdd1b0fb1e617da1d9cef8baebf191a3b3cb9cc1f29039295aeeb5f776dd611c3340e1f94b45a1de3615f6fa28dd11e22e4851b2a7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
- ## [Unreleased]
1
+ # Changelog
2
+
3
+ All notable changes to Apender are documented in this file.
4
+
5
+ This project follows a simple versioning format based on [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.2.0] - 2026-11-01
8
+
9
+ ### Added
10
+ - Replace specific lines using `-l` or `--line`.
11
+ - Add content to existing lines using `-a` or `--add`.
12
+ - Automatically create missing lines when targeting a line beyond the end of a file.
13
+ - Add automated tests for the main functionality.
14
+
15
+ ### Changed
16
+ - Expand command-line help with the new options.
17
+ - Improve project metadata and documentation.
18
+
19
+ ### Notes
20
+ - Line numbers start at 1.
21
+ - `-a` requires `-l`.
22
+ - `-n` cannot be combined with `-l`.
23
+ - Content written to a specific line must be a single line.
2
24
 
3
25
  ## [0.1.0] - 2026-11-01
4
26
 
5
- - Initial release
27
+ ### Added
28
+ - Initial release of Apender.
29
+ - Append text to existing files using `-c` or `--content`.
30
+ - Append empty lines using `-n` or `--null`.
31
+ - Specify target files using `-p` or `--path`.
32
+ - Automatically insert a newline when the file does not end with one.
33
+ - Preserve existing file contents.
34
+ - Display command-line help with `--help`.
35
+ - Error handling for missing files and invalid arguments.
36
+
37
+ ### Notes
38
+ - Files are not created automatically.
39
+ - `-c` and `-n` cannot be used together.
40
+ - Initial release published on RubyGems.
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,10 +1,63 @@
1
1
  # Code of Conduct
2
2
 
3
- "apender" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
3
+ ## Our Pledge
4
4
 
5
- * Participants will be tolerant of opposing views.
6
- * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
- * When interpreting the words and actions of others, participants should always assume good intentions.
8
- * Behaviour which can be reasonably considered harassment will not be tolerated.
5
+ We are committed to making participation in the Apender project a welcoming, respectful, and harassment-free experience for everyone.
9
6
 
10
- If you have any concerns about behaviour within this project, please contact us at ["TODO: Write your email address"](mailto:"TODO: Write your email address").
7
+ We welcome contributions from people of all backgrounds and experience levels.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment:
12
+
13
+ - Being respectful and considerate.
14
+ - Welcoming different opinions and perspectives.
15
+ - Giving and accepting constructive feedback.
16
+ - Helping newcomers feel welcome.
17
+ - Taking responsibility for mistakes and learning from them.
18
+ - Focusing on what is best for the project and its community.
19
+
20
+ Examples of unacceptable behavior:
21
+
22
+ - Harassment, discrimination, or personal attacks.
23
+ - Insulting or threatening other contributors.
24
+ - Publishing private information without permission.
25
+ - Trolling, deliberate intimidation, or disruptive behavior.
26
+ - Any other conduct that would be inappropriate in a professional community.
27
+
28
+ ## Our Responsibilities
29
+
30
+ Project maintainers are responsible for clarifying and enforcing our standards of acceptable behavior.
31
+
32
+ They may remove, edit, or reject contributions that violate this Code of Conduct.
33
+
34
+ ## Scope
35
+
36
+ This Code of Conduct applies to all project spaces, including:
37
+
38
+ - GitHub issues and pull requests.
39
+ - Discussions and comments.
40
+ - Project-related communication channels.
41
+ - Any other space where someone represents the Apender project.
42
+
43
+ ## Reporting
44
+
45
+ If you experience or witness unacceptable behavior, please report it through the GitHub repository:
46
+
47
+ https://github.com/Nic24nix/apender/issues
48
+
49
+ Please include as much relevant information as possible.
50
+
51
+ ## Enforcement
52
+
53
+ Project maintainers will review reports and take appropriate action.
54
+
55
+ They may remove inappropriate content, reject contributions, or restrict participation in the project when necessary.
56
+
57
+ ## Attribution
58
+
59
+ This Code of Conduct is inspired by the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
60
+
61
+ For more information, visit:
62
+
63
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2026 TODO: Write your name
3
+ Copyright (c) 2026 Nic24nix
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,9 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
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
21
- THE SOFTWARE.
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
data/README.md CHANGED
@@ -1,43 +1,140 @@
1
1
  # Apender
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ **A simple Ruby CLI tool to append content to existing files and edit specific lines.**
4
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/apender`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Apender is a lightweight command-line utility written in Ruby. It allows you to append text or empty lines to files, replace specific lines, and add content to existing lines without overwriting the rest of the file.
6
+
7
+ ## Features
8
+
9
+ - Append text to existing files.
10
+ - Append empty lines.
11
+ - Replace content on specific lines.
12
+ - Add content to existing lines without replacing their contents.
13
+ - Automatically create missing lines when targeting a line beyond the end of a file.
14
+ - Preserve all existing file contents.
15
+ - Automatically insert a newline when the file doesn't end with one.
16
+ - Simple command-line interface.
17
+ - Does not create files that don't exist.
6
18
 
7
19
  ## Installation
8
20
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_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.
21
+ ### RubyGems
22
+
23
+ ```bash
24
+ gem install apender
25
+ ```
26
+
27
+ ### Arch Linux / CachyOS
10
28
 
11
- Install the gem and add to the application's Gemfile by executing:
29
+ Once available in the AUR:
12
30
 
13
31
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
32
+ paru -S apender
15
33
  ```
16
34
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
35
+ ### From source
18
36
 
19
37
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
38
+ git clone https://github.com/Nic24nix/apender.git
39
+ cd apender
40
+ gem build apender.gemspec
41
+ gem install --user-install ./apender-0.2.0.gem
21
42
  ```
22
43
 
23
44
  ## Usage
24
45
 
25
- TODO: Write usage instructions here
46
+ ### Append text
47
+
48
+ ```bash
49
+ append -p ~/notes.txt -c "Hello, world!"
50
+ ```
51
+
52
+ This appends `Hello, world!` to the end of `notes.txt`.
53
+
54
+ ### Append an empty line
26
55
 
27
- ## Development
56
+ ```bash
57
+ append -p ~/notes.txt -n
58
+ ```
59
+
60
+ This appends an empty line to the file.
28
61
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+ ### Replace a specific line
30
63
 
31
- 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).
64
+ ```bash
65
+ append -p ~/notes.txt -c "New content" -l 3
66
+ ```
32
67
 
33
- ## Contributing
68
+ This replaces the content of line 3.
34
69
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apender. 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]/apender/blob/master/CODE_OF_CONDUCT.md).
70
+ ### Add content to an existing line
71
+
72
+ ```bash
73
+ append -p ~/notes.txt -c " More text" -l 1 -a
74
+ ```
75
+
76
+ This adds content to the end of line 1 without replacing its existing content.
77
+
78
+ ### Display help
79
+
80
+ ```bash
81
+ append --help
82
+ ```
83
+
84
+ ## Options
85
+
86
+ | Option | Description |
87
+ |---|---|
88
+ | `-p PATH`, `--path PATH` | Path to the existing file |
89
+ | `-c CONTENT`, `--content CONTENT` | Text to write |
90
+ | `-n`, `--null` | Append an empty line |
91
+ | `-l LINE`, `--line LINE` | Select a specific line |
92
+ | `-a`, `--add` | Add content to an existing line |
93
+ | `-h`, `--help` | Display help |
94
+
95
+ **Note:** You must use either `-c` or `-n`, not both. `-a` requires `-l`, and `-n` cannot be combined with `-l`.
96
+
97
+ ## Examples
98
+
99
+ Starting with a file containing:
100
+
101
+ ```text
102
+ Shopping list
103
+ Milk
104
+ Bread
105
+ ```
106
+
107
+ Run:
108
+
109
+ ```bash
110
+ append -p shopping.txt -c "Eggs"
111
+ append -p shopping.txt -n
112
+ append -p shopping.txt -c "Butter" -l 3
113
+ append -p shopping.txt -c " Shopping" -l 1 -a
114
+ ```
115
+
116
+ The resulting file:
117
+
118
+ ```text
119
+ Shopping list Shopping
120
+ Milk
121
+ Butter
122
+ Eggs
123
+
124
+ ```
125
+
126
+ ## Requirements
127
+
128
+ - Ruby 3.2 or newer
36
129
 
37
130
  ## License
38
131
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
132
+ Apender is released under the MIT License. See [LICENSE.txt](LICENSE.txt).
133
+
134
+ ## Repository
135
+
136
+ [github.com/Nic24nix/apender](https://github.com/Nic24nix/apender)
40
137
 
41
- ## Code of Conduct
138
+ ---
42
139
 
43
- Everyone interacting in the Apender project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/apender/blob/master/CODE_OF_CONDUCT.md).
140
+ Made with Ruby 🩷
data/exe/append CHANGED
@@ -7,7 +7,7 @@ require "optparse"
7
7
  options = {}
8
8
 
9
9
  parser = OptionParser.new do |opts|
10
- opts.banner = "Usage: append -p PATH (-c CONTENT | -n)"
10
+ opts.banner = "Usage: append -p PATH (-c CONTENT | -n) [-l LINE] [-a]"
11
11
 
12
12
  opts.on("-p PATH", "--path PATH", "File path") do |path|
13
13
  options[:path] = path
@@ -20,6 +20,14 @@ parser = OptionParser.new do |opts|
20
20
  opts.on("-n", "--null", "Append an empty line") do
21
21
  options[:null] = true
22
22
  end
23
+
24
+ opts.on("-l LINE", "--line LINE", Integer, "Target line number") do |line|
25
+ options[:line] = line
26
+ end
27
+
28
+ opts.on("-a", "--add", "Add content to the existing line") do
29
+ options[:add] = true
30
+ end
23
31
  end
24
32
 
25
33
  begin
@@ -32,10 +40,23 @@ begin
32
40
  "Use either -c CONTENT or -n, not both"
33
41
  end
34
42
 
43
+ if options[:add] && !options[:line]
44
+ raise OptionParser::InvalidArgument, "-a requires -l LINE"
45
+ end
46
+
47
+ if options[:line] && options[:null]
48
+ raise OptionParser::InvalidArgument, "-l cannot be used with -n"
49
+ end
50
+
35
51
  if options[:null]
36
52
  Apender.newline(options[:path])
37
53
  else
38
- Apender.append(options[:path], options[:content])
54
+ Apender.append(
55
+ options[:path],
56
+ options[:content],
57
+ line: options[:line],
58
+ add: !!options[:add]
59
+ )
39
60
  end
40
61
 
41
62
  rescue OptionParser::ParseError, Apender::Error => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apender
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/apender.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "apender/version"
@@ -6,9 +5,14 @@ require_relative "apender/version"
6
5
  module Apender
7
6
  class Error < StandardError; end
8
7
 
9
- def self.append(path, content)
8
+ def self.append(path, content, line: nil, add: false)
10
9
  raise Error, "File does not exist: #{path}" unless File.file?(path)
11
10
 
11
+ if line
12
+ write_line(path, content, line, add)
13
+ return
14
+ end
15
+
12
16
  File.open(path, "a") do |file|
13
17
  unless File.zero?(path)
14
18
  last_byte = File.binread(path, 1, File.size(path) - 1)
@@ -19,6 +23,33 @@ module Apender
19
23
  end
20
24
  end
21
25
 
26
+ def self.write_line(path, content, line, add)
27
+ raise Error, "Line number must be greater than 0" unless line.positive?
28
+ raise Error, "Content must be a single line" if content.include?("\n")
29
+
30
+ original = File.read(path)
31
+ trailing_newline = original.end_with?("\n")
32
+
33
+ lines = original.split("\n", -1)
34
+ lines.pop if trailing_newline
35
+
36
+ while lines.length < line
37
+ lines << ""
38
+ end
39
+
40
+ if add
41
+ lines[line - 1] ||= ""
42
+ lines[line - 1] += content
43
+ else
44
+ lines[line - 1] = content
45
+ end
46
+
47
+ result = lines.join("\n")
48
+ result += "\n" if trailing_newline
49
+
50
+ File.write(path, result)
51
+ end
52
+
22
53
  def self.newline(path)
23
54
  raise Error, "File does not exist: #{path}" unless File.file?(path)
24
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolau
@@ -9,6 +9,8 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
+ description: Apender is a lightweight Ruby CLI tool that appends content to files,
13
+ replaces specific lines, and adds text to existing lines.
12
14
  email:
13
15
  - nic13araujo@proton.me
14
16
  executables:
@@ -25,11 +27,13 @@ files:
25
27
  - lib/apender.rb
26
28
  - lib/apender/version.rb
27
29
  - sig/apender.rbs
28
- homepage: https://github.com
30
+ homepage: https://github.com/Nic24nix/apender
29
31
  licenses:
30
32
  - MIT
31
33
  metadata:
32
- homepage_uri: https://github.com
34
+ homepage_uri: https://github.com/Nic24nix/apender
35
+ source_code_uri: https://github.com/Nic24nix/apender/tree/master
36
+ changelog_uri: https://github.com/Nic24nix/apender/blob/master/CHANGELOG.md
33
37
  rdoc_options: []
34
38
  require_paths:
35
39
  - lib
@@ -46,5 +50,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
50
  requirements: []
47
51
  rubygems_version: 3.6.9
48
52
  specification_version: 4
49
- summary: Add content on the next line of a file
53
+ summary: A simple CLI tool to append and edit file lines
50
54
  test_files: []