import cherrypy
import click
from intercom.roots import IntercomRoot

CLICK_FILE_TYPE = click.Path(exists=True, dir_okay=False)


def run_server(global_config_filename, app_config_filename):
    cherrypy.config.update(global_config_filename)
    cherrypy.quickstart(root=IntercomRoot(), config=app_config_filename)


@click.command()
@click.argument('global_config', type=CLICK_FILE_TYPE)
@click.argument('app_config', type=CLICK_FILE_TYPE)
def main(global_config, app_config):
    run_server(global_config, app_config)


if __name__ == '__main__':
    main()

import cherrypy
import click
from intercom.roots import IntercomRoot
from cherrypy.process.plugins import Daemonizer, PIDFile


def run_server(
        global_config_filename,
        app_config_filename,
        daemon_pid_filename=None):
    if daemon_pid_filename is not None:
        Daemonizer(cherrypy.engine).subscribe()
        PIDFile(cherrypy.engine, daemon_pid_filename).subscribe()

    cherrypy.config.update(global_config_filename)
    cherrypy.quickstart(root=IntercomRoot(), config=app_config_filename)


@click.command()
@click.argument('global-config', type=click.Path(exists=True, dir_okay=False))
@click.argument('app-config', type=click.Path(exists=True, dir_okay=False))
@click.option('--daemon-pid-file', type=click.Path(dir_okay=False))
def main(global_config, app_config, daemon_pid_file):
    run_server(global_config, app_config, daemon_pid_file)


if __name__ == '__main__':
    main()

Add support for daemon mode.
Add support for daemon mode.

  import cherrypy
  import click
  from intercom.roots import IntercomRoot
+ from cherrypy.process.plugins import Daemonizer, PIDFile
- 
- CLICK_FILE_TYPE = click.Path(exists=True, dir_okay=False)
  
  
- def run_server(global_config_filename, app_config_filename):
+ def run_server(
+         global_config_filename,
+         app_config_filename,
+         daemon_pid_filename=None):
+     if daemon_pid_filename is not None:
+         Daemonizer(cherrypy.engine).subscribe()
+         PIDFile(cherrypy.engine, daemon_pid_filename).subscribe()
+ 
      cherrypy.config.update(global_config_filename)
      cherrypy.quickstart(root=IntercomRoot(), config=app_config_filename)
  
  
  @click.command()
- @click.argument('global_config', type=CLICK_FILE_TYPE)
- @click.argument('app_config', type=CLICK_FILE_TYPE)
+ @click.argument('global-config', type=click.Path(exists=True, dir_okay=False))
+ @click.argument('app-config', type=click.Path(exists=True, dir_okay=False))
+ @click.option('--daemon-pid-file', type=click.Path(dir_okay=False))
- def main(global_config, app_config):
+ def main(global_config, app_config, daemon_pid_file):
-     run_server(global_config, app_config)
+     run_server(global_config, app_config, daemon_pid_file)
  
  
  if __name__ == '__main__':
      main()
  
Add support for daemon mode.
## Code Before:
import cherrypy
import click
from intercom.roots import IntercomRoot

CLICK_FILE_TYPE = click.Path(exists=True, dir_okay=False)


def run_server(global_config_filename, app_config_filename):
    cherrypy.config.update(global_config_filename)
    cherrypy.quickstart(root=IntercomRoot(), config=app_config_filename)


@click.command()
@click.argument('global_config', type=CLICK_FILE_TYPE)
@click.argument('app_config', type=CLICK_FILE_TYPE)
def main(global_config, app_config):
    run_server(global_config, app_config)


if __name__ == '__main__':
    main()

## Instruction:
Add support for daemon mode.
## Code After:
import cherrypy
import click
from intercom.roots import IntercomRoot
from cherrypy.process.plugins import Daemonizer, PIDFile


def run_server(
        global_config_filename,
        app_config_filename,
        daemon_pid_filename=None):
    if daemon_pid_filename is not None:
        Daemonizer(cherrypy.engine).subscribe()
        PIDFile(cherrypy.engine, daemon_pid_filename).subscribe()

    cherrypy.config.update(global_config_filename)
    cherrypy.quickstart(root=IntercomRoot(), config=app_config_filename)


@click.command()
@click.argument('global-config', type=click.Path(exists=True, dir_okay=False))
@click.argument('app-config', type=click.Path(exists=True, dir_okay=False))
@click.option('--daemon-pid-file', type=click.Path(dir_okay=False))
def main(global_config, app_config, daemon_pid_file):
    run_server(global_config, app_config, daemon_pid_file)


if __name__ == '__main__':
    main()
