Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge c766dc7 into 6ca181c
Browse files Browse the repository at this point in the history
  • Loading branch information
fainashalts committed Mar 30, 2021
2 parents 6ca181c + c766dc7 commit f5a8ce9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/db-kit/src/cli/App.tsx
Expand Up @@ -12,17 +12,19 @@ import { Menu } from "./menu";

export interface Props {
network?: Pick<Resources.Resource<"networks">, "name">;
configPath?: string;
}

export const App = ({
network = {
name: "development"
}
},
configPath
}: Props) => {
const { exit } = useApp();
const [shouldQuit, setShouldQuit] = useState<boolean>(false);

const config = useConfig({ network });
const config = useConfig({ network, configPath });
const { db, project, error } = useDb({ config });

useEffect(() => {
Expand Down Expand Up @@ -54,8 +56,10 @@ export const App = ({
{" Reading truffle-config and connecting to network..."}
</Text>
)}
{error &&
error instanceof DbNotEnabledError && <ActivationInstructions /> // specific error case
{
error && error instanceof DbNotEnabledError && (
<ActivationInstructions />
) // specific error case
}
{error &&
!(error instanceof DbNotEnabledError) && ( // unknown error case
Expand Down
8 changes: 6 additions & 2 deletions packages/db-kit/src/cli/hooks/useConfig.ts
Expand Up @@ -6,14 +6,18 @@ import type { Resources } from "@truffle/db";

export interface UseConfigOptions {
network: Pick<Resources.Resource<"networks">, "name">;
configPath?: string;
}

export function useConfig({ network: { name } }) {
export function useConfig({ network: { name }, configPath }) {
const [config, setConfig] = useState<TruffleConfig | undefined>(undefined);

useEffect(() => {
setImmediate(() => {
const config = TruffleConfig.detect({ network: name });
const config = TruffleConfig.detect({
network: name,
config: configPath
});

Environment.detect(config).then(() => setConfig(config));
});
Expand Down
9 changes: 7 additions & 2 deletions packages/db-kit/src/cli/index.ts
Expand Up @@ -11,24 +11,29 @@ const cli = meow(
Options
--network Name of network to connect to
--config Path to configuration file
`,
{
flags: {
network: {
type: "string"
},
config: {
type: "string"
}
}
}
);

export async function start() {
const { network: name } = cli.flags;
const { network: name, config: configPath } = cli.flags;

const { waitUntilExit } = render(
React.createElement(App, {
network: {
name
}
},
configPath
})
);

Expand Down

0 comments on commit f5a8ce9

Please sign in to comment.