code: def main_cli():
      args = _cli_argument_parser()
      delta_secs = args.delay
      i2cbus = args.bus
      i2c_address = args.address
      sensor_key = args.sensor
      sensor_params = args.params
      params = {}
      if sensor_params:
          def _parse_param(str_param):
              key, value = str_param.split('=')
              try:
                  value = int(value)
              except ValueError:
                  pass
              return {key.strip(): value}
          [params.update(_parse_param(sp)) for sp in sensor_params]
      if sensor_key:
          from time import sleep
          try:
              import smbus
              bus_handler = smbus.SMBus(i2cbus)
          except ImportError as exc:
              print(exc, "\n", "Please install smbus-cffi before.")
              sys.exit(-1)
          try:
              sensor_handler, i2c_default_address = SENSORS[sensor_key]
          except KeyError:
              print("'%s' is not recognized as an implemented i2c sensor."
                    % sensor_key)
              sys.exit(-1)
          if i2c_address:
              i2c_address = hex(int(i2c_address, 0))
          else:
              i2c_address = i2c_default_address
          sensor = sensor_handler(bus_handler, i2c_address, **params)
          try:
              while True:
                  sensor.update()
                  if not sensor.sample_ok:
                      print("An error has occured.")
                      break
                  print(sensor.current_state_str)
                  sleep(delta_secs)
          except KeyboardInterrupt:
              print("Bye!")
      else:
          from subprocess import check_output
          cmd = '/usr/sbin/i2cdetect -y {}'.format(i2cbus)
          try:
              output = check_output(cmd.split())
              print("Running i2cdetect utility in i2c bus {}:\n"
                    "The command '{}' has returned:\n{}"
                    .format(i2cbus, cmd, output.decode()))
          except FileNotFoundError:
              print("Please install i2cdetect before.")
              sys.exit(-1)
          addresses = ['0x' + l for line in output.decode().splitlines()[1:]
                       for l in line.split()[1:] if l != '--']
          if addresses:
              print("{} sensors detected in {}"
                    .format(len(addresses), ', '.join(addresses)))
          else:
              print("No i2c sensors detected.")