gopkg.in/easygen.v4@v4.1.0/using_easygen.md (about) 1 2 ## Testing the templates on the fly 3 4 5 echo 'Name: some-init-method' > /tmp/var.yaml 6 7 $ EASYGEN_TS='{{.Name}}' easygen /tmp/var 8 some-init-method 9 10 I.e., with the environment variable `EASYGEN_TS`, the `.tmpl` template file is not used. 11 12 $ EASYGEN_TS='{{.Name}}' easygen -ts '{{clk2uc .Name}}' /tmp/var 13 SomeInitMethod 14 15 I.e., command line value takes the highest priority, even overriding the environment variable `EASYGEN_TS`'s value. 16 17 As such, if you have a different naming convention than using `.tmpl` for template file and `.yaml` for data file, you can override them in environment variables, `EASYGEN_ET` and `EASYGEN_EY`, so that you don't need to use `-et` and/or `-ey` to override them from command line each time. 18 19 echo 'Name: myConstantVariable' > /tmp/var.yml 20 21 $ EASYGEN_EY=.yml easygen -ts '{{clc2ss .Name}}' /tmp/var 22 MY_CONSTANT_VARIABLE 23 24 25 <a name="tips" /> 26 27 ## Tips 28 29 [ ](https://suntong.github.io/blogs/) 30 31 You can use `easygen` as an generic Go template testing tool with the `-ts` commandline option. For example, 32 33 ```bash 34 echo "Age: 16" > /tmp/age.yaml 35 36 $ easygen -ts "{{.Age}}" /tmp/age 37 16 38 39 $ easygen -ts '{{printf "%x" .Age}}' /tmp/age 40 10 41 42 $ easygen -ts '{{date "Y4"}}' /tmp/age 43 2017 44 $ 45 46 $ easygen -ts '{{date "I"}}' /tmp/age 47 2017-07-10 48 49 $ easygen -ts '{{date "."}}' /tmp/age 50 2017.07.10 51 52 $ easygen -ts '{{date ""}}' /tmp/age 53 20170710 54 55 $ easygen -ts '{{timestamp}}' /tmp/age 56 2017-07-10T08:53:25-04:00 57 58 $ easygen -ts '{{timestamp "unix"}}' /tmp/age 59 1499691221 60 61 echo '{FirstName: John, LastName: Doe}' > /tmp/name.yaml 62 63 $ easygen -ts '{{.FirstName}}'\''s full name is {{printf "%s%s" .FirstName .LastName | len}} letters long.' /tmp/name 64 John's full name is 7 letters long. 65 66 $ easygen -ts "{{.FirstName}} {{clk2ss .LastName}}'s full name is "'{{len (printf "%s%s" .FirstName .LastName)}} letters long.' /tmp/name 67 John DOE's full name is 7 letters long. 68 69 echo 'Name: some-init-method' > /tmp/var.yaml 70 71 $ easygen -ts '{{.Name}} {{6 | minus1}} {{minus1 6}} {{clk2lc .Name}} {{clk2uc .Name}}' /tmp/var 72 some-init-method 5 5 someInitMethod SomeInitMethod 73 74 75 $ echo 'Name: "%bob'"'"'s file"' | tee /tmp/var.yaml 76 Name: "%bob's file" 77 78 $ easygen -ts '{{quote4shell .Name}}' /tmp/var 79 '%bob'\''s file' 80 81 ```