filecoin-pin
Version:
Bridge IPFS content to Filecoin Onchain Cloud using familiar tools
60 lines (54 loc) • 2.42 kB
text/typescript
import { Command } from 'commander'
import { runDataSetDetailsCommand, runDataSetListCommand } from '../data-set/run.js'
import type { DataSetCommandOptions, DataSetListCommandOptions } from '../data-set/types.js'
import { addAuthOptions, addProviderOptions } from '../utils/cli-options.js'
import { addMetadataOptions, resolveMetadataOptions } from '../utils/cli-options-metadata.js'
export const dataSetCommand = new Command('data-set')
.alias('dataset')
.description('Inspect data sets managed through Filecoin Onchain Cloud')
export const dataSetShowCommand = new Command('show')
.description('Display detailed information about a data set')
.argument('<dataSetId>', 'Display detailed information about a data set')
.action(async (dataSetId: string, options) => {
try {
const commandOptions: DataSetCommandOptions = {
...options,
}
const dataSetIdNumber = Number.parseInt(dataSetId, 10)
if (Number.isNaN(dataSetIdNumber)) {
throw new Error('Invalid data set ID')
}
await runDataSetDetailsCommand(dataSetIdNumber, commandOptions)
} catch (error) {
console.error('Data set command failed:', error instanceof Error ? error.message : error)
process.exit(1)
}
})
addAuthOptions(dataSetShowCommand)
export const dataSetListCommand = new Command('list')
.alias('ls')
.description('List all data sets for the configured account')
.option('--all', 'Show all data sets, not just the ones created with filecoin-pin', false)
.action(async (options) => {
try {
const {
dataSetMetadata: _dataSetMetadata,
datasetMetadata: _datasetMetadata,
...dataSetListOptionsFromCli
} = options
const { dataSetMetadata } = resolveMetadataOptions(options)
const normalizedOptions: DataSetListCommandOptions = {
...dataSetListOptionsFromCli,
...(dataSetMetadata ? { dataSetMetadata } : {}),
}
await runDataSetListCommand(normalizedOptions)
} catch (error) {
console.error('Data set list command failed:', error instanceof Error ? error.message : error)
process.exit(1)
}
})
addAuthOptions(dataSetListCommand)
addProviderOptions(dataSetListCommand)
addMetadataOptions(dataSetListCommand, { includePieceMetadata: false, includeDataSetMetadata: true })
dataSetCommand.addCommand(dataSetShowCommand)
dataSetCommand.addCommand(dataSetListCommand)