Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LITE-28258: list and export streams #220

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions connect/cli/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def validate_output_options(output_path, output_file, default_dir_name, default_

output_file = os.path.join(output_path, output_file or f'{default_file_name}.xlsx')

if os.path.exists(output_file):
console.confirm(
f'Are you sure you want to override the file {output_file} ?',
abort=True,
)
console.echo('')

return output_file


Expand Down
106 changes: 106 additions & 0 deletions connect/cli/plugins/commerce/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-

# This file is part of the Ingram Micro Cloud Blue Connect connect-cli.
# Copyright (c) 2023 Ingram Micro. All Rights Reserved.

import click
from connect.client import R

from connect.cli.core import group
from connect.cli.core.config import pass_config
from connect.cli.core.terminal import console
from connect.cli.plugins.commerce.utils import (
display_streams_table,
export_stream,
)


@group(name='commerce', short_help='Manage commerce definitions.')
def grp_commerce():
pass # pragma: no cover


@grp_commerce.group(
name='stream',
short_help='Manage commerce streams.',
)
def grp_commerce_streams():
pass # pragma: no cover


@grp_commerce_streams.command(
name='list',
short_help='List commerce billing and pricing streams.',
)
@click.option(
'--query',
'-q',
'query',
help='RQL query expression.',
)
@pass_config
def cmd_list_streams(config, query):
query = query or R()
display_streams_table(
config.active.client.ns(
'billing',
)
.streams.filter(
query,
)
.limit(
console.page_size,
)
.select(
'context',
'sources',
),
config.active.client.ns(
'pricing',
)
.streams.filter(
query,
)
.limit(
console.page_size,
)
.select(
'context',
'sources',
),
config.active.id,
)


@grp_commerce_streams.command(
name='export',
short_help='Export commerce billing or pricing streams.',
)
@click.argument('stream_id', metavar='stream_id', nargs=1, required=True) # noqa: E304
@click.option(
'--out',
'-o',
'output_file',
type=click.Path(exists=False, file_okay=True, dir_okay=False),
help='Output Excel file name.',
)
@click.option(
'--output_path',
'-p',
'output_path',
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help='Directory where to store the export.',
)
@pass_config
def cmd_export_stream(config, stream_id, output_file, output_path):
export_stream(
client=config.active.client,
stream_id=stream_id,
active_account_id=config.active.id,
output_file=output_file,
output_path=output_path,
)


def get_group():
return grp_commerce
Loading