{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.EMR.Types.Command
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.EMR.Types.Command where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An entity describing an executable that runs on a cluster.
--
-- /See:/ 'newCommand' smart constructor.
data Command = Command'
  { -- | Arguments for Amazon EMR to pass to the command for execution.
    Command -> Maybe [Text]
args :: Prelude.Maybe [Prelude.Text],
    -- | The Amazon S3 location of the command script.
    Command -> Maybe Text
scriptPath :: Prelude.Maybe Prelude.Text,
    -- | The name of the command.
    Command -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (Command -> Command -> Bool
(Command -> Command -> Bool)
-> (Command -> Command -> Bool) -> Eq Command
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Command -> Command -> Bool
$c/= :: Command -> Command -> Bool
== :: Command -> Command -> Bool
$c== :: Command -> Command -> Bool
Prelude.Eq, ReadPrec [Command]
ReadPrec Command
Int -> ReadS Command
ReadS [Command]
(Int -> ReadS Command)
-> ReadS [Command]
-> ReadPrec Command
-> ReadPrec [Command]
-> Read Command
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Command]
$creadListPrec :: ReadPrec [Command]
readPrec :: ReadPrec Command
$creadPrec :: ReadPrec Command
readList :: ReadS [Command]
$creadList :: ReadS [Command]
readsPrec :: Int -> ReadS Command
$creadsPrec :: Int -> ReadS Command
Prelude.Read, Int -> Command -> ShowS
[Command] -> ShowS
Command -> String
(Int -> Command -> ShowS)
-> (Command -> String) -> ([Command] -> ShowS) -> Show Command
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Command] -> ShowS
$cshowList :: [Command] -> ShowS
show :: Command -> String
$cshow :: Command -> String
showsPrec :: Int -> Command -> ShowS
$cshowsPrec :: Int -> Command -> ShowS
Prelude.Show, (forall x. Command -> Rep Command x)
-> (forall x. Rep Command x -> Command) -> Generic Command
forall x. Rep Command x -> Command
forall x. Command -> Rep Command x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Command x -> Command
$cfrom :: forall x. Command -> Rep Command x
Prelude.Generic)

-- |
-- Create a value of 'Command' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'args', 'command_args' - Arguments for Amazon EMR to pass to the command for execution.
--
-- 'scriptPath', 'command_scriptPath' - The Amazon S3 location of the command script.
--
-- 'name', 'command_name' - The name of the command.
newCommand ::
  Command
newCommand :: Command
newCommand =
  Command' :: Maybe [Text] -> Maybe Text -> Maybe Text -> Command
Command'
    { $sel:args:Command' :: Maybe [Text]
args = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:scriptPath:Command' :: Maybe Text
scriptPath = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Command' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Arguments for Amazon EMR to pass to the command for execution.
command_args :: Lens.Lens' Command (Prelude.Maybe [Prelude.Text])
command_args :: (Maybe [Text] -> f (Maybe [Text])) -> Command -> f Command
command_args = (Command -> Maybe [Text])
-> (Command -> Maybe [Text] -> Command)
-> Lens Command Command (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Command' {Maybe [Text]
args :: Maybe [Text]
$sel:args:Command' :: Command -> Maybe [Text]
args} -> Maybe [Text]
args) (\s :: Command
s@Command' {} Maybe [Text]
a -> Command
s {$sel:args:Command' :: Maybe [Text]
args = Maybe [Text]
a} :: Command) ((Maybe [Text] -> f (Maybe [Text])) -> Command -> f Command)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Command
-> f Command
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon S3 location of the command script.
command_scriptPath :: Lens.Lens' Command (Prelude.Maybe Prelude.Text)
command_scriptPath :: (Maybe Text -> f (Maybe Text)) -> Command -> f Command
command_scriptPath = (Command -> Maybe Text)
-> (Command -> Maybe Text -> Command)
-> Lens Command Command (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Command' {Maybe Text
scriptPath :: Maybe Text
$sel:scriptPath:Command' :: Command -> Maybe Text
scriptPath} -> Maybe Text
scriptPath) (\s :: Command
s@Command' {} Maybe Text
a -> Command
s {$sel:scriptPath:Command' :: Maybe Text
scriptPath = Maybe Text
a} :: Command)

-- | The name of the command.
command_name :: Lens.Lens' Command (Prelude.Maybe Prelude.Text)
command_name :: (Maybe Text -> f (Maybe Text)) -> Command -> f Command
command_name = (Command -> Maybe Text)
-> (Command -> Maybe Text -> Command)
-> Lens Command Command (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Command' {Maybe Text
name :: Maybe Text
$sel:name:Command' :: Command -> Maybe Text
name} -> Maybe Text
name) (\s :: Command
s@Command' {} Maybe Text
a -> Command
s {$sel:name:Command' :: Maybe Text
name = Maybe Text
a} :: Command)

instance Core.FromJSON Command where
  parseJSON :: Value -> Parser Command
parseJSON =
    String -> (Object -> Parser Command) -> Value -> Parser Command
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Command"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> Maybe Text -> Command
Command'
            (Maybe [Text] -> Maybe Text -> Maybe Text -> Command)
-> Parser (Maybe [Text])
-> Parser (Maybe Text -> Maybe Text -> Command)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Args" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe Text -> Command)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Command)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ScriptPath")
            Parser (Maybe Text -> Command)
-> Parser (Maybe Text) -> Parser Command
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Name")
      )

instance Prelude.Hashable Command

instance Prelude.NFData Command