1
+ import functools
1
2
from copy import copy
2
3
from dataclasses import dataclass
3
4
from typing import Callable , List , Optional , Union
@@ -118,6 +119,44 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
118
119
)
119
120
120
121
122
+ # approach from https://github.com/pallets/click/issues/108#issuecomment-280489786
123
+ def global_flags (func ):
124
+ @p .cache_selected_only
125
+ @p .debug
126
+ @p .deprecated_print
127
+ @p .enable_legacy_logger
128
+ @p .fail_fast
129
+ @p .log_cache_events
130
+ @p .log_file_max_bytes
131
+ @p .log_format_file
132
+ @p .log_level
133
+ @p .log_level_file
134
+ @p .log_path
135
+ @p .macro_debugging
136
+ @p .partial_parse
137
+ @p .partial_parse_file_path
138
+ @p .partial_parse_file_diff
139
+ @p .populate_cache
140
+ @p .print
141
+ @p .printer_width
142
+ @p .quiet
143
+ @p .record_timing_info
144
+ @p .send_anonymous_usage_stats
145
+ @p .single_threaded
146
+ @p .static_parser
147
+ @p .use_colors
148
+ @p .use_colors_file
149
+ @p .use_experimental_parser
150
+ @p .version
151
+ @p .version_check
152
+ @p .write_json
153
+ @functools .wraps (func )
154
+ def wrapper (* args , ** kwargs ):
155
+ return func (* args , ** kwargs )
156
+
157
+ return wrapper
158
+
159
+
121
160
# dbt
122
161
@click .group (
123
162
context_settings = {"help_option_names" : ["-h" , "--help" ]},
@@ -126,38 +165,10 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
126
165
epilog = "Specify one of these sub-commands and you can find more help from there." ,
127
166
)
128
167
@click .pass_context
129
- @p .cache_selected_only
130
- @p .debug
131
- @p .deprecated_print
132
- @p .enable_legacy_logger
133
- @p .fail_fast
134
- @p .log_cache_events
135
- @p .log_file_max_bytes
136
- @p .log_format
137
- @p .log_format_file
138
- @p .log_level
139
- @p .log_level_file
140
- @p .log_path
141
- @p .macro_debugging
142
- @p .partial_parse
143
- @p .partial_parse_file_path
144
- @p .partial_parse_file_diff
145
- @p .populate_cache
146
- @p .print
147
- @p .printer_width
148
- @p .quiet
149
- @p .record_timing_info
150
- @p .send_anonymous_usage_stats
151
- @p .single_threaded
152
- @p .static_parser
153
- @p .use_colors
154
- @p .use_colors_file
155
- @p .use_experimental_parser
156
- @p .version
157
- @p .version_check
168
+ @global_flags
158
169
@p .warn_error
159
170
@p .warn_error_options
160
- @p .write_json
171
+ @p .log_format
161
172
def cli (ctx , ** kwargs ):
162
173
"""An ELT tool for managing your SQL transformations and data models.
163
174
For more documentation on these commands, visit: docs.getdbt.com
@@ -167,10 +178,10 @@ def cli(ctx, **kwargs):
167
178
# dbt build
168
179
@cli .command ("build" )
169
180
@click .pass_context
181
+ @global_flags
170
182
@p .defer
171
183
@p .deprecated_defer
172
184
@p .exclude
173
- @p .fail_fast
174
185
@p .favor_state
175
186
@p .deprecated_favor_state
176
187
@p .full_refresh
@@ -190,7 +201,6 @@ def cli(ctx, **kwargs):
190
201
@p .target_path
191
202
@p .threads
192
203
@p .vars
193
- @p .version_check
194
204
@requires .postflight
195
205
@requires .preflight
196
206
@requires .profile
@@ -213,6 +223,7 @@ def build(ctx, **kwargs):
213
223
# dbt clean
214
224
@cli .command ("clean" )
215
225
@click .pass_context
226
+ @global_flags
216
227
@p .profile
217
228
@p .profiles_dir
218
229
@p .project_dir
@@ -235,13 +246,15 @@ def clean(ctx, **kwargs):
235
246
# dbt docs
236
247
@cli .group ()
237
248
@click .pass_context
249
+ @global_flags
238
250
def docs (ctx , ** kwargs ):
239
251
"""Generate or serve the documentation website for your project"""
240
252
241
253
242
254
# dbt docs generate
243
255
@docs .command ("generate" )
244
256
@click .pass_context
257
+ @global_flags
245
258
@p .compile_docs
246
259
@p .defer
247
260
@p .deprecated_defer
@@ -261,7 +274,6 @@ def docs(ctx, **kwargs):
261
274
@p .target_path
262
275
@p .threads
263
276
@p .vars
264
- @p .version_check
265
277
@requires .postflight
266
278
@requires .preflight
267
279
@requires .profile
@@ -284,6 +296,7 @@ def docs_generate(ctx, **kwargs):
284
296
# dbt docs serve
285
297
@docs .command ("serve" )
286
298
@click .pass_context
299
+ @global_flags
287
300
@p .browser
288
301
@p .port
289
302
@p .profile
@@ -312,6 +325,7 @@ def docs_serve(ctx, **kwargs):
312
325
# dbt compile
313
326
@cli .command ("compile" )
314
327
@click .pass_context
328
+ @global_flags
315
329
@p .defer
316
330
@p .deprecated_defer
317
331
@p .exclude
@@ -335,7 +349,6 @@ def docs_serve(ctx, **kwargs):
335
349
@p .target_path
336
350
@p .threads
337
351
@p .vars
338
- @p .version_check
339
352
@requires .postflight
340
353
@requires .preflight
341
354
@requires .profile
@@ -359,6 +372,7 @@ def compile(ctx, **kwargs):
359
372
# dbt show
360
373
@cli .command ("show" )
361
374
@click .pass_context
375
+ @global_flags
362
376
@p .defer
363
377
@p .deprecated_defer
364
378
@p .exclude
@@ -382,7 +396,6 @@ def compile(ctx, **kwargs):
382
396
@p .target_path
383
397
@p .threads
384
398
@p .vars
385
- @p .version_check
386
399
@requires .postflight
387
400
@requires .preflight
388
401
@requires .profile
@@ -406,14 +419,14 @@ def show(ctx, **kwargs):
406
419
# dbt debug
407
420
@cli .command ("debug" )
408
421
@click .pass_context
422
+ @global_flags
409
423
@p .debug_connection
410
424
@p .config_dir
411
425
@p .profile
412
426
@p .profiles_dir_exists_false
413
427
@p .project_dir
414
428
@p .target
415
429
@p .vars
416
- @p .version_check
417
430
@requires .postflight
418
431
@requires .preflight
419
432
def debug (ctx , ** kwargs ):
@@ -432,6 +445,7 @@ def debug(ctx, **kwargs):
432
445
# dbt deps
433
446
@cli .command ("deps" )
434
447
@click .pass_context
448
+ @global_flags
435
449
@p .profile
436
450
@p .profiles_dir_exists_false
437
451
@p .project_dir
@@ -452,6 +466,7 @@ def deps(ctx, **kwargs):
452
466
# dbt init
453
467
@cli .command ("init" )
454
468
@click .pass_context
469
+ @global_flags
455
470
# for backwards compatibility, accept 'project_name' as an optional positional argument
456
471
@click .argument ("project_name" , required = False )
457
472
@p .profile
@@ -474,6 +489,7 @@ def init(ctx, **kwargs):
474
489
# dbt list
475
490
@cli .command ("list" )
476
491
@click .pass_context
492
+ @global_flags
477
493
@p .exclude
478
494
@p .indirect_selection
479
495
@p .models
@@ -519,14 +535,14 @@ def list(ctx, **kwargs):
519
535
# dbt parse
520
536
@cli .command ("parse" )
521
537
@click .pass_context
538
+ @global_flags
522
539
@p .profile
523
540
@p .profiles_dir
524
541
@p .project_dir
525
542
@p .target
526
543
@p .target_path
527
544
@p .threads
528
545
@p .vars
529
- @p .version_check
530
546
@requires .postflight
531
547
@requires .preflight
532
548
@requires .profile
@@ -543,12 +559,12 @@ def parse(ctx, **kwargs):
543
559
# dbt run
544
560
@cli .command ("run" )
545
561
@click .pass_context
562
+ @global_flags
546
563
@p .defer
547
564
@p .deprecated_defer
548
565
@p .favor_state
549
566
@p .deprecated_favor_state
550
567
@p .exclude
551
- @p .fail_fast
552
568
@p .full_refresh
553
569
@p .profile
554
570
@p .profiles_dir
@@ -562,7 +578,6 @@ def parse(ctx, **kwargs):
562
578
@p .target_path
563
579
@p .threads
564
580
@p .vars
565
- @p .version_check
566
581
@requires .postflight
567
582
@requires .preflight
568
583
@requires .profile
@@ -585,14 +600,14 @@ def run(ctx, **kwargs):
585
600
# dbt retry
586
601
@cli .command ("retry" )
587
602
@click .pass_context
603
+ @global_flags
588
604
@p .project_dir
589
605
@p .profiles_dir
590
606
@p .vars
591
607
@p .profile
592
608
@p .target
593
609
@p .state
594
610
@p .threads
595
- @p .fail_fast
596
611
@requires .postflight
597
612
@requires .preflight
598
613
@requires .profile
@@ -615,6 +630,7 @@ def retry(ctx, **kwargs):
615
630
# dbt clone
616
631
@cli .command ("clone" )
617
632
@click .pass_context
633
+ @global_flags
618
634
@p .defer_state
619
635
@p .exclude
620
636
@p .full_refresh
@@ -629,7 +645,6 @@ def retry(ctx, **kwargs):
629
645
@p .target_path
630
646
@p .threads
631
647
@p .vars
632
- @p .version_check
633
648
@requires .preflight
634
649
@requires .profile
635
650
@requires .project
@@ -652,6 +667,7 @@ def clone(ctx, **kwargs):
652
667
# dbt run operation
653
668
@cli .command ("run-operation" )
654
669
@click .pass_context
670
+ @global_flags
655
671
@click .argument ("macro" )
656
672
@p .args
657
673
@p .profile
@@ -683,6 +699,7 @@ def run_operation(ctx, **kwargs):
683
699
# dbt seed
684
700
@cli .command ("seed" )
685
701
@click .pass_context
702
+ @global_flags
686
703
@p .exclude
687
704
@p .full_refresh
688
705
@p .profile
@@ -698,7 +715,6 @@ def run_operation(ctx, **kwargs):
698
715
@p .target_path
699
716
@p .threads
700
717
@p .vars
701
- @p .version_check
702
718
@requires .postflight
703
719
@requires .preflight
704
720
@requires .profile
@@ -720,6 +736,7 @@ def seed(ctx, **kwargs):
720
736
# dbt snapshot
721
737
@cli .command ("snapshot" )
722
738
@click .pass_context
739
+ @global_flags
723
740
@p .defer
724
741
@p .deprecated_defer
725
742
@p .exclude
@@ -759,13 +776,15 @@ def snapshot(ctx, **kwargs):
759
776
# dbt source
760
777
@cli .group ()
761
778
@click .pass_context
779
+ @global_flags
762
780
def source (ctx , ** kwargs ):
763
781
"""Manage your project's sources"""
764
782
765
783
766
784
# dbt source freshness
767
785
@source .command ("freshness" )
768
786
@click .pass_context
787
+ @global_flags
769
788
@p .exclude
770
789
@p .output_path # TODO: Is this ok to re-use? We have three different output params, how much can we consolidate?
771
790
@p .profile
@@ -808,10 +827,10 @@ def freshness(ctx, **kwargs):
808
827
# dbt test
809
828
@cli .command ("test" )
810
829
@click .pass_context
830
+ @global_flags
811
831
@p .defer
812
832
@p .deprecated_defer
813
833
@p .exclude
814
- @p .fail_fast
815
834
@p .favor_state
816
835
@p .deprecated_favor_state
817
836
@p .indirect_selection
@@ -828,7 +847,6 @@ def freshness(ctx, **kwargs):
828
847
@p .target_path
829
848
@p .threads
830
849
@p .vars
831
- @p .version_check
832
850
@requires .postflight
833
851
@requires .preflight
834
852
@requires .profile
0 commit comments