-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09a153b
commit a26597d
Showing
4 changed files
with
36 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { OptionValues } from 'commander' | ||
import { readFileSync } from 'fs' | ||
|
||
interface Config { | ||
wallet_password: string | ||
wallet_path: string | ||
node_url: string | ||
chunk_size: number | ||
secret_key: string | ||
} | ||
|
||
export function parseConfigFile(filePath: string): Config { | ||
const fileContent = readFileSync(filePath, 'utf-8') | ||
try { | ||
return JSON.parse(fileContent) | ||
} catch (error) { | ||
throw new Error(`Failed to parse file: ${error}`) | ||
} | ||
} | ||
|
||
export function mergeConfigAndOptions( | ||
commandOptions: OptionValues, | ||
configOptions: Config | ||
): OptionValues { | ||
if (!configOptions) return commandOptions | ||
|
||
const wallet = commandOptions.wallet || configOptions.wallet_path | ||
const password = commandOptions.password || configOptions.wallet_password | ||
const node_url = commandOptions.node_url || configOptions.node_url | ||
const chunk_size = commandOptions.chunk_size || configOptions.chunk_size | ||
|
||
return { wallet, password, node_url, chunk_size } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters