blob: 68cce4d232acbabdf48ed37e4aaa3e29e75826f5 [file]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use clap::{Args, Subcommand};
use iggy::prelude::Identifier;
#[derive(Debug, Clone, Subcommand)]
pub(crate) enum SegmentAction {
/// Delete segments for the specified topic ID,
/// stream ID and partition ID based on the given count.
///
/// Stream ID can be specified as a stream name or ID
/// Topic ID can be specified as a topic name or ID
/// Partition ID must be numeric
///
/// Examples
/// iggy segment delete 1 1 1 10
/// iggy segment delete prod 2 2 2
/// iggy segment delete test sensor 2 2
/// iggy segment delete 1 sensor 2 16
#[clap(verbatim_doc_comment, visible_alias = "d")]
Delete(SegmentDeleteArgs),
}
#[derive(Debug, Clone, Args)]
pub(crate) struct SegmentDeleteArgs {
/// Stream ID to delete segments
///
/// Stream ID can be specified as a stream name or ID
#[arg(value_parser = clap::value_parser!(Identifier))]
pub(crate) stream_id: Identifier,
/// Topic ID to delete segments
///
/// Topic ID can be specified as a topic name or ID
#[arg(value_parser = clap::value_parser!(Identifier))]
pub(crate) topic_id: Identifier,
/// Partition ID to delete segments
pub(crate) partition_id: u32,
/// Segments count to be deleted
#[arg(value_parser = clap::value_parser!(u32).range(1..100_001))]
pub(crate) segments_count: u32,
}
#[cfg(test)]
mod tests {
use super::SegmentAction;
use crate::args::{Command, IggyConsoleArgs};
use clap::Parser;
#[test]
fn given_numeric_partition_when_deleting_segments_should_parse_command() {
for partition in ["0", "1"] {
let parsed = IggyConsoleArgs::try_parse_from([
"iggy", "segment", "delete", "dev", "events", partition, "3",
])
.unwrap();
let Some(Command::Segment(SegmentAction::Delete(args))) = parsed.command else {
panic!("Expected the segment delete command");
};
assert_eq!(args.partition_id.to_string(), partition);
assert_eq!(args.segments_count, 3);
}
assert!(
IggyConsoleArgs::try_parse_from([
"iggy",
"segment",
"delete",
"dev",
"events",
"named-partition",
"3",
])
.is_err()
);
}
}