changelog-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/changelog +117 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e42968def1777421eb7390bc15206a30f4f18e0593ed3e0f464bff905581223
4
+ data.tar.gz: 2fa8e3d92f3c96e6bb85822f86ed89a946c417a835022474f4594ae306e3ec0c
5
+ SHA512:
6
+ metadata.gz: 55cb6757d86c1b017e2b94eff7e8f78c9fdce2a5f0eb87c106456233d8a0661fa59caa070e3fdccc151cb1f31b5b9bef2421807aec0589122db6ea60431963ef
7
+ data.tar.gz: 942291212084aeea591d0d6fce3c570d499aa51c6cdba881b1a83261fcbe9a9c63051376eee403ae37897429f536bfae59017041aa99c7b5fb83097a86845d47
data/bin/changelog ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ require 'slop'
3
+ require 'date'
4
+
5
+ VERSION = "0.0.1"
6
+ DEFAULT_FILENAMES = [".changelog", "CHANGELOG"]
7
+ GLOBAL_CHANGELOG = "~/#{DEFAULT_FILENAMES.first}"
8
+
9
+ def default_changelog
10
+ possible_files = DEFAULT_FILENAMES.map { |f| File.expand_path "./#{f}" }
11
+ local_file = possible_files.find { |f| File.exists? f }
12
+
13
+ local_file || GLOBAL_CHANGELOG
14
+ end
15
+
16
+ def editor_available?(editor)
17
+ system("which #{editor} > /dev/null 2>&1")
18
+ end
19
+
20
+ def open_in_default_editor(filepath)
21
+ editor = [ENV['EDITOR'], 'nano', 'vi'].find { |e| editor_available?(e) }
22
+
23
+ if editor
24
+ system("#{editor} #{filepath}")
25
+ else
26
+ puts "ERROR: No editor found"
27
+ end
28
+ end
29
+
30
+ def add_line(file, line, modify = false)
31
+ today = Date.today.strftime("# %B %dth, %Y")
32
+ entry_exists = false
33
+ new_content = ""
34
+
35
+ prev_line = nil
36
+ new_line = "- #{line}"
37
+
38
+ if File.exist? file
39
+ content = File.read file
40
+
41
+ if modify
42
+ lines = content.lines
43
+ prev_line = lines.last
44
+ puts prev_line
45
+ # Attempt to replace the last line starting with "- "
46
+ # last_index = lines.rindex { |l| l.strip.start_with?("- ") }
47
+ # if last_index
48
+ # lines[last_index] = "- #{line}\n"
49
+ # content = lines.join
50
+ # end
51
+ new_content = content
52
+
53
+ else # fresh
54
+ entry_exists = content.include? today
55
+ new_content = content.chomp
56
+ new_content += "\n\n---\n\n" unless entry_exists
57
+ end
58
+
59
+ else # new file
60
+ new_content = "CHANGELOG\n---\n\n"
61
+ end
62
+
63
+ unless modify
64
+ new_content += today unless entry_exists
65
+ new_content += "\n#{new_line}\n"
66
+ end
67
+
68
+ # WRITE
69
+ File.write(file, new_content)
70
+
71
+ # FEEDBACK
72
+ unless modify
73
+ puts "\n#{file}:"
74
+ puts " #{new_line}"
75
+
76
+ else # modify
77
+ puts "MODIFY [#{file}], REPLACE:"
78
+ puts prev_line
79
+ puts "WITH:"
80
+ puts new_line
81
+ end
82
+ end
83
+
84
+ opts = Slop.parse do |o|
85
+ o.string '-f', '--file', 'changelog filepath', default: default_changelog
86
+ o.bool '-g', '--global', "overrides --file to use the global changelog at '#{GLOBAL_CHANGELOG}'"
87
+ o.bool '-m', '--modify', 'modify the last line logged'
88
+ o.bool '-o', '--open', 'open the changelog in default editor'
89
+ o.bool '--where', 'prints current changelog (can be used with -g)'
90
+ o.on '--version', 'print the version' do
91
+ puts VERSION
92
+ exit
93
+ end
94
+ o.on '--help', 'print this help message' do
95
+ puts o
96
+ exit
97
+ end
98
+ end
99
+
100
+ # RUN
101
+ #
102
+
103
+ changelog_file = File.expand_path(opts.global? ? GLOBAL_CHANGELOG : opts[:file])
104
+
105
+ if opts.where?
106
+ puts "CHANGELOG: #{changelog_file}"
107
+ exit
108
+ end
109
+
110
+ if !opts.arguments.empty?
111
+ line = opts.arguments.join " "
112
+ add_line(changelog_file, line, opts.modify?)
113
+ end
114
+
115
+ open_in_default_editor(changelog_file) if opts.open?
116
+
117
+ puts opts if ARGV.empty?
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: changelog-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vidur Murali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple tool to add/modify lines to changelogs
14
+ email: vidur@monkeychai.com
15
+ executables:
16
+ - changelog
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/changelog
21
+ homepage: https://github.com/10k-apps/changelog-cli
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.1.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: CLI to work with changelogs
44
+ test_files: []