Skip to content

Commit a8f2293

Browse files
committed
PR feedback
1 parent 36e09e5 commit a8f2293

6 files changed

Lines changed: 33 additions & 53 deletions

File tree

docs/reference/cli.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ Options:
431431
only they will be expanded as raw queries.
432432
--dialect TEXT The SQL dialect to render the query as.
433433
--no-format Disable fancy formatting of the query.
434-
--no-rewrite-casts Preserve the existing casts, without rewriting
435-
them to use the :: syntax.
436-
--append-newline Include a newline at the end of each file.
437434
--max-text-width INTEGER The max number of characters in a segment before
438435
creating new lines in pretty mode.
439436
--leading-comma Determines whether or not the comma is leading

docs/reference/notebook.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ options:
223223
models are expanded as raw queries.
224224
--dialect DIALECT SQL dialect to render.
225225
--no-format Disable fancy formatting of the query.
226-
--no-rewrite-casts Preserve the existing casts, without rewriting them
227-
to use the :: syntax.
228-
--append-newline Include a newline at the end of the output.
229226
--normalize Whether or not to normalize identifiers to lowercase.
230227
--pad PAD Determines the pad size in a formatted string.
231228
--indent INDENT Determines the indentation size in a formatted string.

sqlmesh/cli/main.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,16 @@ def render(
215215
expand=expand,
216216
)
217217

218-
format_options = {}
219-
if format_kwargs.get("no_rewrite_casts"):
220-
format_options["rewrite_casts"] = False
221-
format_kwargs.pop("no_rewrite_casts")
222-
223-
format_options.update({k: v for k, v in format_kwargs.items() if v is not None})
224-
225218
format_config = ctx.obj.config_for_node(model).format
226-
format_options = {**format_config.generator_options, **format_options}
219+
format_kwargs = {
220+
**format_config.generator_options,
221+
**{k: v for k, v in format_kwargs.items() if v is not None},
222+
}
227223

228224
sql = rendered.sql(
229225
pretty=True,
230226
dialect=ctx.obj.config.dialect if dialect is None else dialect,
231-
**format_options,
227+
**format_kwargs,
232228
)
233229
if no_format:
234230
print(sql)
@@ -285,6 +281,17 @@ def evaluate(
285281
help="Whether or not to check formatting (but not actually format anything).",
286282
default=None,
287283
)
284+
@click.option(
285+
"--rewrite-casts/--no-rewrite-casts",
286+
is_flag=True,
287+
help="Rewrite casts to use the :: syntax.",
288+
default=None,
289+
)
290+
@click.option(
291+
"--append-newline",
292+
is_flag=True,
293+
help="Include a newline at the end of each file.",
294+
)
288295
@opt.format_options
289296
@click.pass_context
290297
@error_handler
@@ -293,9 +300,6 @@ def format(
293300
ctx: click.Context, paths: t.Optional[t.Tuple[str, ...]] = None, **kwargs: t.Any
294301
) -> None:
295302
"""Format all SQL models and audits."""
296-
if kwargs.pop("no_rewrite_casts", None):
297-
kwargs["rewrite_casts"] = False
298-
299303
if not ctx.obj.format(**{k: v for k, v in kwargs.items() if v is not None}, paths=paths):
300304
ctx.exit(1)
301305

sqlmesh/cli/options.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def format_options(func: t.Callable) -> t.Callable:
6363
"--normalize",
6464
is_flag=True,
6565
help="Whether or not to normalize identifiers to lowercase.",
66-
default=None,
6766
)(func)
6867
func = click.option(
6968
"--pad",
@@ -84,23 +83,10 @@ def format_options(func: t.Callable) -> t.Callable:
8483
"--leading-comma",
8584
is_flag=True,
8685
help="Determines whether or not the comma is leading or trailing in select expressions. Default is trailing.",
87-
default=None,
8886
)(func)
8987
func = click.option(
9088
"--max-text-width",
9189
type=int,
9290
help="The max number of characters in a segment before creating new lines in pretty mode.",
9391
)(func)
94-
func = click.option(
95-
"--append-newline",
96-
is_flag=True,
97-
help="Include a newline at the end of each file.",
98-
default=None,
99-
)(func)
100-
func = click.option(
101-
"--no-rewrite-casts",
102-
is_flag=True,
103-
help="Preserve the existing casts, without rewriting them to use the :: syntax.",
104-
default=None,
105-
)(func)
10692
return func

sqlmesh/magics.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,6 @@ def format_arguments(func: t.Callable) -> t.Callable:
127127
type=int,
128128
help="The max number of characters in a segment before creating new lines in pretty mode.",
129129
)(func)
130-
func = argument(
131-
"--append-newline",
132-
action="store_true",
133-
help="Include a newline at the end of the output.",
134-
default=None,
135-
)(func)
136-
func = argument(
137-
"--no-rewrite-casts",
138-
action="store_true",
139-
help="Preserve the existing casts, without rewriting them to use the :: syntax.",
140-
default=None,
141-
)(func)
142130
return func
143131

144132

@@ -648,15 +636,11 @@ def render(self, context: Context, line: str) -> None:
648636

649637
no_format = render_opts.pop("no_format", False)
650638

651-
format_options = {}
652-
if render_opts.get("no_rewrite_casts"):
653-
format_options["rewrite_casts"] = False
654-
render_opts.pop("no_rewrite_casts")
655-
656-
format_options.update({k: v for k, v in render_opts.items() if v is not None})
657-
658639
format_config = context.config_for_node(model).format
659-
format_options = {**format_config.generator_options, **format_options}
640+
format_options = {
641+
**format_config.generator_options,
642+
**{k: v for k, v in render_opts.items() if v is not None},
643+
}
660644

661645
sql = query.sql(
662646
pretty=True,
@@ -927,6 +911,18 @@ def rewrite(self, context: Context, line: str, sql: str) -> None:
927911
help="Whether or not to check formatting (but not actually format anything).",
928912
default=None,
929913
)
914+
@argument(
915+
"--append-newline",
916+
action="store_true",
917+
help="Include a newline at the end of the output.",
918+
default=None,
919+
)
920+
@argument(
921+
"--no-rewrite-casts",
922+
action="store_true",
923+
help="Preserve the existing casts, without rewriting them to use the :: syntax.",
924+
default=None,
925+
)
930926
@format_arguments
931927
@line_magic
932928
@pass_sqlmesh_context

tests/core/test_dialect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def test_format_model_expressions():
207207
parse(
208208
"""
209209
MODEL(name foo);
210-
SELECT 1::INT AS bla
210+
SELECT CAST(1 AS INT) AS bla
211211
"""
212212
),
213213
rewrite_casts=False,

0 commit comments

Comments
 (0)