Skip to content
Snippets Groups Projects
Select Git revision
  • 4010a9e40db1b3beeebb06151fdf3c008496d4a3
  • master default protected
  • json-output
  • nostr
  • 48-error-base-58-requirement-is-violated
  • no-rename
  • hugo/tx-comments
  • poka/dev
  • hugo/dev
  • tuxmain/mail
  • 0.4.3-RC2
  • 0.4.3-RC1
  • 0.4.2
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.17
  • 0.2.16
  • 0.2.15
  • 0.2.14
  • 0.2.13
  • 0.2.12
  • 0.2.10
  • 0.2.9
  • 0.2.8
  • 0.2.7
  • 0.2.6
  • 0.2.5
  • 0.2.4
  • 0.2.3
30 results

publish.rs

Blame
  • publish.rs 1.65 KiB
    // commands/publish.rs
    // This module handles the 'publish' command of the CLI.
    
    use crate::GcliError;
    use anyhow::anyhow;
    use inquire::Confirm;
    use std::process::Command;
    
    /// Executes the 'publish' operation.
    pub async fn handle_command() -> Result<(), GcliError> {
    	// Step 1: Get actual version of gcli
    	const VERSION: &str = env!("CARGO_PKG_VERSION");
    
    	// Fetch the latest tags from the remote repository
    	Command::new("git")
    		.args(["fetch", "--tags"])
    		.status()
    		.map_err(|e| anyhow!(e))?;
    
    	// Step 2: Check if the git tag already exists
    	let tag_check_output = Command::new("git").args(["tag", "-l", VERSION]).output()?;
    
    	if !tag_check_output.stdout.is_empty() {
    		return Err(GcliError::Logic(format!("Tag {VERSION} already exists")));
    	}
    
    	// Display a confirmation prompt with the version number.
    	match Confirm::new(&format!(
    		"Are you sure you want to publish version {VERSION} ?"
    	))
    	.with_default(false)
    	.prompt()
    	{
    		Ok(true) => {
    			// User confirmed, proceed publishing
    			// Step 3: Create and push the git tag
    
    			Command::new("git")
    				.args(["tag", "-a", VERSION, "-m", &format!("Release v{VERSION}")])
    				.status()
    				.map_err(|e| anyhow!(e))?;
    
    			Command::new("git")
    				.args(["push", "origin", &format!("refs/tags/{VERSION}")])
    				.status()
    				.map_err(|e| anyhow!(e))?;
    			println!("Publication of version {VERSION} completed successfully.");
    			Ok(())
    		}
    		Ok(false) => {
    			// User did not confirm, cancel the operation
    			println!("Publication cancelled.");
    			Ok(())
    		}
    		Err(_) => {
    			// There was an error with the prompt, return an error
    			Err(GcliError::Input(
    				"Failed to display confirmation prompt".to_string(),
    			))
    		}
    	}
    }