gfsm 0.4.1 → 0.5.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: 609b6aa36f5d40d22494c91916c704c41917d3aa04974a07b625fa606d66242c
4
- data.tar.gz: d93219bb8abccaf7a4cbeb0fb098ba4f9913d9e6903fb2b47b28504fa80cf256
3
+ metadata.gz: bcc64afb8b73256994f18c36d2a639a046e0590ec702860b6cc60346cb764752
4
+ data.tar.gz: '048ff158cca74ebd96952424b7c8246bcae31f99d75a94d679e713411bf7aa51'
5
5
  SHA512:
6
- metadata.gz: 6ce084d2804499c1a61412bd291a8dc987bd9e8a04a0826c68a9f0b0d9210cf028c79e76686e5eacab490c72cf1700cf2d18fc69ad5d091997cb71559b545f3b
7
- data.tar.gz: b127e98c31c81acee6892904785991c08ec8c8a478b0a607bc7498f0f2f5b2c2e831632007409da7da4aca9cacff468c27be77d4742c5d7745aaee2fac238fcc
6
+ metadata.gz: 0b3283af8114728bc505d00af6e12fe6b7ebc0011e9f3fdddf0fb254752a78e98dc67283ae294c4acf3660ba2a5856c673f53786c6fb1899252df8db52058d42
7
+ data.tar.gz: 0d739d31c958f5802b595521ec7ed0ad573220a7930d5c79272628fc0172cbf71fc0129ea29ed7fd8a74036ce1f869824eb6af16e251fc6116631ab6421cf9c2
data/.version CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/bin/gfsm CHANGED
File without changes
@@ -11,22 +11,27 @@ module GFSM
11
11
 
12
12
  <<~HELP
13
13
  Usage:
14
- gfsm changelog [help|generate] [--output-file <path>] [--no-incremental] #{cli_info[:usage]}
14
+ gfsm changelog [help|generate|extract] [--output-file <path>] [--input-file <path>] [--no-incremental] [--only-new-entries] [--extract-version <version>] #{cli_info[:usage]}
15
15
 
16
16
  Commands:
17
17
  help # Prints this help
18
18
  generate # Generate the changelog for the current version
19
+ extract # Extract the changelog for the latest or specified version
19
20
 
20
21
  Options:
21
22
  --output-file <path> # Path to the output changelog file. Defaults to 'CHANGELOG.md'. If not specified, the generate changelog content will be written to stdout
22
23
  --no-incremental # When provided, the generated changelog won't look for an existing changelog file. When outputting to stdout the changelog will never be incremental
23
24
  --only-new-entries # When provided, the generated changelog won't look for an existing changelog file and will contain only the new entries for the current version, without the Changelog or version headings
25
+ --input-file <path> # Path to the input changelog file. Defaults to 'CHANGELOG.md'
26
+ --extract-version <version> # Version from which to extract the changelog. Defaults to the latest one on the changelog file
24
27
  #{cli_info[:options]}
25
28
 
26
29
  Environment variables:
27
30
  OUTPUT_FILE # Equivalent to --output-file
28
31
  NO_INCREMENTAL # Equivalent to --no-incremental
29
32
  ONLY_NEW_ENTRIES # Equivalent to --only-new-entries
33
+ INPUT_FILE # Equivalent to --input-file
34
+ EXTRACT_VERSION # Equivalent to --extract-version
30
35
  #{cli_info[:environment_variables]}
31
36
  HELP
32
37
  end
@@ -64,8 +69,23 @@ module GFSM
64
69
  end
65
70
  end
66
71
  end
72
+ when 'extract'
73
+ input_file_path = get_input_file_path(args)
74
+ version_to_extract = get_version_to_extract(args)
75
+
76
+ unless File.file?(input_file_path)
77
+ GFSM::Output.error "No changelog file found at #{input_file_path}"
78
+ else
79
+ section = extract_version_section(input_file_path, version_to_extract)
80
+
81
+ if section.nil?
82
+ GFSM::Output.error "No changelog section found for version #{version_to_extract}"
83
+ else
84
+ GFSM::Output.puts section
85
+ end
86
+ end
67
87
  else
68
- GFSM::Output.warn(GFSM::Commands::Version.help)
88
+ GFSM::Output.warn GFSM::Commands::Version.help
69
89
  end
70
90
 
71
91
  true
@@ -106,6 +126,44 @@ module GFSM
106
126
  "#{section}\n\n#{changelog_entries}"
107
127
  end
108
128
 
129
+ def extract_version_section(input_file_path, version_to_extract)
130
+ file_content = File.read(input_file_path)
131
+
132
+ # Parse the file contect to subdivide the changelog sections based on the version
133
+ version_sections = file_content.split(/^## /)
134
+
135
+ # Remove the initial empty section
136
+ version_sections.shift
137
+
138
+ version_to_extract_index = if version_to_extract.nil? || version_to_extract == "latest"
139
+ 0
140
+ else
141
+ version_sections.find_index { |section| section.start_with?("#{version_to_extract}\n") }
142
+ end
143
+ return nil if version_to_extract_index.nil? || version_to_extract_index > version_sections.length
144
+
145
+ version_section = version_sections[version_to_extract_index]
146
+
147
+ # Remove the first line that contains version heading
148
+ version_section = version_section[version_section.index("\n")..-1]
149
+
150
+ # Remove the empty lines at the start and at the end of version_section
151
+ version_section = version_section.strip
152
+
153
+ return version_section
154
+ end
155
+
156
+ def extract_switch_value(args, switch, default_value, env_name = nil)
157
+ return ENV.fetch(env_name) if ENV.has_key?(env_name)
158
+
159
+ switch_index = args.find_index(switch)
160
+
161
+ return default_value unless switch_index &&
162
+ (switch_index + 1) < args.length
163
+
164
+ args[switch_index + 1]
165
+ end
166
+
109
167
  def extract_switch_value_if_present(args, switch, default_value, env_name)
110
168
  return ENV.fetch(env_name) if ENV.has_key?(env_name)
111
169
 
@@ -120,6 +178,14 @@ module GFSM
120
178
  def get_output_file_path(args)
121
179
  extract_switch_value_if_present(args, "--output-file", "./CHANGELOG.md", "OUTPUT_FILE")
122
180
  end
181
+
182
+ def get_input_file_path(args)
183
+ extract_switch_value(args, "--input-file", "./CHANGELOG.md", "INPUT_FILE")
184
+ end
185
+
186
+ def get_version_to_extract(args)
187
+ extract_switch_value(args, "--extract-version", nil, "EXTRACT_VERSION")
188
+ end
123
189
  end
124
190
  end
125
191
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gfsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zille Marco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml