Use second argument for optional first argument if not provided in macro
There are several ways to do it.
Classical method
\makeatletter
\newcommand{\mycommand}{\@dblarg\my@command}
\def\my@command[#1]#2{\label{#1}#2}
\makeatother
xparse
\usepackage{xparse}
\NewDocumentCommand{\mycommand}{O{#2}m}{\label{#1}#2}
Your use case
\NewDocumentCommand{\mycommand}{O{optionone=#2}m}{%
\begin{myenv}[#1]\input{#2}\end{myenv}%
}
Here, \mycommand
determines if there is 1 or 2 arguments, and passes the result off to \mycommandaux
, which handles both arguments, whether repeated or not.
\documentclass{article}
\newcommand\mycommand[2][\relax]{%
\ifx\relax#1%
\mycommandaux{#2}{#2}%
\else
\mycommandaux{#1}{#2}%
\fi
}
\newcommand\mycommandaux[2]{Arguments 1,2: [#1]\{#2\}}
\begin{document}
\mycommand{xyz}
\mycommand[xyz]{pdq}
\end{document}
Trying to conform more to the OP's edited example
\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand\mycommand[2][\relax]{%
\ifx\relax#1%
\mycommandaux{optionone=#2}{#2}%
\else
\mycommandaux{#1}{#2}%
\fi
}
\newcommand\mycommandaux[2]{\detokenize{\begin{myenv}[#1]\input{#2}\end{myenv}}}
\begin{document}
\mycommand{ABC}
\mycommand[optiontwo=xyz]{pdq}
\end{document}