Class: GFSM::Commands::Changelog
Constant Summary
collapse
- NEXT_ENTRY_MARKER =
"<!--- next entry here -->"
Instance Attribute Summary
Attributes inherited from BaseCommand
#stderr, #stdout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseCommand
#initialize
Class Method Details
.help ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/commands/changelog.rb', line 9
def self.help
cli_info = GFSM::Tools::VersionBumperSettings.cli_info
" Usage:\n gfsm changelog [help|generate|extract] [--output-file <path>] [--input-file <path>] [--no-incremental] [--only-new-entries] [--extract-version <version>] \#{cli_info[:usage]}\n\n Commands:\n help # Prints this help\n generate # Generate the changelog for the current version\n extract # Extract the changelog for the latest or specified version\n\n Options:\n --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\n --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\n --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\n --input-file <path> # Path to the input changelog file. Defaults to 'CHANGELOG.md'\n --extract-version <version> # Version from which to extract the changelog. Defaults to the latest one on the changelog file\n \#{cli_info[:options]}\n\n Environment variables:\n OUTPUT_FILE # Equivalent to --output-file\n NO_INCREMENTAL # Equivalent to --no-incremental\n ONLY_NEW_ENTRIES # Equivalent to --only-new-entries\n INPUT_FILE # Equivalent to --input-file\n EXTRACT_VERSION # Equivalent to --extract-version\n \#{cli_info[:environment_variables]}\n HELP\nend\n"
|
Instance Method Details
#run(args = []) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/commands/changelog.rb', line 39
def run(args = [])
case args.shift
when 'help'
GFSM::Output.puts(GFSM::Commands::Changelog.help)
when 'generate'
no_incremental = ENV.has_key?("NO_INCREMENTAL") || args.include?("--no-incremental")
only_new_entries = ENV.has_key?("ONLY_NEW_ENTRIES") || args.include?("--only-new-entries")
output_file_path = get_output_file_path(args)
changelog_section = compute_this_version_section(args, only_new_entries)
if only_new_entries
GFSM::Output.puts changelog_section
elsif !output_file_path
GFSM::Output.puts " # Changelog\n \#{changelog_section}\n CHANGELOG\n else\n if File.file?(output_file_path) && !no_incremental\n existing_content = File.read(output_file_path)\n\n file_content = existing_content.gsub(/\#{Regexp.quote(NEXT_ENTRY_MARKER)}/i, changelog_section)\n\n File.open(output_file_path, 'w') { |file| file.write file_content }\n else\n File.open(output_file_path, 'w') do |file|\n file.write <<~CHANGELOG\n # Changelog\n \#{changelog_section}\n CHANGELOG\n end\n end\n end\n when 'extract'\n input_file_path = get_input_file_path(args)\n version_to_extract = get_version_to_extract(args)\n\n unless File.file?(input_file_path)\n GFSM::Output.error \"No changelog file found at \#{input_file_path}\"\n else\n section = extract_version_section(input_file_path, version_to_extract)\n\n if section.nil?\n GFSM::Output.error \"No changelog section found for version \#{version_to_extract}\"\n else\n GFSM::Output.puts section\n end\n end\n else\n GFSM::Output.warn GFSM::Commands::Changelog.help\n end\n\n true\nend\n"
|