kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/platform/tools/kzip/flags/encoding.go (about)

     1  /*
     2   * Copyright 2019 The Kythe Authors. All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *   http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  // Package flags provides type EncodingFlag for use as a flag to specify Encoding.
    18  package flags // import "kythe.io/kythe/go/platform/tools/kzip/flags"
    19  
    20  import (
    21  	"kythe.io/kythe/go/platform/kzip"
    22  )
    23  
    24  // EncodingFlag encapsulates an Encoding for use as a flag.
    25  type EncodingFlag struct {
    26  	kzip.Encoding
    27  }
    28  
    29  // String implements part of the flag.Value interface.
    30  func (e *EncodingFlag) String() string {
    31  	return e.Encoding.String()
    32  }
    33  
    34  // Get implements part of the flag.Getter interface.
    35  func (e *EncodingFlag) Get() any {
    36  	return e.Encoding
    37  }
    38  
    39  // Set implements part of the flag.Value interface.
    40  func (e *EncodingFlag) Set(v string) error {
    41  	enc, err := kzip.EncodingFor(v)
    42  	if err == nil {
    43  		*e = EncodingFlag{enc}
    44  	}
    45  	return err
    46  }