code: def _encode_env_val(val, cmd_flag=None):
      """Returns an encoded flag val for use as env values.
  
      If `val` appears in `cmd_flag.env_encoding`, returns the
      corresponding value unmodified. Otherwise uses the same encoding
      scheme as _encode_flag_arg_for_argparse under the assumption that
      the same logic is used to decode env values as as command
      arguments.
      """
      cmd_flag = cmd_flag or CmdFlag()
      try:
          return cmd_flag.env_encoding[val]
      except (KeyError, TypeError):
          return _encode_flag_arg_for_argparse(val, cmd_flag)
  
imports: import logging
  import pprint
  from guild import flag_util
  from guild import util
  from guild import yaml_util
label_desc: Use image node_id 20 for calling a global function with example usage: _encode_env_val(val, cmd_flag) and returns: cmd_flag, _encode_flag_arg_for_argparse