Skip to content

Commit

Permalink
Replace all positional arguments with flagged ones (#14)
Browse files Browse the repository at this point in the history
* Make path a common option to the whole CLI

Signed-off-by: Thane Thomson <[email protected]>

* Make positional arguments flagged instead

Signed-off-by: Thane Thomson <[email protected]>

* Rename build:project-type field to build:type in CLI

Signed-off-by: Thane Thomson <[email protected]>

* Shorten name of init:epilogue-path field to init::epilogue

Signed-off-by: Thane Thomson <[email protected]>

* Update readme for new CLI changes

Signed-off-by: Thane Thomson <[email protected]>

* Add .changelog entry

Signed-off-by: Thane Thomson <[email protected]>

* cargo fmt

Signed-off-by: Thane Thomson <[email protected]>
  • Loading branch information
thanethomson authored Aug 17, 2021
1 parent b28646d commit d6cdffe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/breaking-changes/12-positional-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- All positional CLI arguments have now been replaced with flagged ones. See
`unclog --help` and the project `README.md` for more details.
([#12](https://github.com/informalsystems/unclog/issues/12))
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ unclog init -e CHANGELOG.md
#
# The convention is that you *must* prepend the issue/PR number to which the
# change refers to the entry ID (i.e. 23-some-new-feature relates to issue 23).
unclog add features 23-some-new-feature
unclog add --section features --id 23-some-new-feature

# Add another feature in a different section
unclog add breaking-changes 24-break-the-api
unclog add -s breaking-changes -i 24-break-the-api
```

The format of an entry is currently recommended as the following (in Markdown):
Expand Down Expand Up @@ -149,7 +149,7 @@ unclog --help
```bash
# Moves all entries in your ".changelog/unreleased" folder to
# ".changelog/v0.2.0" and ensures the ".changelog/unreleased" folder is empty.
unclog release v0.2.0
unclog release --version v0.2.0
```

### As a Library
Expand Down
46 changes: 14 additions & 32 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const ADD_CHANGE_TEMPLATE: &str = r#"<!--

#[derive(StructOpt)]
struct Opt {
/// The path to the changelog folder.
#[structopt(short, long, default_value = ".changelog")]
path: PathBuf,

/// Increase output logging verbosity to DEBUG level.
#[structopt(short, long)]
verbose: bool,
Expand All @@ -38,13 +42,9 @@ struct Opt {
enum Command {
/// Create and initialize a fresh .changelog folder.
Init {
/// An optional epilogue to add to the new changelog.
#[structopt(short, long)]
/// The path to an epilogue to optionally append to the new changelog.
#[structopt(name = "epilogue", short, long)]
epilogue_path: Option<PathBuf>,

/// The path to the changelog folder to initialize.
#[structopt(default_value = ".changelog")]
path: PathBuf,
},
/// Add a change to the unreleased set of changes.
Add {
Expand All @@ -58,29 +58,23 @@ enum Command {

/// The ID of the section to which the change must be added (e.g.
/// "breaking-changes").
#[structopt(short, long)]
section: String,

/// The ID of the change to add, which should include the number of the
/// issue or PR to which the change applies (e.g. "820-change-api").
#[structopt(short, long)]
id: String,

/// The path to the changelog folder to build.
#[structopt(default_value = ".changelog")]
path: PathBuf,
},
/// Build the changelog from the input path and write the output to stdout.
Build {
/// The path to the changelog folder to build.
#[structopt(default_value = ".changelog")]
path: PathBuf,

/// Only render unreleased changes.
#[structopt(short, long)]
unreleased: bool,

/// The type of project this is. If not supplied, unclog will attempt
/// to autodetect it.
#[structopt(short = "t", long)]
#[structopt(name = "type", short, long)]
project_type: Option<ProjectType>,
},
/// Release any unreleased features.
Expand All @@ -90,11 +84,8 @@ enum Command {
editor: PathBuf,

/// The version string to use for the new release (e.g. "v0.1.0").
#[structopt(long)]
version: String,

/// The path to the changelog folder.
#[structopt(default_value = ".changelog")]
path: PathBuf,
},
}

Expand All @@ -114,26 +105,17 @@ fn main() {

let result = match opt.cmd {
Command::Build {
path,
unreleased,
project_type,
} => build_changelog(&path, unreleased, project_type),
} => build_changelog(&opt.path, unreleased, project_type),
Command::Add {
editor,
component,
section,
id,
path,
} => add_unreleased_entry(&editor, &path, &section, component, &id),
Command::Init {
epilogue_path,
path,
} => Changelog::init_dir(path, epilogue_path),
Command::Release {
editor,
version,
path,
} => prepare_release(&editor, &path, &version),
} => add_unreleased_entry(&editor, &opt.path, &section, component, &id),
Command::Init { epilogue_path } => Changelog::init_dir(opt.path, epilogue_path),
Command::Release { editor, version } => prepare_release(&editor, &opt.path, &version),
};
if let Err(e) = result {
log::error!("Failed: {}", e);
Expand Down

0 comments on commit d6cdffe

Please sign in to comment.