#
# Copyright (c) 2021 Software AG, Darmstadt, Germany and/or its licensors
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""server command"""

import click

from .. import options
from .core import ProxyContext


@click.command()
@options.common_options
@click.pass_context
def server(
    ctx,
    *_args,
    **kwargs,
):
    """Start local proxy in server mode

    \b
        DEVICE is the device's external identity

    Once the local proxy has started, clients such as ssh and scp can be used
    to establish a connection to the device.

    \b
    Example 1: Start the local proxy, prompt for credentials (if not set via env variables)

        \b
        c8ylp server device01 --host https://example.c8y.io

    Example 2: Start the local proxy using environment file

        \b
        c8ylp server --env-file .env device01

    Example 3: Start the local proxy with randomized port

        \b
        c8ylp server --env-file .env --port 0 device01
    """
    proxy = ProxyContext(ctx, kwargs)
    proxy.start()
