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
1 change: 0 additions & 1 deletion caffeine_cli/src/caffeine_cli.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ fn dispatch(parsed: ParsedArgs) -> Result(Nil, String) {
let check = get_bool_flag(parsed.flags, "check")
handler.run_format(quiet, check, parsed.positional)
}
"artifacts" -> handler.run_artifacts(quiet)
"types" -> handler.run_types(quiet)
"explain" -> handler.run_explain(parsed.positional)
other -> Error(unknown_command_message(other))
Expand Down
9 changes: 0 additions & 9 deletions caffeine_cli/src/caffeine_cli/args.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ pub fn commands() -> List(CommandSpec) {
"caffeine format expectations/ --check",
],
),
CommandSpec(
name: "artifacts",
summary: "List standard-library artifacts",
signature: "",
description: "Print the catalog of artifacts (e.g. SLO) provided by Caffeine's "
<> "standard library, including each artifact's parameters and types.",
flags: [FlagSpec("--quiet", "Suppress decorative output")],
examples: ["caffeine artifacts"],
),
CommandSpec(
name: "types",
summary: "Show the type-system reference",
Expand Down
50 changes: 1 addition & 49 deletions caffeine_cli/src/caffeine_cli/display.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import caffeine_cli/color.{type ColorMode}
import caffeine_lang/linker/artifacts.{type ParamInfo}
import caffeine_lang/types.{
type AcceptedTypes, type TypeMeta, Defaulted, ModifierType, OneOf, Optional,
RefinementType,
}
import gleam/dict
import caffeine_lang/types.{type TypeMeta}
import gleam/list
import gleam/string

Expand All @@ -27,49 +22,6 @@ pub fn pretty_print_category(
header <> "\n\n" <> type_entries
}

/// Pretty-prints SLO params showing name, description, and type details.
pub fn pretty_print_slo_params(
params: dict.Dict(String, ParamInfo),
mode: ColorMode,
) -> String {
let header =
color.bold(color.cyan("SLO", mode), mode)
<> ": "
<> color.dim(
"\"A Service Level Objective that monitors a metric query against a threshold over a rolling window.\"",
mode,
)
let param_lines =
params
|> dict.to_list
|> list.sort(fn(a, b) { string.compare(a.0, b.0) })
|> list.map(fn(pair) {
let #(name, param_info) = pair
" "
<> color.yellow(name, mode)
<> ": "
<> color.dim("\"" <> param_info.description <> "\"", mode)
<> "\n type: "
<> color.green(types.accepted_type_to_string(param_info.type_), mode)
<> "\n "
<> param_status(param_info.type_, mode)
})
|> string.join("\n")

header <> "\n\n" <> param_lines
}

/// Returns the status of a parameter: "required", "optional", or "default: <value>".
fn param_status(typ: AcceptedTypes, mode: ColorMode) -> String {
case typ {
ModifierType(Optional(_)) -> color.dim("optional", mode)
ModifierType(Defaulted(_, default)) ->
color.blue("default: " <> default, mode)
RefinementType(OneOf(inner, _)) -> param_status(inner, mode)
_ -> color.magenta("required", mode)
}
}

/// Pretty-prints a single type entry.
fn pretty_print_type_meta(meta: TypeMeta, mode: ColorMode) -> String {
let name_line =
Expand Down
6 changes: 3 additions & 3 deletions caffeine_cli/src/caffeine_cli/explanations.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn all() -> Dict(String, Explanation) {
"An artifact reference whose template body is malformed.",
"A standard-library artifact the linker doesn't recognize.",
],
fix: "Check the artifact name and argument list against `caffeine artifacts`. If you wrote a custom artifact reference, verify its template syntax.",
fix: "Check the artifact name and argument list in the offending fragment. If you wrote a custom artifact reference, verify its template syntax.",
link: option.Some(docs_root <> "E301"),
),

Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn all() -> Dict(String, Explanation) {
"A `$`-prefixed reference without a matching parameter definition.",
"Template argument count doesn't match the template's parameter list.",
],
fix: "Locate the template named in the error and verify its body is well-formed. Artifact templates live in the standard library — `caffeine artifacts` lists them.",
fix: "Locate the template named in the error and verify its body is well-formed.",
link: option.Some(docs_root <> "E402"),
),

Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn all() -> Dict(String, Explanation) {
"Measurement uses a vendor Caffeine's current build doesn't support.",
"Vendor name was normalized unexpectedly (check case and spelling).",
],
fix: "Check `caffeine artifacts` or the project's supported-vendor list. If the vendor should be supported, this is a compiler bug — please file it.",
fix: "Check the project's supported-vendor list. If the vendor should be supported, this is a compiler bug — please file it.",
link: option.Some(docs_root <> "E500"),
),

Expand Down
23 changes: 0 additions & 23 deletions caffeine_cli/src/caffeine_cli/handler.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import caffeine_lang/constants
import caffeine_lang/errors
import caffeine_lang/frontend/formatter
import caffeine_lang/source_file.{SourceFile, VendorMeasurementSource}
import caffeine_lang/standard_library/artifacts as stdlib_artifacts
import caffeine_lang/types
import filepath
import gleam/bool
Expand Down Expand Up @@ -81,12 +80,6 @@ pub fn run_format(
format_command(path, check_only, log_level)
}

/// Run the artifacts command.
@internal
pub fn run_artifacts(quiet: Bool) -> Result(Nil, String) {
artifacts_catalog(log_level_from_quiet(quiet), color.detect_color_mode())
}

/// Run the types command.
@internal
pub fn run_types(quiet: Bool) -> Result(Nil, String) {
Expand Down Expand Up @@ -378,22 +371,6 @@ fn write_file(path: String, content: String) -> Result(Nil, String) {
})
}

fn artifacts_catalog(
log_level: LogLevel,
mode: color.ColorMode,
) -> Result(Nil, String) {
compile_presenter.log(log_level, "Artifact Catalog")
compile_presenter.log(log_level, string.repeat("=", 16))
compile_presenter.log(log_level, "")

stdlib_artifacts.slo_params()
|> display.pretty_print_slo_params(mode)
|> compile_presenter.log(log_level, _)

compile_presenter.log(log_level, "")
Ok(Nil)
}

fn types_catalog(
log_level: LogLevel,
mode: color.ColorMode,
Expand Down
6 changes: 3 additions & 3 deletions caffeine_cli/test/caffeine_cli/args_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import gleeunit/should

pub fn commands_lists_all_subcommands_test() {
let names = args.command_names()
["compile", "format", "artifacts", "types", "explain"]
["compile", "format", "types", "explain"]
|> list.each(fn(expected) {
case list.contains(names, expected) {
True -> Nil
Expand Down Expand Up @@ -83,9 +83,9 @@ pub fn usage_message_includes_signature_test() {
}

pub fn usage_message_omits_signature_for_no_arg_command_test() {
let assert Some(spec) = args.find("artifacts")
let assert Some(spec) = args.find("types")
let msg = args.usage_message(spec)
msg |> should.equal("Usage: caffeine artifacts")
msg |> should.equal("Usage: caffeine types")
}

// --- usage_for ---
Expand Down
35 changes: 0 additions & 35 deletions caffeine_cli/test/caffeine_cli/display_test.gleam
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
import caffeine_cli/color
import caffeine_cli/display
import caffeine_lang/linker/artifacts.{ParamInfo}
import caffeine_lang/types.{TypeMeta}
import gleam/dict
import gleam/string
import gleeunit/should
import test_helpers

const off = color.ColorDisabled

// ==== pretty_print_slo_params ====
// * ✅ includes SLO name
// * ✅ includes param names
// * ✅ includes param descriptions
// * ✅ includes param types
// * ✅ includes param status (required/optional/default)
pub fn pretty_print_slo_params_test() {
let params =
dict.from_list([
#(
"my_param",
ParamInfo(
type_: types.PrimitiveType(types.String),
description: "My param description",
),
),
])
let output = display.pretty_print_slo_params(params, off)

// Verify all expected content is present in the output
[
#("includes SLO name", "SLO", True),
#("includes param names", "my_param", True),
#("includes param descriptions", "My param description", True),
#("includes param types", "String", True),
#("includes param status (required/optional/default)", "required", True),
]
|> test_helpers.table_test_1(fn(substring) {
string.contains(output, substring)
})
}

// ==== pretty_print_category ====
// * ✅ empty types list -> header only
// * ✅ single type -> header + type entry
Expand Down
4 changes: 2 additions & 2 deletions caffeine_cli/test/caffeine_cli/distance_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn levenshtein_unrelated_test() {
// --- nearest ---

pub fn nearest_finds_close_match_test() {
let candidates = ["compile", "format", "artifacts"]
let candidates = ["compile", "format", "types"]
distance.nearest("compil", candidates, max_distance: 2)
|> should.equal(Some("compile"))
}
Expand All @@ -47,7 +47,7 @@ pub fn nearest_picks_closest_when_multiple_test() {
}

pub fn nearest_returns_none_when_too_far_test() {
let candidates = ["compile", "format", "artifacts"]
let candidates = ["compile", "format", "types"]
distance.nearest("xyzzy", candidates, max_distance: 2)
|> should.equal(None)
}
Expand Down
7 changes: 0 additions & 7 deletions caffeine_cli/test/caffeine_cli/handler_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ pub fn format_exit_code_test() {
|> should.be_error()
}

// ==== Artifacts Command ====
// * ✅ artifacts returns Ok
pub fn artifacts_exit_code_test() {
caffeine_cli.run(["artifacts", "--quiet"])
|> should.be_ok()
}

// ==== Types Command ====
// * ✅ types returns Ok
pub fn types_exit_code_test() {
Expand Down
4 changes: 2 additions & 2 deletions caffeine_cli/test/caffeine_cli/help_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn themed_includes_tagline_test() {

pub fn themed_lists_all_commands_test() {
let out = help.render(off, Themed, True)
["compile", "format", "artifacts", "types"]
["compile", "format", "types"]
|> all_present(out)
}

Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn plain_does_not_use_themed_tagline_test() {

pub fn plain_lists_all_commands_test() {
let out = help.render(off, Plain, True)
["compile", "format", "artifacts", "types"]
["compile", "format", "types"]
|> all_present(out)
}

Expand Down
Loading