roswell.roswell/documents/man/ros-template.1
2022-02-20 06:14:59 +00:00

229 lines
6.1 KiB
Groff

.\" Automatically generated by Pandoc 2.5
.\"
.TH "ros-template" "1" "" "" ""
.hy
.PP
ros\-template \- Edit template for ros\-init
.SH synopsis
.IP \[bu] 2
\f[B]ros template\f[R] command args\&...
.SH Subcommands
.TP
.B init template\-name
Create new template in local\-project directory.
.TP
.B deinit template\-name
Remove a template from local\-project directory.
.TP
.B list
Show file list and states of the files \f[I]type\f[R] \f[I]chmod\f[R]
\f[I]rewrite\f[R] in templates.
.TP
.B checkout [template\-name]
When invoked without template\-name,this command shows candidates for
current templates to operate.If with template\-name, this command choose
the name as current template.
.TP
.B add [template\-name] [files \&...]
Add files to current template.First parameter could taken as a
template\-name when current template are \f[I]default\f[R].
.TP
.B cat [template\-name] [files \&...]
Show contents in the current template.
.TP
.B edit [template\-name] [files \&...]
Edit content of files in template using \f[C]/usr/bin/editor\f[R].
.TP
.B path [template\-name] [files \&...]
Show native path of files in template.
.TP
.B rm [template\-name] [files \&...]
Remove file form current template.
.TP
.B type [template\-name] [type] [files \&...]
Change file type.
current choice for \f[I]type\f[R]s are \f[I]djula\f[R] or \f[I]copy\f[R]
{{name}} {{author}} {{email}} {{universal_time}} are available variable
in the template file.
Withoug files, change default type.
.TP
.B chmod [template\-name] [mode] [files \&...]
Change file mode bits to generate.
specify mode in octal format.
.TP
.B rewrite [template\-name] file rewrite\-rule
Change file name using djula template.Variables {{name}} {{author}}
{{email}} {{universal_time}} are available for rewrite\-rule.
.TP
.B export [template\-name] [directory]
Export files in current template to current directory.
.TP
.B import [directory]
Import template in current directory
.TP
.B help
Show the subcommand help.
.SH Description
.PP
The \f[I]ros\-template\f[R](1) command manages templates of projects.
.SS Create template
.PP
First, the \f[C]init\f[R] sub\-command creates an empty template.
.IP
.nf
\f[C]
$ ros template init sample\-template
\f[R]
.fi
.PP
Many of sub\-commands take a template name as first argument.
But you can omit it by the \f[C]checkout\f[R] sub\-commands.
After the following, such sub\-commands are applied to
\f[C]sample\-template\f[R].
.IP
.nf
\f[C]
$ ros template checkout sample\-template
\f[R]
.fi
.PP
Next, the \f[C]add\f[R] sub\-command adds local file[s] to template.
Then, the \f[C]list\f[R] sub\-command shows information of files in
template.
.IP
.nf
\f[C]
$ echo \[dq]Hello {{ author }}!!\[dq] > sample.txt
$ ros template add sample.txt
$ ros template list
copy sample.txt
\f[R]
.fi
.PP
The word \f[I]copy\f[R] means a strategy when applying the template.
There are the following 2 strategies.
.IP \[bu] 2
\f[I]copy\f[R] simply copies the file as\-is.
.IP \[bu] 2
\f[I]djula\f[R] processes the content of the file by template engine,
Djula (http://mmontone.github.io/djula/).
.RS 2
.IP \[bu] 2
Available variables are explained later.
.RE
.PP
The \f[C]type\f[R] sub\-command changes it.
In addition, default strategy (\f[I]copy\f[R]) can be changed for each
template by the \f[C]type\f[R] sub\-command without file names (Ex.
\f[C]ros template type djula\f[R]).
.IP
.nf
\f[C]
$ ros template type djula sample.txt
$ ros template list
djula sample.txt
\f[R]
.fi
.PP
The \f[C]sample.txt\f[R] will be simply output as \f[C]sample.txt\f[R]
in default.
But you can change it by the \f[C]rewrite\f[R] sub\-command.
In the following example, it will be output as
\f[C]sample_<project name>.txt\f[R].
.IP
.nf
\f[C]
$ ros template rewrite sample.txt \[dq]sample\-{{ name }}.txt\[dq]
$ ros template list
djula sample.txt \-> \[dq]sample\-{{ name }}.txt\[dq]
\f[R]
.fi
.PP
Note: Rewrite rules are always processed by Djula irrespective of
strategy of the file.
.SS Apply template
.PP
\f[I]ros\-init\f[R](1) can specify a template.
.IP
.nf
\f[C]
$ mkdir temp ; cd temp
$ ros init sample\-template some\-project
$ ls
sample\-some\-project.txt
$ cat sample\-some\-project.txt # Assume that \[dq]author\[dq] is \[dq]alien\[dq]
Hello alien!!
\f[R]
.fi
.PP
The file name and its content are processed by Djula as explained in the
above.
The following variables can be used in defaut.
.IP \[bu] 2
{{name}}: A project name specified in \f[I]ros\-init\f[R](1)
.IP \[bu] 2
{{author}}: An author name extracted from config of Git or
\f[C]whoami\f[R]
.IP \[bu] 2
{{email}}: An e\-mail address extracted from config of Git or created
using \f[C]whoami\f[R] and \f[C]hostname\f[R]
.IP \[bu] 2
{{universal_time}}: A universal time created by
\f[C]get\-universal\-time\f[R] function
.PP
In addition, you can use original variables as the followings.
.IP
.nf
\f[C]
$ echo \[dq]Hello {{ area }}!!\[dq] > sample.txt
$ ros template add sample.txt # Note: It overwrites existing
$ mkdir temp ; cd temp
$ ros init sample\-template roswell \-\-area 51
$ cat sample\-roswell.txt
Hello 51!!
\f[R]
.fi
.SS Export and import template
.PP
Basically, \f[I]ros\-template\f[R](1) is designed to internally manage
added files.
.PP
However, if you want to, for example, manage it using Git in a local
directory or to install distributed templates, you can use the
\f[C]export\f[R] and \f[C]import\f[R] sub\-commands.
.PP
First, the \f[C]export\f[R] sub\-command exports added files and a
setting file \f[C]roswell.init.<template name>.asd\f[R] that is
internally created and editted.
.IP
.nf
\f[C]
$ ros template export dir
$ ls dir
roswell.init.sample\-template.asd sample.txt
$ cat dir/sample.txt
Hello {{ area }}!!
\f[R]
.fi
.PP
Second, the \f[C]import\f[R] sub\-command imports them.
.IP
.nf
\f[C]
# Assume that this is another machine...
$ ros template list sample\-template # nothing is output
$ ls downloaded
roswell.init.sample\-template.asd sample.txt
$ ros template import downloaded
$ ros template list sample\-template
djula sample.txt \-> \[dq]sample\-{{ name }}.txt\[dq]
\f[R]
.fi
.PP
Note: If there is a template whose name is same, it will be overwritten.
.SH SEE ALSO
.PP
\f[I]ros\f[R](1) \f[I]ros\-init\f[R](1)
.SH AUTHORS
Roswell Project Team.