Skip to content

Commit

Permalink
update to not use colon commands
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 18, 2024
1 parent f52184c commit 764aa01
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 69 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ npm install -g freerouting
Before using the CLI, you need to configure your profile ID. The easiest way is to generate a new one:

```bash
freerouting config:create-profile
freerouting config create-profile
```

Alternatively, you can set a specific UUID as your profile ID:

```bash
freerouting config:set-profile <uuid>
freerouting config set-profile <uuid>
```

You can also optionally set a custom API base URL (defaults to https://api.freerouting.app):

```bash
freerouting config:set-api-url <api-url>
freerouting config set-api-url <api-url>
```

## Usage
Expand All @@ -40,49 +40,53 @@ The CLI follows a typical workflow for PCB autorouting:

```bash
# Create a new session
freerouting session:create
freerouting session create

# Create a new job in the session
freerouting job:create --name "my-board"
freerouting job create --name "my-board"

# Upload your DSN file
freerouting job:upload --file my-board.dsn
freerouting job upload --file my-board.dsn

# Start the routing process
freerouting job:start
freerouting job start

# Get the routed output (saves to the same filename by default)
freerouting job:output
freerouting job output
```

### Available Commands

#### Session Management
- `session:create` - Create a new routing session
- `session:list` - List all your sessions
- `session:get [sessionId]` - Get details of a specific session

- `session create` - Create a new routing session
- `session list` - List all your sessions
- `session get [sessionId]` - Get details of a specific session

#### Job Management
- `job:create` - Create a new routing job

- `job create` - Create a new routing job
- Options:
- `-s, --session-id <sessionId>` - Session ID (uses last session by default)
- `-n, --name <name>` - Job name (default: "untitled")
- `-p, --priority <priority>` - Job priority (default: "NORMAL")
- `job:list <sessionId>` - List all jobs in a session
- `job:get <jobId>` - Get details of a specific job
- `job:upload` - Upload a design file
- `job list <sessionId>` - List all jobs in a session
- `job get <jobId>` - Get details of a specific job
- `job upload` - Upload a design file
- Required: `-f, --file <file>` - Path to your DSN file
- Optional: `-j, --job-id <jobId>` - Job ID (uses last job by default)
- `job:start [jobId]` - Start the routing process
- `job:output [jobId]` - Get the routed output
- `job start [jobId]` - Start the routing process
- `job output [jobId]` - Get the routed output
- Optional: `-o, --output <file>` - Custom output file path

#### System Commands
- `system:status` - Check the API system status

- `system status` - Check the API system status

#### Configuration
- `config:set-profile <profileId>` - Set your profile ID
- `config:set-api-url <apiBaseUrl>` - Set custom API base URL

- `config set-profile <profileId>` - Set your profile ID
- `config set-api-url <apiBaseUrl>` - Set custom API base URL

## Acknowledgements

Expand Down
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"style": {
"noUselessElse": "off",
"noParameterAssign": "off",
"noNonNullAssertion": "off",
"useNumberNamespace": "off",
"useFilenamingConvention": {
Expand Down
125 changes: 76 additions & 49 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const API_BASE = commonOptions.apiBaseUrl
const getHeaders = (needsAuth = true) => {
if (!commonOptions.profileId && needsAuth) {
console.error(
'Profile ID is not set, use --profile-id, do "freerouting config:set-profile" or set FREEROUTING_PROFILE_ID environment variable',
'Profile ID is not set, use --profile-id, do "freerouting config set-profile" or set FREEROUTING_PROFILE_ID environment variable',
)
process.exit(1)
}
Expand All @@ -73,8 +73,12 @@ const getHeaders = (needsAuth = true) => {
}

// Session commands
program
.command("session:create")
const sessionCommand = new Command("session")
.alias("sessions")
.description("Manage routing sessions")

sessionCommand
.command("create")
.description("Create a new routing session")
.action(async () => {
const response = await axios.post(`${API_BASE}/v1/sessions/create`, "", {
Expand All @@ -84,36 +88,8 @@ program
console.log(response.data)
})

// Config commands
program
.command("config:set-profile")
.description("Set the Freerouting Profile ID")
.argument("<profileId>", "Profile ID to set")
.action(async (profileId: string) => {
config.set("profileId", profileId)
console.log(`Profile ID set to: ${profileId}`)
})

program
.command("config:set-api-url")
.description("Set the Freerouting API Base URL")
.argument("<apiBaseUrl>", "API Base URL to set")
.action(async (apiBaseUrl: string) => {
config.set("apiBaseUrl", apiBaseUrl)
console.log(`API Base URL set to: ${apiBaseUrl}`)
})

program
.command("config:create-profile")
.description("Generate and set a new random UUID v4 as the Profile ID")
.action(async () => {
const profileId = randomUUID()
config.set("profileId", profileId)
console.log(`New Profile ID generated and set to: ${profileId}`)
})

program
.command("session:list")
sessionCommand
.command("list")
.description("List all sessions")
.action(async () => {
const response = await axios.get(`${API_BASE}/v1/sessions/list`, {
Expand All @@ -122,8 +98,8 @@ program
console.log(response.data)
})

program
.command("session:get [sessionId]")
sessionCommand
.command("get [sessionId]")
.description("Get session details")
.action(async (sessionId: string) => {
sessionId ??= config.get("lastSessionId")
Expand All @@ -139,9 +115,45 @@ program
console.log(response.data)
})

// Config commands
const configCommand = new Command("config").description(
"Manage configuration settings",
)

configCommand
.command("set-profile")
.description("Set the Freerouting Profile ID")
.argument("<profileId>", "Profile ID to set")
.action(async (profileId: string) => {
config.set("profileId", profileId)
console.log(`Profile ID set to: ${profileId}`)
})

configCommand
.command("set-api-url")
.description("Set the Freerouting API Base URL")
.argument("<apiBaseUrl>", "API Base URL to set")
.action(async (apiBaseUrl: string) => {
config.set("apiBaseUrl", apiBaseUrl)
console.log(`API Base URL set to: ${apiBaseUrl}`)
})

configCommand
.command("create-profile")
.description("Generate and set a new random UUID v4 as the Profile ID")
.action(async () => {
const profileId = randomUUID()
config.set("profileId", profileId)
console.log(`New Profile ID generated and set to: ${profileId}`)
})

// Job commands
program
.command("job:create")
const jobCommand = new Command("job")
.alias("jobs")
.description("Manage routing jobs")

jobCommand
.command("create")
.description("Create a new routing job")
.option(
"-s, --session-id <sessionId>",
Expand All @@ -164,9 +176,10 @@ program
console.log(response.data)
})

program
.command("job:list <sessionId>")
jobCommand
.command("list")
.description("List jobs for a session")
.argument("<sessionId>", "Session ID")
.action(async (sessionId: string) => {
sessionId ??= config.get("lastSessionId")
const response = await axios.get(`${API_BASE}/v1/jobs/list/${sessionId}`, {
Expand All @@ -175,9 +188,10 @@ program
console.log(response.data)
})

program
.command("job:get <jobId>")
jobCommand
.command("get")
.description("Get job details")
.argument("[jobId]", "Job ID")
.action(async (jobId: string) => {
jobId ??= config.get("lastJobId")
const response = await axios.get(`${API_BASE}/v1/jobs/${jobId}`, {
Expand All @@ -186,8 +200,8 @@ program
console.log(response.data)
})

program
.command("job:upload")
jobCommand
.command("upload")
.description("Upload design file for a job")
.option("-j, --job-id <jobId>", "Job ID", config.get("lastJobId"))
.requiredOption("-f, --file <file>", "Design file path")
Expand All @@ -209,9 +223,10 @@ program
console.log(response.data)
})

program
.command("job:start [jobId]")
jobCommand
.command("start")
.description("Start a routing job")
.argument("[jobId]", "Job ID")
.action(async (jobId: string) => {
jobId ??= config.get("lastJobId")
if (!jobId) {
Expand All @@ -224,9 +239,10 @@ program
console.log(response.data)
})

program
.command("job:output [jobId]")
jobCommand
.command("output")
.description("Get job output")
.argument("[jobId]", "Job ID")
.option("-o, --output <file>", "Output file path")
.action(async (jobId: string, opts: any) => {
jobId ??= config.get("lastJobId")
Expand Down Expand Up @@ -254,12 +270,23 @@ program
})

// System commands
program
.command("system:status")
const systemCommand = new Command("system").description(
"Manage system operations",
)

systemCommand
.command("status")
.description("Get system status")
.action(async () => {
const response = await axios.get(`${API_BASE}/v1/system/status`)
console.log(response.data)
})

// Add all command groups to the main program
program
.addCommand(sessionCommand)
.addCommand(configCommand)
.addCommand(jobCommand)
.addCommand(systemCommand)

program.parse(process.argv)

0 comments on commit 764aa01

Please sign in to comment.