MCPcopy Create free account
hub / github.com/ccusage/ccusage / parse_command

Function parse_command

rust/crates/ccusage-cli/src/parser.rs:104–269  ·  view source on GitHub ↗
(
    command: &str,
    parser: &mut ArgParser,
    shared: SharedArgs,
    config: &dyn CliConfig,
    default_session_duration_hours: f64,
)

Source from the content-addressed store, hash-verified

102}
103
104fn parse_command(
105 command: &str,
106 parser: &mut ArgParser,
107 shared: SharedArgs,
108 config: &dyn CliConfig,
109 default_session_duration_hours: f64,
110) -> Result<Command, String> {
111 match command {
112 "daily" => parse_all_command(parser, shared, AgentReportKind::Daily, config),
113 "monthly" => parse_all_command(parser, shared, AgentReportKind::Monthly, config),
114 "weekly" => parse_all_command(parser, shared, AgentReportKind::Weekly, config),
115 "session" => parse_top_level_session_command(parser, shared, config),
116 "blocks" => {
117 let mut args = BlocksArgs {
118 shared,
119 active: false,
120 recent: false,
121 token_limit: None,
122 session_length: default_session_duration_hours,
123 };
124 config.apply_blocks_args(&mut args);
125 while parser.peek().is_some() {
126 if parse_shared_arg_for_command(parser, &mut args.shared)? {
127 continue;
128 }
129 match parser.next_flag()?.as_str() {
130 "-a" | "--active" => args.active = true,
131 "-r" | "--recent" => args.recent = true,
132 "-t" | "--token-limit" => {
133 args.token_limit = Some(parser.value_for("--token-limit")?)
134 }
135 "-n" | "--session-length" => {
136 args.session_length = parser
137 .value_for("--session-length")?
138 .parse()
139 .map_err(|_| "Invalid value for --session-length".to_string())?
140 }
141 flag => return Err(format!("Unknown blocks option '{flag}'")),
142 }
143 }
144 Ok(Command::Blocks(args))
145 }
146 "statusline" => {
147 let mut args = StatuslineArgs::default();
148 config.apply_statusline_args(&mut args);
149 while parser.peek().is_some() {
150 match parser.next_flag()?.as_str() {
151 "-O" | "--offline" => args.offline = true,
152 "--no-offline" => args.no_offline = true,
153 "-B" | "--visual-burn-rate" => {
154 args.visual_burn_rate =
155 parse_visual_burn_rate(&parser.value_for("--visual-burn-rate")?)?
156 }
157 "--cost-source" => {
158 args.cost_source = parse_cost_source(&parser.value_for("--cost-source")?)?
159 }
160 "--cache" => args.cache = true,
161 "--no-cache" => args.no_cache = true,

Callers 2

parse_claude_commandFunction · 0.85

Calls 15

parse_all_commandFunction · 0.85
parse_visual_burn_rateFunction · 0.85
parse_cost_sourceFunction · 0.85
parse_claude_commandFunction · 0.85
parse_codex_commandFunction · 0.85
parse_pi_commandFunction · 0.85
parse_openclaw_commandFunction · 0.85
peekMethod · 0.80
next_flagMethod · 0.80

Tested by

no test coverage detected