Skip to content

Commit

Permalink
Merge branch 'naynay/file-restructure' into naynay/faucet-restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Sep 23, 2024
2 parents d668598 + fa335b4 commit 3a9fb9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const program = new Command()
/* no command */
program
.name('entropy')
.description('CLI interface for interacting with entropy.xyz. Running without commands starts an interactive ui')
.description('CLI interface for interacting with entropy.xyz. Running this binary without any commands or arguments starts a text-based interface.')
.addOption(currentAccountAddressOption())
.addOption(endpointOption())
// NOTE: I think this is currently unused
Expand Down
27 changes: 18 additions & 9 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,37 @@ export async function init (configPath = CONFIG_PATH, oldConfigPath = OLD_CONFIG
await set(newConfig, configPath)
}
}
function noop () {}

export async function get (configPath = CONFIG_PATH) {
const configBuffer = await readFile(configPath)

return deserialize(configBuffer.toString())
return readFile(configPath, 'utf-8')
.then(deserialize)
.catch(makeGetErrorHandler(configPath))
}

export function getSync (configPath = CONFIG_PATH): EntropyConfig {
try {
const configBuffer = readFileSync(configPath, 'utf8')
return deserialize(configBuffer)
} catch (err) {
if (err.code !== 'ENOENT') throw err

const newConfig = migrateData(allMigrations, {})
writeFileSync(configPath, serialize(newConfig))
return newConfig
return makeGetErrorHandler(configPath)(err)
}
}

export async function set (config: EntropyConfig, configPath = CONFIG_PATH) {
await mkdirp(dirname(configPath))
await writeFile(configPath, serialize(config))
}

/* util */
function noop () {}

function makeGetErrorHandler (configPath) {
return function getErrorHandler (err) {
if (err.code !== 'ENOENT') throw err

const newConfig = migrateData(allMigrations, {})
mkdirp.sync(dirname(configPath))
writeFileSync(configPath, serialize(newConfig))
return newConfig
}
}

0 comments on commit 3a9fb9a

Please sign in to comment.