Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ USAGE:
github-action-doc action <ACTION_FILE>

ARGS:
<ACTION_FILE>
<ACTION_FILE> Action YAML file

OPTIONS:
-h, --help Print help information

```

### Documenting GitHub Workflows
Expand All @@ -29,13 +28,15 @@ $ github-action-doc workflow -h
Generate documentation for a Github workflow

USAGE:
github-action-doc workflow <WORKFLOW_FILE>
github-action-doc workflow [OPTIONS] <WORKFLOW_FILE>

ARGS:
<WORKFLOW_FILE>
<WORKFLOW_FILE> Workflow YAML file

OPTIONS:
-h, --help Print help information
-h, --help Print help information
-o <OUTPUT_FILE> Optional path to the output file to write workflow documentation to;
defaults to `<WORKFLOW_FILE>.md`, replacing the YAML file extension
```

## Examples
Expand Down
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{Subcommand};
use clap::Parser;

#[derive(Debug, Parser)]
#[clap(name = "github-action-doc")]
#[clap(name = "github-action-doc", version)]
#[clap(about = "A GitHub action & workflow readme writer", long_about = None)]
pub struct Cli {
#[clap(subcommand)]
Expand All @@ -14,12 +14,19 @@ pub enum Commands {
#[clap(arg_required_else_help = true)]
#[clap(about = "Generate documentation for a Github action", long_about = None)]
Action {
/// Action YAML file
#[clap(required = true, value_parser)]
action_file: String
},
#[clap(arg_required_else_help = true)]
#[clap(about = "Generate documentation for a Github workflow", long_about = None)]
Workflow {
/// Optional path to the output file to write workflow documentation to;
/// defaults to `<WORKFLOW_FILE>.md`, replacing the YAML file extension.
#[clap(short = 'o', value_name = "OUTPUT_FILE", value_parser)]
output_file: Option<String>,

/// Workflow YAML file
#[clap(required = true, value_parser)]
workflow_file: String
}
Expand Down
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let readme_path = Path::new(&action_file).to_path_buf().parent().unwrap().join("README.md");
fs::write(readme_path.to_str().unwrap(), gha.to_markdown().to_string()).expect("Unable to write readme");
}
cli::Commands::Workflow { workflow_file} => {
cli::Commands::Workflow { workflow_file, output_file } => {
let workflow = GitHubWorkflow::parse(&workflow_file)
.expect("Unable to parse workflow");
let wf_path = Path::new(&workflow_file).to_path_buf();
let readme_path = wf_path
.parent()
.unwrap()
.join(&format!("{}.md", wf_path.file_stem().unwrap().to_str().unwrap()));
let readme_path = match output_file {
Some(out) => { Path::new(&out).to_path_buf() },
None => {
wf_path
.parent()
.unwrap()
.join(&format!("{}.md", wf_path.file_stem().unwrap().to_str().unwrap()))
}
};

println!("Writing workflow readme {:?}", &readme_path);
fs::write(readme_path.to_str().unwrap(), workflow.to_markdown().to_string()).expect("Unable to write readme");
Expand Down