Skip to content

Commit

Permalink
feat: token, port parameters (#44)
Browse files Browse the repository at this point in the history
* feat: token, port parameters

* pr comments
  • Loading branch information
zlalvani authored Apr 28, 2024
1 parent 480570e commit 1a404f8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
12 changes: 8 additions & 4 deletions apps/cli/src/app.tsx → apps/cli/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import Spinner from "ink-spinner";
import { omit } from "radash";
import stripAnsi from "strip-ansi";

import { Sidebar } from "./components/sidebar";
import { Sidebar } from "./components/Sidebar";
import { TitleText } from "./components/TitleText";
import { useStdoutDimensions } from "./use-stdout-dimensions";
import { useStdoutDimensions } from "./hooks/use-stdout-dimensions";

const getLatestPlanGraph = (events: SerializeableBumpgenEvent[]) => {
const planGraphs = events
Expand Down Expand Up @@ -182,10 +182,12 @@ const App = (props: {
language: SupportedLanguage;
pkg: string;
version: string;
port: number;
token?: string;
}) => {
const { exit } = useApp();

const { model, language, pkg, version } = props;
const { model, language, pkg, version, token, port } = props;

const [columns, rows] = useStdoutDimensions();

Expand Down Expand Up @@ -245,11 +247,13 @@ const App = (props: {
pkg,
version,
"-i",
"3000",
"-l",
language,
"-m",
model,
"-p",
port.toString(),
...(token ? ["-t", token] : []),
],
{
shell: true,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import spinners from "cli-spinners";
import { Box, measureElement, Text } from "ink";
import ms from "ms";

import { Bold } from "../common/bold";
import { useStdoutDimensions } from "../use-stdout-dimensions";
import { useStdoutDimensions } from "../hooks/use-stdout-dimensions";
import { Bold } from "./Bold";
import { Task } from "./task-list";

const ExecutionHistory = (props: {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/components/TitleText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useRef, useState } from "react";
import { Box, measureElement, Text } from "ink";
import BigText from "ink-big-text";

import { useStdoutDimensions } from "../use-stdout-dimensions";
import { useStdoutDimensions } from "../hooks/use-stdout-dimensions";

export const TitleText = (
props: Omit<BoxProps, "flexDirection" | "alignItems" | "justifyContent"> & {
Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 23 additions & 6 deletions apps/cli/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SupportedModels,
} from "@xeol/bumpgen-core";

import App from "./app";
import App from "./App";

const command = program
.name("bumpgen")
Expand All @@ -30,11 +30,21 @@ const command = program
.choices(SupportedModels)
.default("gpt-4-turbo-preview" as const),
)
.option(
"-t, --token <token>",
"LLM token (can also be set via the LLM_API_KEY environment variable)",
)
.option(
"-p, --port <port>",
"port to run the IPC server on (default: 3000)",
parseInt,
3000,
)
.option("-s, --simple", "simple mode")
.option("-i, --ipc <port>", "run in ipc mode", parseInt)
.option("-i, --ipc", "run in ipc mode")
.parse();

const { model, language, ipc, simple } = command.opts();
const { model, language, port, ipc, simple, token } = command.opts();

let [pkg, version] = command.processedArgs;

Expand Down Expand Up @@ -79,7 +89,7 @@ if (!pkg) {
}

const bumpgen = makeBumpgen({
llmApiKey: process.env.LLM_API_KEY ?? "",
llmApiKey: token ?? process.env.LLM_API_KEY ?? "",
model,
packageToUpgrade: {
packageName: pkg,
Expand All @@ -106,7 +116,7 @@ if (simple) {
},
body: JSON.stringify(event),
};
await fetch(`http://localhost:${ipc}/data`, options);
await fetch(`http://localhost:${port}/data`, options);
} catch (error) {
console.log("error", serializeError(error));
process.exit(1);
Expand All @@ -117,7 +127,14 @@ if (simple) {
}
} else {
const app = render(
<App model={model} language={language} pkg={pkg} version={version} />,
<App
model={model}
language={language}
pkg={pkg}
version={version}
token={token}
port={port}
/>,
);
await app.waitUntilExit();
}

0 comments on commit 1a404f8

Please sign in to comment.