File size: 1,334 Bytes
1244914
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import path from "path";

export type CliArgs = {
  evalName: string;
  evalDir: string;
  taskFile: string;
};

/**
 * Parses command line arguments and resolves paths
 */
export async function parseCliArgs(dirname: string): Promise<CliArgs> {
  const argv = await yargs(hideBin(process.argv))
    .usage("Usage: $0 <eval-name> [options]")
    .command("$0 <eval-name>", "Run an evaluation")
    .positional("eval-name", {
      describe: "Name of the evaluation to run",
      type: "string",
    })
    .help()
    .alias("h", "help")
    .parseAsync();

  const evalName = argv["eval-name"];

  // Ensure evalName is provided
  if (!evalName) {
    throw new Error("eval-name is required");
  }

  // Support both directory path and direct task.yml path
  let evalDir: string;
  let taskFile: string;

  if (evalName.endsWith("task.yml") || evalName.endsWith(".yml") || evalName.endsWith(".yaml")) {
    // Direct path to task file
    taskFile = path.isAbsolute(evalName) ? evalName : path.join(dirname, evalName);
    evalDir = path.dirname(taskFile);
  } else {
    // Directory path (original behavior)
    evalDir = path.join(dirname, evalName);
    taskFile = path.join(evalDir, "task.yml");
  }

  return {
    evalName,
    evalDir,
    taskFile,
  };
}