11from logging import getLogger
22from typing import Optional
3+
4+ import yaml
35from resotolib .args import Namespace , ArgumentParser
46from resotolib .logger import setup_logger
57from sqlalchemy import create_engine
68from sqlalchemy .engine import Engine
79
10+ from cloud2sql import __version__
811from cloud2sql .analytics import PosthogEventSender , NoEventSender , AnalyticsEventSender
9- from cloud2sql .collect_plugins import collect_from_plugins , configure
12+ from cloud2sql .collect_plugins import collect_from_plugins , configure , default_config
1013from cloud2sql .util import db_string_from_config , check_parquet_driver
1114
1215# Will fail in case snowflake is not installed - which is fine.
2124def parse_args () -> Namespace :
2225 parser = ArgumentParser (
2326 description = "Collect data from cloud providers and store it in a database" ,
24- epilog = "Synchronizes cloud data to a database" ,
27+ epilog = "Synchronizes cloud data to a database. Visit https://cloud2sql.com for more information. " ,
2528 env_args_prefix = "CLOUD2SQL_" ,
2629 )
2730 parser .add_argument ("--debug" , action = "store_true" , help = "Enable debug logging" )
28- parser .add_argument ("--config" , help = "Path to config file" , required = True )
31+ parser .add_argument ("--config" , help = "Path to config file" )
2932 parser .add_argument (
3033 "--show" ,
3134 choices = ["progress" , "log" , "none" ],
@@ -36,9 +39,29 @@ def parse_args() -> Namespace:
3639 "--analytics-opt-out" ,
3740 default = False ,
3841 action = "store_true" ,
39- help = "Do not send anonimized analytics data" ,
42+ help = "Do not send anonymized analytics data" ,
43+ )
44+ parser .add_argument (
45+ "--version" ,
46+ default = False ,
47+ action = "store_true" ,
48+ help = "Print version and exit" ,
49+ )
50+ parser .add_argument (
51+ "--create-config" ,
52+ action = "store_true" ,
53+ help = "Print empty configuration and exit. Use this to create your own config file." ,
4054 )
4155 args = parser .parse_args ()
56+ if args .version :
57+ print (f"Cloud2SQL Version { __version__ } " )
58+ exit (0 )
59+ elif args .create_config :
60+ cfg = {"sources" : default_config (), "destinations" : {"sqlite" : {"database" : "cloud2sql.db" }}}
61+ print (yaml .safe_dump (cfg , sort_keys = False ))
62+ exit (0 )
63+ elif not args .config :
64+ parser .error ("The following arguments are required: --config" )
4265 args .log_level = "CRITICAL" if args .show != "log" else "DEBUG" if args .debug else "INFO"
4366 return args # type: ignore
4467
@@ -59,7 +82,7 @@ def main() -> None:
5982 sender = NoEventSender () if args .analytics_opt_out else PosthogEventSender ()
6083 config = configure (args .config )
6184 engine = None
62- if config ["destinations" ].keys () & set ([ "file" , "s3" , "gcs" ]) :
85+ if config ["destinations" ].keys () & { "file" , "s3" , "gcs" } :
6386 check_parquet_driver ()
6487 else :
6588 engine = create_engine (db_string_from_config (config ))
0 commit comments