old_contents: """Simple echo server."""
  
  from functools import partial
  import logging
  
  import curio
  
  from garage import cli
  from garage import components
  from garage.asyncs.utils import make_server_socket, serve
  from garage.startups.asyncs.servers import (
      GracefulExitComponent,
      ServerContainerComponent,
  )
  
  
  LOG = logging.getLogger(__name__)
  
  
  class ServerComponent(components.Component):
  
      require = (components.ARGS, GracefulExitComponent.provide.graceful_exit)
  
      provide = ServerContainerComponent.require.make_server
  
      def add_arguments(self, parser):
          group = parser.add_argument_group(__name__)
          group.add_argument(
              '--port', default=25000, type=int,
              help="""set port (default to %(default)s)""")
  
      def make(self, require):
          return partial(
              serve,
              require.graceful_exit,
              partial(make_server_socket, ('', require.args.port)),
              handle,
              logger=LOG,
          )
  
  
  async def handle(client_sock, client_addr):
      async with client_sock:
          stream = client_sock.as_stream()
          async for line in stream:
              await stream.write(line)
      LOG.info('close connection to: %s', client_addr)
  
  
  @cli.command('echo-server')
  @cli.component(ServerContainerComponent)
  @cli.component(ServerComponent)
  def main(serve: ServerContainerComponent.provide.serve):
      return 0 if curio.run(serve()) else 1
  
  
  if __name__ == '__main__':
      main()
  
new_contents: """Simple TCP echo server."""
  
  import functools
  import logging
  
  import curio
  
  from garage import apps
  from garage import parameters
  from garage import parts
  from garage.asyncs import utils
  from garage.partdefs.asyncs import servers
  
  
  LOG = logging.getLogger(__name__)
  
  
  PARAMS = parameters.get(__name__)
  PARAMS.port = parameters.define(25000, 'set port')
  
  
  @parts.register_maker
  def make_server(
          graceful_exit: servers.PARTS.graceful_exit) -> servers.PARTS.server:
      return utils.serve(
          graceful_exit,
          functools.partial(utils.make_server_socket, ('', PARAMS.port.get())),
          handle,
          logger=LOG,
      )
  
  
  async def handle(client_sock, client_addr):
      async with client_sock:
          stream = client_sock.as_stream()
          async for line in stream:
              await stream.write(line)
      LOG.info('close connection to: %s', client_addr)
  
  
  @apps.with_prog('echo-server')
  @apps.with_selected_makers({servers.PARTS.server: all})
  @apps.using_parts(serve=servers.PARTS.serve)
  def main(_, serve):
      return 0 if curio.run(serve()) else 1
  
  
  if __name__ == '__main__':
      apps.run(main)
  
subject: Rewrite examples/asyncs/echo_server.py under new apps framework