@@ -6,7 +6,7 @@ module Commands
66 class Render < Base
77 help 'Render the bashly data structure using cutsom templates'
88
9- usage 'bashly render SOURCE TARGET [options ]'
9+ usage 'bashly render SOURCE TARGET [--watch --show PATH ]'
1010 usage 'bashly render SOURCE --about'
1111 usage 'bashly render --list'
1212 usage 'bashly render (-h|--help)'
@@ -20,12 +20,21 @@ class Render < Base
2020 param 'TARGET' , 'Output directory'
2121
2222 option '-w --watch' , 'Watch bashly.yml and the templates source for changes and render on change'
23+ option '-s --show PATH' , <<~USAGE
24+ After rendering, show the result generated in PATH.
25+
26+ The provided PATH is treated as relative TARGET.
27+
28+ Note that this works only if the template source supports it.
29+ USAGE
30+
2331 option '-l --list' , 'Show list of built-in templates'
2432 option '-a --about' , 'Show information about a given templates source'
2533
2634 example 'bashly render --list'
2735 example 'bashly render :markdown --about'
2836 example 'bashly render :markdown docs --watch'
37+ example 'bashly render :markdown docs --show "cli-download.1"'
2938 example 'bashly render /path/to/templates ./out_path'
3039
3140 attr_reader :watching , :target , :source
@@ -50,21 +59,6 @@ def show_about
5059 puts TTY ::Markdown . parse ( render_source . readme )
5160 end
5261
53- def render_source
54- @render_source ||= begin
55- source = RenderSource . new selector
56- raise "Invalid render source: #{ args [ 'SOURCE' ] } " unless source . exist?
57-
58- source
59- end
60- end
61-
62- def selector
63- return args [ 'SOURCE' ] unless args [ 'SOURCE' ] . start_with? ':'
64-
65- args [ 'SOURCE' ] [ 1 ..] . to_sym
66- end
67-
6862 def start_render
6963 @target = args [ 'TARGET' ]
7064 @watching = args [ '--watch' ]
@@ -74,7 +68,7 @@ def start_render
7468 end
7569
7670 def render
77- render_source . render target
71+ render_source . render target , show : args [ '--show' ]
7872 end
7973
8074 def watch
@@ -86,6 +80,21 @@ def watch
8680 end
8781 end
8882
83+ def render_source
84+ @render_source ||= begin
85+ source = RenderSource . new selector
86+ raise "Invalid render source: #{ args [ 'SOURCE' ] } " unless source . exist?
87+
88+ source
89+ end
90+ end
91+
92+ def selector
93+ return args [ 'SOURCE' ] unless args [ 'SOURCE' ] . start_with? ':'
94+
95+ args [ 'SOURCE' ] [ 1 ..] . to_sym
96+ end
97+
8998 def watchables
9099 @watchables ||= [ Settings . config_path , render_source . path ]
91100 end
0 commit comments