Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli-v2s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Rust
Ğcli-v2s
Commits
ffb55891
Commit
ffb55891
authored
1 year ago
by
poka
Browse files
Options
Downloads
Patches
Plain Diff
add publish command to push git tag with actual version
parent
523901c7
No related branches found
No related tags found
1 merge request
!19
Add publish command
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/commands.rs
+1
-0
1 addition, 0 deletions
src/commands.rs
src/commands/publish.rs
+73
-0
73 additions, 0 deletions
src/commands/publish.rs
src/main.rs
+3
-0
3 additions, 0 deletions
src/main.rs
with
77 additions
and
0 deletions
src/commands.rs
+
1
−
0
View file @
ffb55891
...
@@ -8,6 +8,7 @@ pub mod expire;
...
@@ -8,6 +8,7 @@ pub mod expire;
pub
mod
identity
;
pub
mod
identity
;
pub
mod
net_test
;
pub
mod
net_test
;
pub
mod
oneshot
;
pub
mod
oneshot
;
pub
mod
publish
;
pub
mod
revocation
;
pub
mod
revocation
;
pub
mod
runtime
;
pub
mod
runtime
;
pub
mod
smith
;
pub
mod
smith
;
...
...
This diff is collapsed.
Click to expand it.
src/commands/publish.rs
0 → 100644
+
73
−
0
View file @
ffb55891
// commands/publish.rs
// This module handles the 'publish' command of the CLI.
use
crate
::
GcliError
;
// Custom error type.
use
anyhow
::
anyhow
;
use
std
::
fs
;
// For file system operations.
use
std
::
io
::{
self
,
Write
};
// For input/output operations.
use
std
::
process
::
Command
;
// For executing system commands. // For better error handling.
/// Asks the user for confirmation before proceeding.
fn
confirm_action
(
version
:
&
str
)
->
Result
<
bool
,
GcliError
>
{
print!
(
"Are you sure you want to publish tag version {}? (y/N) "
,
version
);
io
::
stdout
()
.flush
()
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
// Ensure the output is displayed immediately.
let
mut
response
=
String
::
new
();
io
::
stdin
()
.read_line
(
&
mut
response
)
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
Ok
(
response
.trim
()
.eq_ignore_ascii_case
(
"y"
))
// Checks if the user's input is 'y' (case insensitive).
}
/// Executes the 'publish' operation.
pub
async
fn
handle_command
()
->
Result
<
(),
GcliError
>
{
// Step 1: Read the version number from Cargo.toml
let
cargo_toml_content
=
fs
::
read_to_string
(
"Cargo.toml"
)
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
let
version
=
cargo_toml_content
.lines
()
.find
(|
line
|
line
.starts_with
(
"version ="
))
.and_then
(|
line
|
line
.split
(
'"'
)
.nth
(
1
))
.ok_or_else
(||
GcliError
::
Input
(
"Version not found in Cargo.toml"
.to_string
()))
?
;
// Step 2: Check if the git tag already exists
let
tag_check_output
=
Command
::
new
(
"git"
)
.args
([
"tag"
,
"-l"
,
&
format!
(
"{}"
,
version
)])
.output
()
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
if
!
tag_check_output
.stdout
.is_empty
()
{
return
Err
(
GcliError
::
Logic
(
format!
(
"Tag {} already exists"
,
version
)));
}
// Display a confirmation prompt with the version number.
if
!
confirm_action
(
&
version
)
?
{
println!
(
"Publication cancelled."
);
return
Ok
(());
}
// Step 3: Create and push the git tag
Command
::
new
(
"git"
)
.args
([
"tag"
,
"-a"
,
&
format!
(
"{}"
,
version
),
"-m"
,
&
format!
(
"Release v{}"
,
version
),
])
.status
()
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
Command
::
new
(
"git"
)
.args
([
"push"
,
"origin"
,
&
format!
(
"{}"
,
version
)])
.status
()
.map_err
(|
e
|
GcliError
::
Anyhow
(
anyhow!
(
e
)))
?
;
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
3
−
0
View file @
ffb55891
...
@@ -100,6 +100,8 @@ pub enum Subcommand {
...
@@ -100,6 +100,8 @@ pub enum Subcommand {
/// Cesium
/// Cesium
#[clap(subcommand,
hide
=
true
)]
#[clap(subcommand,
hide
=
true
)]
Cesium
(
commands
::
cesium
::
Subcommand
),
Cesium
(
commands
::
cesium
::
Subcommand
),
/// Publish a new git tag with actual version
Publish
,
}
}
/// main function
/// main function
...
@@ -135,6 +137,7 @@ async fn main() -> Result<(), GcliError> {
...
@@ -135,6 +137,7 @@ async fn main() -> Result<(), GcliError> {
Subcommand
::
Indexer
(
subcommand
)
=>
indexer
::
handle_command
(
data
,
subcommand
)
.await
,
Subcommand
::
Indexer
(
subcommand
)
=>
indexer
::
handle_command
(
data
,
subcommand
)
.await
,
Subcommand
::
Config
(
subcommand
)
=>
conf
::
handle_command
(
data
,
subcommand
),
Subcommand
::
Config
(
subcommand
)
=>
conf
::
handle_command
(
data
,
subcommand
),
Subcommand
::
Cesium
(
subcommand
)
=>
commands
::
cesium
::
handle_command
(
data
,
subcommand
)
.await
,
Subcommand
::
Cesium
(
subcommand
)
=>
commands
::
cesium
::
handle_command
(
data
,
subcommand
)
.await
,
Subcommand
::
Publish
=>
commands
::
publish
::
handle_command
()
.await
,
};
};
if
let
Err
(
ref
e
)
=
result
{
if
let
Err
(
ref
e
)
=
result
{
println!
(
"{}"
,
e
)
println!
(
"{}"
,
e
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment