# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Component source location: https://raw.githubusercontent.com/kubeflow/pipelines/master/components/sample/Shell_script/component.yaml
# Component details: Takes a text file and a regex pattern filter to produce a filtered text file
name: Filter text
inputs:
- {name: Text, optional: false, description: 'Path to file to be filtered'}
- {name: Pattern, optional: true, default: '.*', description: 'Regex pattern'}
outputs:
- {name: Filtered text}
metadata:
  annotations:
    author: Alexey Volkov <alexey.volkov@ark-kun.com>
implementation:
  container:
    image: alpine
    command:
    - sh
    - -ec
    - |
      text_path=$0
      pattern=$1
      filtered_text_path=$2
      mkdir -p "$(dirname "$filtered_text_path")"
      
      grep "$pattern" < "$text_path" > "$filtered_text_path"
    - {inputPath: Text}
    - {inputValue: Pattern}
    - {outputPath: Filtered text}
