Update add-device command. Make "device" a positional argument instead of a kw option
This commit is contained in:
parent
b3f0f7a3ed
commit
da05edb71a
@ -16,13 +16,11 @@ logger = logging.getLogger(__name__)
|
||||
def add_device_guided(ctx, cn, db):
|
||||
click.echo('TODO: Implement')
|
||||
logger.info('Adding device interactively')
|
||||
#logger.debug(f'Parameters: {params}. value: {value}')
|
||||
# logger.debug(f'Parameters: {params}. value: {value}')
|
||||
|
||||
|
||||
@click.command('add-device', help='Add a device to a database')
|
||||
@click.option('--dev', '--device-name', type=str, required=True,
|
||||
help='The name of the device to be added. If this string contains spaces or other special characters \
|
||||
normalization is performed to derive a canonical name')
|
||||
@click.argument('device', type=str, required=True)
|
||||
@click.option('--db', '--database', type=click.Path(exists=True, file_okay=False, dir_okay=True),
|
||||
envvar='IOTTB_DB', show_envvar=True,
|
||||
help='Database in which to add this device. If not specified use default from config.')
|
||||
@ -31,7 +29,9 @@ def add_device_guided(ctx, cn, db):
|
||||
def add_device(dev, db, guided):
|
||||
"""Add a new device to a database
|
||||
|
||||
Device name must be supplied unless in an interactive setup. Database is taken from config by default.
|
||||
Device name must be supplied unless in an interactive setup.
|
||||
Database is taken from config by default.
|
||||
If this device name contains spaces or other special characters normalization is performed to derive a canonical name.
|
||||
"""
|
||||
logger.info('add-device invoked')
|
||||
|
||||
@ -54,9 +54,11 @@ def add_device(dev, db, guided):
|
||||
full_db_path = Path(path) / database
|
||||
if not full_db_path.is_dir():
|
||||
logger.warning(f'No database at {database}')
|
||||
click.echo(f'Could not find a database.')
|
||||
click.echo(f'You need to initialize the testbed before before you add devices!')
|
||||
click.echo(f'To initialize the testbed in the default location run "iottb init-db"')
|
||||
click.echo(f'No database found at {full_db_path}', lvl='w')
|
||||
click.echo(
|
||||
f'You need to initialize the testbed before before you add devices!')
|
||||
click.echo(
|
||||
f'To initialize the testbed in the default location run "iottb init-db"')
|
||||
click.echo('Exiting...')
|
||||
exit()
|
||||
|
||||
@ -83,7 +85,6 @@ def add_device(dev, db, guided):
|
||||
with metadata_path.open('w') as metadata_file:
|
||||
json.dump(device_metadata.__dict__, metadata_file, indent=4)
|
||||
click.echo(f'Successfully added device {dev} to database')
|
||||
logger.debug(f'Added device {dev} to database {database}. Full path of metadata {metadata_path}')
|
||||
logger.debug(f'Added device {dev} to database {
|
||||
database}. Full path of metadata {metadata_path}')
|
||||
logger.info(f'Metadata for {dev} {device_metadata.print_attributes()}')
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user